Create a Snapshot
Run the Example
You can create a new snapshot on the file system, and generate and store a new Ed25519 key inside the desired location by running the following command from within the client crate.
cargo run --example cli create-snapshot --path "/path/to/snapshot.file" --client-path "client-path-0" --vault-path "vault-path" --record-path "record-path" --key "passphrase"
Expected Output
[2022-06-28T14:27:05Z INFO cli] Snapshot created successully? true
Example Code
async fn command_create_snapshot(path: String, client_path: String, output: VaultLocation, key: String) {
let stronghold = Stronghold::default();
let client_path = client_path.as_bytes().to_vec();
let client = stronghold
.create_client(client_path.clone())
.expect("Cannot creat client");
let output_location = output.to_location();
let generate_key_procedure = GenerateKey {
ty: KeyType::Ed25519,
output: output_location,
};
client
.execute_procedure(generate_key_procedure)
.expect("Running procedure failed");
stronghold
.write_client(client_path)
.expect("Store client state into snapshot state failed");
// calculate hash from key
let key = hash_blake2b(key);
info!(
"Snapshot created successully? {}",
stronghold
.commit_with_keyprovider(&SnapshotPath::from_path(path), &KeyProvider::try_from(key).unwrap())
.is_ok()
);
}