dls: add password hash function
This commit is contained in:
+21
-6
@@ -36,6 +36,10 @@ enum Command {
|
||||
},
|
||||
#[command(subcommand)]
|
||||
DlSet(DlSet),
|
||||
/// hash a password
|
||||
Hash {
|
||||
salt: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -103,14 +107,16 @@ async fn main() -> eyre::Result<()> {
|
||||
.parse_default_env()
|
||||
.init();
|
||||
|
||||
let token = std::env::var("DLS_TOKEN").map_err(|_| format_err!("DLS_TOKEN should be set"))?;
|
||||
|
||||
let dls = dls::Client::new(cli.dls, token);
|
||||
let dls = || {
|
||||
let token = std::env::var("DLS_TOKEN").expect("DLS_TOKEN should be set");
|
||||
dls::Client::new(cli.dls, token)
|
||||
};
|
||||
|
||||
use Command as C;
|
||||
match cli.command {
|
||||
C::Clusters => write_json(&dls.clusters().await?),
|
||||
C::Clusters => write_json(&dls().clusters().await?),
|
||||
C::Cluster { cluster, command } => {
|
||||
let dls = dls();
|
||||
let cluster = dls.cluster(cluster);
|
||||
|
||||
use ClusterCommand as CC;
|
||||
@@ -155,8 +161,9 @@ async fn main() -> eyre::Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
C::Hosts => write_json(&dls.hosts().await?),
|
||||
C::Hosts => write_json(&dls().hosts().await?),
|
||||
C::Host { out, host, asset } => {
|
||||
let dls = dls();
|
||||
let host_name = host.clone();
|
||||
let host = dls.host(host);
|
||||
match asset {
|
||||
@@ -171,7 +178,7 @@ async fn main() -> eyre::Result<()> {
|
||||
C::DlSet(set) => match set {
|
||||
DlSet::Sign { expiry, items } => {
|
||||
let req = dls::DownloadSetReq { expiry, items };
|
||||
let signed = dls.sign_dl_set(&req).await?;
|
||||
let signed = dls().sign_dl_set(&req).await?;
|
||||
println!("{signed}");
|
||||
}
|
||||
DlSet::Show { signed_set } => {
|
||||
@@ -211,11 +218,19 @@ async fn main() -> eyre::Result<()> {
|
||||
name,
|
||||
asset,
|
||||
} => {
|
||||
let dls = dls();
|
||||
let stream = dls.fetch_dl_set(&signed_set, &kind, &name, &asset).await?;
|
||||
let mut out = create_asset_file(out, &kind, &name, &asset).await?;
|
||||
copy_stream(stream, &mut out).await?;
|
||||
}
|
||||
},
|
||||
C::Hash { salt } => {
|
||||
let salt = dkl::base64_decode(&salt)?;
|
||||
let passphrase = rpassword::prompt_password("password to hash: ")?;
|
||||
let hash = dls::store::hash_password(&salt, &passphrase)?;
|
||||
println!("hash (hex): {}", hex::encode(&hash));
|
||||
println!("hash (base64): {}", dkl::base64_encode(&hash));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user