Skip to content

Commit

Permalink
Add user human handles ifor shared recovery cli list and info.
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Dec 11, 2024
1 parent 915edb2 commit 1d225c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cli/src/commands/shared_recovery/info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use itertools::Itertools;

use crate::{build_main_with_client, utils::*};
Expand All @@ -18,6 +20,8 @@ pub async fn list_shared_recovery(_args: Args, client: &StartedClient) -> anyhow
}

let info = client.get_self_shamir_recovery().await?;
let users = client.list_users(false, None, None).await?;
let users: HashMap<_, _> = users.iter().map(|info| (info.id, info)).collect();

match info {
libparsec_client::SelfShamirRecoveryInfo::Deleted {
Expand All @@ -28,7 +32,10 @@ pub async fn list_shared_recovery(_args: Args, client: &StartedClient) -> anyhow
libparsec_client::SelfShamirRecoveryInfo::SetupAllValid {
per_recipient_shares, threshold, ..
} => println!("Shared recovery {GREEN}set up{RESET} with threshold {threshold}\n{}", per_recipient_shares.iter().map(|(recipient, share)| {
format!("• User {recipient} has {share} share(s)") // TODO: special case if there is only on share
// this means that a user disappeared completely, it should not happen
let user= &users.get(recipient).expect("missing recipient").human_handle;
format!("\t• User {user} has {share} share(s)", // TODO: special case if there is only on share
)
}).join("\n")),
libparsec_client::SelfShamirRecoveryInfo::SetupWithRevokedRecipients {
threshold,
Expand Down
11 changes: 9 additions & 2 deletions cli/src/commands/shared_recovery/list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use itertools::Itertools;

use crate::{build_main_with_client, utils::*};
Expand All @@ -18,6 +20,8 @@ pub async fn shared_recovery_info(_args: Args, client: &StartedClient) -> anyhow
}

let res = client.list_shamir_recoveries_for_others().await?;
let users = client.list_users(false, None, None).await?;
let users: HashMap<_, _> = users.iter().map(|info| (info.id, info)).collect();

if res.is_empty() {
println!("No shared recovery found");
Expand All @@ -34,8 +38,11 @@ pub async fn shared_recovery_info(_args: Args, client: &StartedClient) -> anyhow
} => println!("• Deleted shared recovery for {RED}{user_id}{RESET} - deleted by {deleted_by} on {deleted_on}"),
libparsec_client::OtherShamirRecoveryInfo::SetupAllValid {
user_id, threshold, per_recipient_shares,..
} => println!("Shared recovery for {GREEN}{user_id}{RESET} with threshold {threshold}\n{}", per_recipient_shares.iter().map(|(recipient, share)| {
format!("\t• User {recipient} has {share} share(s)") // TODO: special case if there is only on share
} => println!("Shared recovery for {GREEN}{}{RESET} with threshold {threshold}\n{}", users.get(&user_id).expect("missing author").human_handle, per_recipient_shares.iter().map(|(recipient, share)| {
// this means that a user disappeared completely, it should not happen
let user= &users.get(recipient).expect("missing recipient").human_handle;
format!("\t• User {user} has {share} share(s)", // TODO: special case if there is only on share
)
}).join("\n")),
libparsec_client::OtherShamirRecoveryInfo::SetupWithRevokedRecipients {
user_id,
Expand Down

0 comments on commit 1d225c2

Please sign in to comment.