From e4f955d672af99d1bf25e6a0bb038d116f8bca0c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 16 May 2023 18:34:46 +0200 Subject: fix base64 uses --- src/k2v-client/bin/k2v-cli.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/k2v-client/bin') diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index cdd63cce..c8418e0d 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -2,6 +2,8 @@ use std::collections::BTreeMap; use std::process::exit; use std::time::Duration; +use base64::prelude::*; + use k2v_client::*; use garage_util::formater::format_table; @@ -155,7 +157,7 @@ impl Value { if let Some(ref text) = self.text { Ok(text.as_bytes().to_vec()) } else if let Some(ref b64) = self.b64 { - base64::decode(b64).map_err(|_| Error::Message("invalid base64 input".into())) + BASE64_STANDARD.decode(b64).map_err(|_| Error::Message("invalid base64 input".into())) } else if let Some(ref path) = self.file { use tokio::io::AsyncReadExt; if path == "-" { @@ -230,7 +232,7 @@ impl ReadOutputKind { for val in val.value { match val { K2vValue::Value(v) => { - println!("{}", base64::encode(&v)) + println!("{}", BASE64_STANDARD.encode(&v)) } K2vValue::Tombstone => { println!(); @@ -249,7 +251,7 @@ impl ReadOutputKind { if let Ok(string) = std::str::from_utf8(&v) { println!(" utf-8: {}", string); } else { - println!(" base64: {}", base64::encode(&v)); + println!(" base64: {}", BASE64_STANDARD.encode(&v)); } } K2vValue::Tombstone => { @@ -284,7 +286,7 @@ impl BatchOutputKind { if let Ok(string) = std::str::from_utf8(&v) { println!(" value(utf-8): {}", string); } else { - println!(" value(base64): {}", base64::encode(&v)); + println!(" value(base64): {}", BASE64_STANDARD.encode(&v)); } } K2vValue::Tombstone => { -- cgit v1.2.3 From bb03805b582562ddec1ac5e8fdc3b31bad070731 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 16 May 2023 18:37:49 +0200 Subject: k2v-cli: fix sort_key being partition_key and specify which key --- src/k2v-client/bin/k2v-cli.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/k2v-client/bin') diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index c8418e0d..5dad6106 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -277,7 +277,7 @@ struct BatchOutputKind { impl BatchOutputKind { fn display_human_output(&self, values: BTreeMap) -> ! { for (key, values) in values { - println!("key: {}", key); + println!("sort_key: {}", key); let causality: String = values.causality.into(); println!("causality: {}", causality); for value in values.value { @@ -522,7 +522,7 @@ async fn main() -> Result<(), Error> { value .as_object_mut() .unwrap() - .insert("sort_key".to_owned(), k.into()); + .insert("partition_key".to_owned(), k.into()); value }) .collect::>(); @@ -539,7 +539,7 @@ async fn main() -> Result<(), Error> { } let mut to_print = Vec::new(); - to_print.push(format!("key:\tentries\tconflicts\tvalues\tbytes")); + to_print.push(format!("partition_key\tentries\tconflicts\tvalues\tbytes")); for (k, v) in res.items { to_print.push(format!( "{}\t{}\t{}\t{}\t{}", -- cgit v1.2.3 From 16f2a32bb78cdc0d9cee9806c04065af845d0dff Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 16 May 2023 18:40:27 +0200 Subject: cargo fmt --- src/k2v-client/bin/k2v-cli.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/k2v-client/bin') diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index 5dad6106..e771fe26 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -157,7 +157,9 @@ impl Value { if let Some(ref text) = self.text { Ok(text.as_bytes().to_vec()) } else if let Some(ref b64) = self.b64 { - BASE64_STANDARD.decode(b64).map_err(|_| Error::Message("invalid base64 input".into())) + BASE64_STANDARD + .decode(b64) + .map_err(|_| Error::Message("invalid base64 input".into())) } else if let Some(ref path) = self.file { use tokio::io::AsyncReadExt; if path == "-" { -- cgit v1.2.3 From a1cec2cd60d64208caa2cbd11d8e6f885e80f630 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 17 May 2023 13:01:37 +0200 Subject: Split format_table into separate crate and reduce k2v-client dependencies --- src/k2v-client/bin/k2v-cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/k2v-client/bin') diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index e771fe26..76388752 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -6,7 +6,7 @@ use base64::prelude::*; use k2v_client::*; -use garage_util::formater::format_table; +use format_table::format_table; use rusoto_core::credential::AwsCredentials; use rusoto_core::Region; -- cgit v1.2.3 From 4420db731020bf7123f2bb80b076da581836f900 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 18 May 2023 00:07:54 +0200 Subject: add tracing to k2v-client --- src/k2v-client/bin/k2v-cli.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/k2v-client/bin') diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index 76388752..984b4192 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -397,6 +397,15 @@ impl Filter { #[tokio::main] async fn main() -> Result<(), Error> { + if std::env::var("RUST_LOG").is_err() { + std::env::set_var("RUST_LOG", "warn") + } + + tracing_subscriber::fmt() + .with_writer(std::io::stderr) + .with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env()) + .init(); + let args = Args::parse(); let region = Region::Custom { -- cgit v1.2.3 From 644e8722641c826603f7ee3c2c7b58f31ab88c23 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 18 May 2023 13:04:17 +0200 Subject: Port k2v-client to aws-sigv4 since rusoto_signature is deprecated --- src/k2v-client/bin/k2v-cli.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/k2v-client/bin') diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index 984b4192..5a2422ab 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -8,9 +8,6 @@ use k2v_client::*; use format_table::format_table; -use rusoto_core::credential::AwsCredentials; -use rusoto_core::Region; - use clap::{Parser, Subcommand}; /// K2V command line interface @@ -408,14 +405,16 @@ async fn main() -> Result<(), Error> { let args = Args::parse(); - let region = Region::Custom { - name: args.region, + let config = K2vClientConfig { endpoint: args.endpoint, + region: args.region, + aws_access_key_id: args.key_id, + aws_secret_access_key: args.secret, + bucket: args.bucket, + user_agent: None, }; - let creds = AwsCredentials::new(args.key_id, args.secret, None, None); - - let client = K2vClient::new(region, args.bucket, creds, None)?; + let client = K2vClient::new(config)?; match args.command { Command::Insert { -- cgit v1.2.3