aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-05-16 18:34:46 +0200
committerAlex Auvolat <alex@adnab.me>2023-05-16 19:46:56 +0200
commite4f955d672af99d1bf25e6a0bb038d116f8bca0c (patch)
tree162fe0927e1edbd168d5f06e4c2396dbcd0be6f1 /src
parentea9b15f669703eb74e340599dd1fbc216bb38df8 (diff)
downloadgarage-e4f955d672af99d1bf25e6a0bb038d116f8bca0c.tar.gz
garage-e4f955d672af99d1bf25e6a0bb038d116f8bca0c.zip
fix base64 uses
Diffstat (limited to 'src')
-rw-r--r--src/k2v-client/Cargo.toml3
-rw-r--r--src/k2v-client/bin/k2v-cli.rs10
-rw-r--r--src/k2v-client/lib.rs9
3 files changed, 13 insertions, 9 deletions
diff --git a/src/k2v-client/Cargo.toml b/src/k2v-client/Cargo.toml
index f49d3205..604099ea 100644
--- a/src/k2v-client/Cargo.toml
+++ b/src/k2v-client/Cargo.toml
@@ -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..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 => {
diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs
index ca52d0cf..548838f8 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 {
@@ -483,7 +484,7 @@ 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"))?)
+ K2vValue::Value(BASE64_STANDARD.decode(s).map_err(|_| DeError::custom("invalid base64"))?)
}
None => K2vValue::Tombstone,
})
@@ -498,7 +499,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)
}
}