Skip to content

Commit

Permalink
Enable trussed-auth and trussed-se050-backend migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Apr 4, 2024
1 parent 4a9e561 commit 7ddcfd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
22 changes: 17 additions & 5 deletions components/apps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,31 +349,43 @@ impl<R: Runner> Apps<R> {
// TODO: use CLIENT_ID directly
let mut filestore = ClientFilestore::new(ADMIN_APP_CLIENT_ID.into(), data.store);
let version = data.version.encode();

let valid_migrators = migrations::MIGRATORS;
// No migrations if the config failed to load. In that case applications are disabled anyways
let config_error_migrators = &[];

let mut used_migrators = valid_migrators;

let mut app = AdminApp::<R>::load_config(
trussed,
&mut filestore,
runner.uuid(),
version,
data.version_string,
data.status(),
migrations::MIGRATORS,
valid_migrators,
)
.unwrap_or_else(|(trussed, _err)| {
data.init_status.insert(InitStatus::CONFIG_ERROR);
used_migrators = config_error_migrators;
AdminApp::<R>::with_default_config(
trussed,
runner.uuid(),
version,
data.version_string,
data.status(),
// No migrations if the config failed to load. In that case applications are disabled anyways
&[],
config_error_migrators,
)
});

const LATEST_MIGRATION: u32 = 0;
let migration_version = used_migrators
.iter()
.map(|m| m.version)
.max()
.unwrap_or_default();

let migration_success = app
.migrate(LATEST_MIGRATION, data.store, &mut filestore)
.migrate(migration_version, data.store, &mut filestore)
.is_ok();
if !migration_success {
data.init_status.insert(InitStatus::MIGRATION_ERROR);
Expand Down
24 changes: 3 additions & 21 deletions components/apps/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,12 @@ pub(crate) const MIGRATION_VERSION_SPACE_EFFICIENCY: u32 = 1;

#[cfg(feature = "backend-auth")]
pub(crate) const TRUSSED_AUTH_FS_LAYOUT: trussed_auth::FilesystemLayout =
trussed_auth::FilesystemLayout::V0;
trussed_auth::FilesystemLayout::V1;
#[cfg(feature = "se050")]
pub(crate) const SE050_BACKEND_FS_LAYOUT: trussed_se050_backend::FilesystemLayout =
trussed_se050_backend::FilesystemLayout::V0;
trussed_se050_backend::FilesystemLayout::V1;

/// TODO: When enabling the filesystem layout V1, fido-authenticator will also need to be bump and have its migration enabled
const _: () = {
#[cfg(feature = "backend-auth")]
assert!(matches!(
TRUSSED_AUTH_FS_LAYOUT,
trussed_auth::FilesystemLayout::V0
));
#[cfg(feature = "se050")]
assert!(matches!(
SE050_BACKEND_FS_LAYOUT,
trussed_se050_backend::FilesystemLayout::V0
));
assert!(MIGRATORS.is_empty());
};

pub(crate) const MIGRATORS: &[Migrator] = &[];

// TODO: use when enabling migrations of trussed-auth and se050-backend and of fido-authenticator
const _MIGRATORS: &[Migrator] = &[
pub(crate) const MIGRATORS: &[Migrator] = &[
// We first migrate the SE050 since this migration deletes data to make sure that the other
// migrations succeed even on low block availability
#[cfg(feature = "se050")]
Expand Down

0 comments on commit 7ddcfd6

Please sign in to comment.