aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcat-auth.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-11 17:43:58 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-11 17:46:32 -0800
commit21a932b6412cfa9610d3d40c95b34be6e52a97ce (patch)
treed48a046809de31f9763eafaa3e35ebbe01a906f7 /rust/src/bin/fatcat-auth.rs
parent98a5b7f00ad36fd84583b3b21387b85c9e42bd49 (diff)
downloadfatcat-21a932b6412cfa9610d3d40c95b34be6e52a97ce.tar.gz
fatcat-21a932b6412cfa9610d3d40c95b34be6e52a97ce.zip
implement --env-format for fatcat-auth
Diffstat (limited to 'rust/src/bin/fatcat-auth.rs')
-rw-r--r--rust/src/bin/fatcat-auth.rs22
1 files changed, 15 insertions, 7 deletions
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(
"<editor-id> '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())?;