Skip to content

Commit

Permalink
feat: Update fencing token to accept base64 instead of base16 (#106)
Browse files Browse the repository at this point in the history
Signed-off-by: Vaibhav Rabber <[email protected]>
  • Loading branch information
vrongmeal authored Dec 31, 2024
1 parent f57611e commit fd92516
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path = "src/main.rs"

[dependencies]
async-stream = "0.3.6"
base16ct = { version = "0.2.0", features = ["alloc"] }
base64ct = { version = "1.6.0", features = ["alloc"] }
clap = { version = "4.5.20", features = ["derive"] }
color-print = "0.3.6"
colored = "2.1.0"
Expand Down
18 changes: 11 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
};

use account::AccountService;
use base64ct::{Base64, Encoding};
use basin::BasinService;
use clap::{builder::styling, Parser, Subcommand};
use colored::*;
Expand Down Expand Up @@ -213,7 +214,7 @@ enum Commands {
/// and any regression will be ignored.
trim_point: u64,

/// Enforce fencing token specified in hex.
/// Enforce fencing token specified in base64.
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

Expand All @@ -233,12 +234,12 @@ enum Commands {
#[arg(value_name = "S2_URI")]
uri: S2BasinAndStreamUri,

/// New fencing token specified in hex.
/// New fencing token specified in base64.
/// It may be upto 16 bytes, and can be empty.
#[arg(value_parser = parse_fencing_token)]
new_fencing_token: FencingToken,

/// Enforce existing fencing token, specified in hex.
/// Enforce existing fencing token, specified in base64.
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

Expand All @@ -254,7 +255,7 @@ enum Commands {
#[arg(value_name = "S2_URI")]
uri: S2BasinAndStreamUri,

/// Enforce fencing token specified in hex.
/// Enforce fencing token specified in base64.
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

Expand Down Expand Up @@ -410,8 +411,8 @@ fn parse_records_output_source(s: &str) -> Result<RecordsOut, std::io::Error> {
}

fn parse_fencing_token(s: &str) -> Result<FencingToken, ConvertError> {
base16ct::mixed::decode_vec(s)
.map_err(|_| "invalid hex")?
Base64::decode_vec(s)
.map_err(|_| "invalid base64")?
.try_into()
}

Expand Down Expand Up @@ -860,7 +861,10 @@ async fn run() -> Result<(), S2CliError> {
let (cmd, description) = match command_record {
CommandRecord::Fence { fencing_token } => (
"fence",
format!("FencingToken({})", base16ct::lower::encode_string(fencing_token.as_ref())),
format!(
"FencingToken({})",
Base64::encode_string(fencing_token.as_ref()),
),
),
CommandRecord::Trim { seq_num } => (
"trim",
Expand Down

0 comments on commit fd92516

Please sign in to comment.