aboutsummaryrefslogtreecommitdiff
path: root/src/garage/cli
diff options
context:
space:
mode:
Diffstat (limited to 'src/garage/cli')
-rw-r--r--src/garage/cli/cmd.rs8
-rw-r--r--src/garage/cli/util.rs73
2 files changed, 69 insertions, 12 deletions
diff --git a/src/garage/cli/cmd.rs b/src/garage/cli/cmd.rs
index b65fea02..1c64f9b5 100644
--- a/src/garage/cli/cmd.rs
+++ b/src/garage/cli/cmd.rs
@@ -173,8 +173,8 @@ pub async fn cmd_admin(
format_table(table);
println!("Buckets that don't have a global alias (i.e. that only exist in the namespace of an access key) are not shown.");
}
- AdminRpc::BucketInfo(bucket) => {
- print_bucket_info(&bucket);
+ AdminRpc::BucketInfo(bucket, rk) => {
+ print_bucket_info(&bucket, &rk);
}
AdminRpc::KeyList(kl) => {
println!("List of keys:");
@@ -182,8 +182,8 @@ pub async fn cmd_admin(
println!("{}\t{}", key.0, key.1);
}
}
- AdminRpc::KeyInfo(key) => {
- print_key_info(&key);
+ AdminRpc::KeyInfo(key, rb) => {
+ print_key_info(&key, &rb);
}
r => {
error!("Unexpected response: {:?}", r);
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);
}
};
}