-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migration pre-upgrade script (#104)
Co-authored-by: Andrew Whitehead <cywolf@gmail.com> Signed-off-by: blu3beri <blu3beri@proton.me>
- Loading branch information
1 parent
8954ebc
commit ee4e5aa
Showing
12 changed files
with
679 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.vscode | ||
target | ||
*.bak.db | ||
*.db-shm | ||
*.db-wal | ||
Cargo.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use ffi_support::FfiStr; | ||
|
||
use crate::{future::spawn_ok, migration::IndySdkToAriesAskarMigration}; | ||
|
||
use super::{ | ||
error::{set_last_error, ErrorCode}, | ||
CallbackId, EnsureCallback, | ||
}; | ||
|
||
/// Migrate an sqlite wallet from an indy-sdk structure to an aries-askar structure. | ||
/// It is important to note that this does not do any post-processing. If the record values, tags, | ||
/// names, etc. have changed, it must be processed manually afterwards. This script does the following: | ||
/// | ||
/// 1. Create and rename the required tables | ||
/// 2. Fetch the indy key from the wallet | ||
/// 3. Create a new configuration | ||
/// 4. Initialize a profile | ||
/// 5. Update the items from the indy-sdk | ||
/// 6. Clean up (drop tables and add a version of "1") | ||
#[no_mangle] | ||
pub extern "C" fn askar_migrate_indy_sdk( | ||
spec_uri: FfiStr<'_>, | ||
wallet_name: FfiStr<'_>, | ||
wallet_key: FfiStr<'_>, | ||
kdf_level: FfiStr<'_>, | ||
cb: Option<extern "C" fn(cb_id: CallbackId, err: ErrorCode)>, | ||
cb_id: CallbackId, | ||
) -> ErrorCode { | ||
catch_err!( | ||
trace!("Migrate sqlite wallet from indy-sdk structure to aries-askar"); | ||
let cb = cb.ok_or_else(|| err_msg!("No callback provided"))?; | ||
let spec_uri = spec_uri.into_opt_string().ok_or_else(|| err_msg!("No provision spec URI provided"))?; | ||
let wallet_name = wallet_name.into_opt_string().ok_or_else(|| err_msg!("No wallet name provided"))?; | ||
let wallet_key = wallet_key.into_opt_string().ok_or_else(|| err_msg!("No wallet key provided"))?; | ||
let kdf_level = kdf_level.into_opt_string().ok_or_else(|| err_msg!("No KDF level provided"))?; | ||
|
||
let cb = EnsureCallback::new(move |result| | ||
match result { | ||
Ok(_) => cb(cb_id, ErrorCode::Success), | ||
Err(err) => cb(cb_id, set_last_error(Some(err))), | ||
}); | ||
|
||
spawn_ok(async move { | ||
let result = async { | ||
let migrator = IndySdkToAriesAskarMigration::connect(&spec_uri, &wallet_name, &wallet_key, &kdf_level).await?; | ||
migrator.migrate().await?; | ||
Ok(()) | ||
}.await; | ||
cb.resolve(result); | ||
}); | ||
Ok(ErrorCode::Success) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.