Skip to content

Commit e22340c

Browse files
add strip password flag (#33)
* add strip password flag * fix pack test * prevent strip if flag is not set * use set password * None instead of Some() * change to no_strip_password and use context for errors * change to no_strip_password and use context for errors * cleaner handling of password stipping * fix formatting --------- Co-authored-by: Muhamad Azamy <muhamad@incubaid.com>
1 parent a17dbc6 commit e22340c

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod test {
6464
store.add(0x00, 0x7f, Box::new(store0));
6565
store.add(0x80, 0xff, Box::new(store1));
6666

67-
pack(writer, store, &source).await.unwrap();
67+
pack(writer, store, &source, false).await.unwrap();
6868

6969
println!("packing complete");
7070
// recreate the stores for reading.

src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ struct PackOptions {
6767
#[clap(short, long, action=ArgAction::Append)]
6868
store: Vec<String>,
6969

70+
/// no_strip_password strips password from store url, otherwise password will be stored in the fl and then shipped
71+
/// some stores like ZDB has a public namespace which means writing requires a password
72+
#[clap(long, default_value_t = false)]
73+
no_strip_password: bool,
74+
7075
/// target directory to upload
7176
target: String,
7277
}
@@ -120,7 +125,7 @@ fn pack(opts: PackOptions) -> Result<()> {
120125
rt.block_on(async move {
121126
let store = parse_router(opts.store.as_slice()).await?;
122127
let meta = fungi::Writer::new(opts.meta).await?;
123-
rfs::pack(meta, store, opts.target).await?;
128+
rfs::pack(meta, store, opts.target, !opts.no_strip_password).await?;
124129

125130
Ok(())
126131
})

src/pack.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,33 @@ struct Item(Ino, PathBuf, OsString, Metadata);
1818
/// it's logically incorrect to store multiple filessytem in the same FL.
1919
/// All file chunks will then be uploaded to the provided store
2020
///
21-
pub async fn pack<P: Into<PathBuf>, S: Store>(writer: Writer, store: S, root: P) -> Result<()> {
21+
pub async fn pack<P: Into<PathBuf>, S: Store>(
22+
writer: Writer,
23+
store: S,
24+
root: P,
25+
strip_password: bool,
26+
) -> Result<()> {
2227
use tokio::fs;
2328

2429
// building routing table from store information
2530
for route in store.routes() {
31+
let mut store_url = route.url;
32+
33+
if strip_password {
34+
let mut url = url::Url::parse(&store_url).context("failed to parse store url")?;
35+
if url.password().is_some() {
36+
url.set_password(None)
37+
.map_err(|_| anyhow::anyhow!("failed to strip password"))?;
38+
39+
store_url = url.to_string();
40+
}
41+
}
42+
2643
writer
2744
.route(
2845
route.start.unwrap_or(u8::MIN),
2946
route.end.unwrap_or(u8::MAX),
30-
route.url,
47+
store_url,
3148
)
3249
.await?;
3350
}

0 commit comments

Comments
 (0)