Skip to content

Commit

Permalink
feat: supports authorization environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkwc committed Jun 9, 2024
1 parent 9f24352 commit 8801ed4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Usage: agscheduler-cli [OPTIONS]

Options:
-e, --endpoint <ENDPOINT> AGScheduler HTTP endpoint [default: http://127.0.0.1:36370]
-p, --password <PASSWORD> AGScheduler password [default: ]
-p, --password <PASSWORD> AGScheduler password
You can also use the AGSCHEDULERCLI_AUTH environment variable to pass this password more safely [default: ]
-h, --help Print help
-V, --version Print version

Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

use std::env;

use clap::Parser;
use dialoguer::{theme::ColorfulTheme, Select};
use sha2::{Digest, Sha256};
Expand All @@ -16,7 +18,8 @@ struct Args {
#[arg(short, long, default_value = "http://127.0.0.1:36370")]
endpoint: String,
/// AGScheduler password
#[arg(short, long, default_value = "")]
/// You can also use the AGSCHEDULERCLI_AUTH environment variable to pass this password more safely
#[arg(short, long, default_value = "", verbatim_doc_comment)]
password: String,
}

Expand All @@ -25,9 +28,13 @@ struct Args {
async fn main() {
let args = Args::parse();

let mut auth = env::var("AGSCHEDULERCLI_AUTH").unwrap_or("".to_string());
if !args.password.is_empty() {
auth = args.password;
}
if !auth.is_empty() {
unsafe {
let hash = Sha256::digest(args.password);
let hash = Sha256::digest(auth);
http::PASSWORD_SHA2 = hex::encode(hash);
}
}
Expand Down

0 comments on commit 8801ed4

Please sign in to comment.