From 21a932b6412cfa9610d3d40c95b34be6e52a97ce Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 11 Jan 2019 17:43:58 -0800 Subject: implement --env-format for fatcat-auth --- rust/src/bin/fatcat-auth.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'rust') diff --git a/rust/src/bin/fatcat-auth.rs b/rust/src/bin/fatcat-auth.rs index 652c0db5..de9ade15 100644 --- a/rust/src/bin/fatcat-auth.rs +++ b/rust/src/bin/fatcat-auth.rs @@ -32,7 +32,7 @@ fn main() -> Result<()> { .about("Creates a new auth token (macaroon) for the given editor") .args_from_usage( " 'id of the editor (fatcatid, not username)' - --env-format 'outputs in a format that shells can source'", // TODO + --env-format 'outputs in a format that shells can source'", ), ) .subcommand( @@ -43,9 +43,7 @@ fn main() -> Result<()> { .subcommand( SubCommand::with_name("create-key") .about("Creates a new auth secret key (aka, root/signing key for tokens)") - .args_from_usage( - "--env-format 'outputs in a format that shells can source'", // TODO - ), + .args_from_usage("--env-format 'outputs in a format that shells can source'"), ) .subcommand( SubCommand::with_name("revoke-tokens") @@ -60,8 +58,13 @@ fn main() -> Result<()> { // First, the commands with no db or confectionary needed match m.subcommand() { - ("create-key", Some(_subm)) => { - println!("{}", fatcat::auth::create_key()); + ("create-key", Some(subm)) => { + let key = fatcat::auth::create_key(); + if subm.is_present("env-format") { + println!("AUTH_SECRET_KEY=\"{}\"", key); + } else { + println!("{}", key); + } return Ok(()); } _ => (), @@ -90,7 +93,12 @@ fn main() -> Result<()> { } ("create-token", Some(subm)) => { let editor_id = FatcatId::from_str(subm.value_of("editor-id").unwrap())?; - println!("{}", confectionary.create_token(editor_id, None)?); + let token = confectionary.create_token(editor_id, None)?; + if subm.is_present("env-format") { + println!("FATCAT_AUTH_TOKEN=\"{}\"", token); + } else { + println!("{}", token); + } } ("inspect-token", Some(subm)) => { confectionary.inspect_token(&db_conn, subm.value_of("token").unwrap())?; -- cgit v1.2.3