Skip to content

Commit

Permalink
[WIP] Add cli command mount_realm_export;
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Feb 17, 2025
1 parent 7cdb816 commit b67f04b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ libparsec_crypto = { workspace = true }
libparsec_client = { workspace = true }
libparsec_client_connection = { workspace = true }
libparsec_platform_ipc = { workspace = true }
libparsec_platform_mountpoint = { workspace = true }

anyhow = { workspace = true }
clap = { workspace = true, features = ["default", "derive", "env"] }
Expand Down
1 change: 1 addition & 0 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod device;
pub mod invite;
pub mod ls;
pub mod mount_realm_export;
pub mod organization;
pub mod rm;
#[cfg(feature = "testenv")]
Expand Down
63 changes: 63 additions & 0 deletions cli/src/commands/mount_realm_export.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use std::{path::PathBuf, sync::Arc};

use dialoguer::Confirm;
use libparsec::{DateTime, SequesterPrivateKeyDer, SequesterServiceID};
use libparsec_client::{WorkspaceHistoryOps, WorkspaceHistoryRealmExportDecryptor};
use libparsec_platform_mountpoint::Mountpoint;

use crate::utils::default_client_config;

crate::clap_parser_with_shared_opts_builder!(
#[with = device, password_stdin]
pub struct Args {
/// Path to the DB
export_db_path: PathBuf,
/// sequester private key
decryptor_sequester_private_key: String,
/// workspace name
workspace: String,
/// sequester id
sequester_service_id: String,
// /// target timestamp
// timestamp_of_interest: DateTime,
}
);

pub async fn main(args: Args) -> anyhow::Result<()> {
let Args {
export_db_path,
decryptor_sequester_private_key,
//timestamp_of_interest,
workspace,
sequester_service_id,
..
} = args;

let config = Arc::new(default_client_config());

let decryptors = vec![WorkspaceHistoryRealmExportDecryptor::SequesterService {
sequester_service_id: SequesterServiceID::from_hex(&sequester_service_id)?,
private_key: Box::new(SequesterPrivateKeyDer::try_from(
&decryptor_sequester_private_key.into_bytes()[..],
)?),
}];

let wksp_history_ops = Arc::new(
WorkspaceHistoryOps::start_with_realm_export(config, &export_db_path, decryptors).await?,
);

let mountpoint_name_hint = format!("{workspace}-{}", DateTime::now()).parse()?;
let mountpoint = Mountpoint::mount_history(wksp_history_ops, mountpoint_name_hint).await?;

println!("Mounted workspace at {:?}", mountpoint.path());

while !Confirm::new()
.with_prompt("Close mountpoint ?")
.interact()?
{}

mountpoint.unmount().await?;
println!("Unmounted workspace.");

Ok(())
}
5 changes: 5 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum Command {
/// Contains subcommands related to shared recovery devices (shamir)
#[command(subcommand)]
SharedRecovery(shared_recovery::Group),
/// Mount realm export.
MountRealmExport(mount_realm_export::Args),
}

#[tokio::main]
Expand All @@ -70,5 +72,8 @@ async fn main() -> anyhow::Result<()> {
Command::SharedRecovery(shared_recovery) => {
shared_recovery::dispatch_command(shared_recovery).await
}
Command::MountRealmExport(mount_realm_export) => {
mount_realm_export::main(mount_realm_export).await
}
}
}

0 comments on commit b67f04b

Please sign in to comment.