aboutsummaryrefslogtreecommitdiff
path: root/src/k2v-client
diff options
context:
space:
mode:
Diffstat (limited to 'src/k2v-client')
-rw-r--r--src/k2v-client/Cargo.toml5
-rw-r--r--src/k2v-client/bin/k2v-cli.rs18
-rw-r--r--src/k2v-client/lib.rs15
3 files changed, 23 insertions, 15 deletions
diff --git a/src/k2v-client/Cargo.toml b/src/k2v-client/Cargo.toml
index f49d3205..293ad8b7 100644
--- a/src/k2v-client/Cargo.toml
+++ b/src/k2v-client/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "k2v-client"
-version = "0.1.1"
+version = "0.0.2"
authors = ["Trinity Pointard <trinity.pointard@gmail.com>", "Alex Auvolat <alex@adnab.me>"]
edition = "2018"
license = "AGPL-3.0"
@@ -24,10 +24,11 @@ tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi
# cli deps
clap = { version = "4.1", optional = true, features = ["derive", "env"] }
garage_util = { workspace = true, optional = true }
+garage_db = { workspace = true, optional = true }
[features]
-cli = ["clap", "tokio/fs", "tokio/io-std", "garage_util"]
+cli = ["clap", "tokio/fs", "tokio/io-std", "garage_util", "garage_db/sled"]
[lib]
path = "lib.rs"
diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs
index cdd63cce..e771fe26 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,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::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 +234,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 +253,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 => {
@@ -275,7 +279,7 @@ struct BatchOutputKind {
impl BatchOutputKind {
fn display_human_output(&self, values: BTreeMap<String, CausalValue>) -> ! {
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 {
@@ -284,7 +288,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 => {
@@ -520,7 +524,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::<Vec<_>>();
@@ -537,7 +541,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{}",
diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs
index ca52d0cf..3d1b5461 100644
--- a/src/k2v-client/lib.rs
+++ b/src/k2v-client/lib.rs
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use std::time::Duration;
+use base64::prelude::*;
use http::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE};
use http::status::StatusCode;
use http::HeaderMap;
@@ -375,7 +376,7 @@ impl K2vClient {
.unwrap_or_default();
let err_body_str = std::str::from_utf8(&err_body)
.map(String::from)
- .unwrap_or_else(|_| base64::encode(&err_body));
+ .unwrap_or_else(|_| BASE64_STANDARD.encode(&err_body));
if s.is_client_error() || s.is_server_error() {
error!("Error response {}: {}", res.status, err_body_str);
@@ -408,7 +409,7 @@ impl K2vClient {
"Response body: {}",
std::str::from_utf8(&body)
.map(String::from)
- .unwrap_or_else(|_| base64::encode(&body))
+ .unwrap_or_else(|_| BASE64_STANDARD.encode(&body))
);
Ok(Response {
@@ -482,9 +483,11 @@ impl<'de> Deserialize<'de> for K2vValue {
{
let val: Option<&str> = Option::deserialize(d)?;
Ok(match val {
- Some(s) => {
- K2vValue::Value(base64::decode(s).map_err(|_| DeError::custom("invalid base64"))?)
- }
+ Some(s) => K2vValue::Value(
+ BASE64_STANDARD
+ .decode(s)
+ .map_err(|_| DeError::custom("invalid base64"))?,
+ ),
None => K2vValue::Tombstone,
})
}
@@ -498,7 +501,7 @@ impl Serialize for K2vValue {
match self {
K2vValue::Tombstone => serializer.serialize_none(),
K2vValue::Value(v) => {
- let b64 = base64::encode(v);
+ let b64 = BASE64_STANDARD.encode(v);
serializer.serialize_str(&b64)
}
}