Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add strip password flag #33

Merged
merged 10 commits into from
Oct 17, 2023
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod test {
store.add(0x00, 0x7f, Box::new(store0));
store.add(0x80, 0xff, Box::new(store1));

pack(writer, store, &source).await.unwrap();
pack(writer, store, &source, false).await.unwrap();

println!("packing complete");
// recreate the stores for reading.
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ struct PackOptions {
#[clap(short, long, action=ArgAction::Append)]
store: Vec<String>,

/// no_strip_password strips password from store url, otherwise password will be stored in the fl and then shipped
/// some stores like ZDB has a public namespace which means writing requires a password
#[clap(long, default_value_t = false)]
no_strip_password: bool,

/// target directory to upload
target: String,
}
Expand Down Expand Up @@ -120,7 +125,7 @@ fn pack(opts: PackOptions) -> Result<()> {
rt.block_on(async move {
let store = parse_router(opts.store.as_slice()).await?;
let meta = fungi::Writer::new(opts.meta).await?;
rfs::pack(meta, store, opts.target).await?;
rfs::pack(meta, store, opts.target, !opts.no_strip_password).await?;

Ok(())
})
Expand Down
21 changes: 19 additions & 2 deletions src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,33 @@ struct Item(Ino, PathBuf, OsString, Metadata);
/// it's logically incorrect to store multiple filessytem in the same FL.
/// All file chunks will then be uploaded to the provided store
///
pub async fn pack<P: Into<PathBuf>, S: Store>(writer: Writer, store: S, root: P) -> Result<()> {
pub async fn pack<P: Into<PathBuf>, S: Store>(
writer: Writer,
store: S,
root: P,
strip_password: bool,
) -> Result<()> {
use tokio::fs;

// building routing table from store information
for route in store.routes() {
let mut store_url = route.url;

if strip_password {
let mut url = url::Url::parse(&store_url).context("failed to parse store url")?;
if url.password().is_some() {
url.set_password(None)
.map_err(|_| anyhow::anyhow!("failed to strip password"))?;

store_url = url.to_string();
}
}

writer
.route(
route.start.unwrap_or(u8::MIN),
route.end.unwrap_or(u8::MAX),
route.url,
store_url,
)
.await?;
}
Expand Down
Loading