diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-16 16:17:51 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-04 12:46:41 +0100 |
commit | 5db600e2316b80102e3fd4df9e8974c9586aec9c (patch) | |
tree | 88089cba0721cdcc293ddb3b23b0f374e993fe89 /src/garage/cli/util.rs | |
parent | 4d30e62db456097563c574b9dfd22b138d700087 (diff) | |
download | garage-5db600e2316b80102e3fd4df9e8974c9586aec9c.tar.gz garage-5db600e2316b80102e3fd4df9e8974c9586aec9c.zip |
More complete output to bucket info and key info
Diffstat (limited to 'src/garage/cli/util.rs')
-rw-r--r-- | src/garage/cli/util.rs | 73 |
1 files changed, 65 insertions, 8 deletions
diff --git a/src/garage/cli/util.rs b/src/garage/cli/util.rs index f586d55b..ad48c301 100644 --- a/src/garage/cli/util.rs +++ b/src/garage/cli/util.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use garage_util::crdt::*; use garage_util::data::Uuid; use garage_util::error::*; @@ -5,7 +7,24 @@ use garage_util::error::*; use garage_model::bucket_table::*; use garage_model::key_table::*; -pub fn print_key_info(key: &Key) { +pub fn print_key_info(key: &Key, relevant_buckets: &HashMap<Uuid, Bucket>) { + let bucket_global_aliases = |b: &Uuid| { + if let Some(bucket) = relevant_buckets.get(b) { + if let Some(p) = bucket.state.as_option() { + return p + .aliases + .items() + .iter() + .filter(|(_, _, active)| *active) + .map(|(a, _, _)| a.clone()) + .collect::<Vec<_>>() + .join(", "); + } + } + + "".to_string() + }; + println!("Key name: {}", key.name.get()); println!("Key ID: {}", key.key_id); println!("Secret key: {}", key.secret_key); @@ -16,18 +35,39 @@ pub fn print_key_info(key: &Key) { let mut table = vec![]; for (alias_name, _, alias) in p.local_aliases.items().iter() { if let Some(bucket_id) = alias.as_option() { - table.push(format!("\t{}\t{}", alias_name, hex::encode(bucket_id))); + table.push(format!( + "\t{}\t{}\t{}", + alias_name, + bucket_global_aliases(bucket_id), + hex::encode(bucket_id) + )); } } format_table(table); println!("\nAuthorized buckets:"); let mut table = vec![]; - for (b, perm) in p.authorized_buckets.items().iter() { + for (bucket_id, perm) in p.authorized_buckets.items().iter() { let rflag = if perm.allow_read { "R" } else { " " }; let wflag = if perm.allow_write { "W" } else { " " }; let oflag = if perm.allow_owner { "O" } else { " " }; - table.push(format!("\t{}{}{}\t{:?}", rflag, wflag, oflag, b)); + let local_aliases = p + .local_aliases + .items() + .iter() + .filter(|(_, _, a)| a.as_option() == Some(bucket_id)) + .map(|(a, _, _)| a.clone()) + .collect::<Vec<_>>() + .join(", "); + table.push(format!( + "\t{}{}{}\t{}\t{}\t{:?}", + rflag, + wflag, + oflag, + bucket_global_aliases(bucket_id), + local_aliases, + bucket_id + )); } format_table(table); } @@ -37,32 +77,49 @@ pub fn print_key_info(key: &Key) { } } -pub fn print_bucket_info(bucket: &Bucket) { +pub fn print_bucket_info(bucket: &Bucket, relevant_keys: &HashMap<String, Key>) { println!("Bucket: {}", hex::encode(bucket.id)); match &bucket.state { Deletable::Deleted => println!("Bucket is deleted."), Deletable::Present(p) => { + println!("Website access: {}", p.website_access.get()); + println!("\nGlobal aliases:"); for (alias, _, active) in p.aliases.items().iter() { if *active { - println!("- {}", alias); + println!(" {}", alias); } } println!("\nKey-specific aliases:"); + let mut table = vec![]; for ((key_id, alias), _, active) in p.local_aliases.items().iter() { if *active { - println!("- {} {}", key_id, alias); + let key_name = relevant_keys + .get(key_id) + .map(|k| k.name.get().as_str()) + .unwrap_or(""); + table.push(format!("\t{}\t{} ({})", alias, key_id, key_name)); } } + format_table(table); println!("\nAuthorized keys:"); + let mut table = vec![]; for (k, perm) in p.authorized_keys.items().iter() { let rflag = if perm.allow_read { "R" } else { " " }; let wflag = if perm.allow_write { "W" } else { " " }; let oflag = if perm.allow_owner { "O" } else { " " }; - println!("- {}{}{} {}", rflag, wflag, oflag, k); + let key_name = relevant_keys + .get(k) + .map(|k| k.name.get().as_str()) + .unwrap_or(""); + table.push(format!( + "\t{}{}{}\t{} ({})", + rflag, wflag, oflag, k, key_name + )); } + format_table(table); } }; } |