summaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcat-auth.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-12-31 14:57:29 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-12-31 14:57:29 -0800
commite16ba3d02564121ae5f27e0784be86137f3b9386 (patch)
treee1e19c2e1b678d041b64501c35a1ace6e8da900b /rust/src/bin/fatcat-auth.rs
parent230032ec1a13dd3830bcffed6112c2fddabc4b6e (diff)
downloadfatcat-e16ba3d02564121ae5f27e0784be86137f3b9386.tar.gz
fatcat-e16ba3d02564121ae5f27e0784be86137f3b9386.zip
rustfmt; implement role-based auth checks
Diffstat (limited to 'rust/src/bin/fatcat-auth.rs')
-rw-r--r--rust/src/bin/fatcat-auth.rs53
1 files changed, 25 insertions, 28 deletions
diff --git a/rust/src/bin/fatcat-auth.rs b/rust/src/bin/fatcat-auth.rs
index 3240964f..addd2b66 100644
--- a/rust/src/bin/fatcat-auth.rs
+++ b/rust/src/bin/fatcat-auth.rs
@@ -8,16 +8,16 @@ extern crate dotenv;
extern crate error_chain;
extern crate fatcat;
//#[macro_use]
-extern crate log;
extern crate env_logger;
+extern crate log;
extern crate serde_json;
extern crate uuid;
use clap::{App, SubCommand};
use diesel::prelude::*;
-use fatcat::errors::*;
use fatcat::api_helpers::FatCatId;
+use fatcat::errors::*;
use std::str::FromStr;
//use uuid::Uuid;
@@ -26,15 +26,13 @@ use std::str::FromStr;
//use std::io::prelude::*;
//use std::io::{BufReader, BufWriter};
-
fn run() -> Result<()> {
let m = App::new("fatcat-auth")
.version(env!("CARGO_PKG_VERSION"))
.author("Bryan Newbold <bnewbold@archive.org>")
.about("Editor authentication admin tool")
.subcommand(
- SubCommand::with_name("list-editors")
- .about("Prints all currently registered editors")
+ SubCommand::with_name("list-editors").about("Prints all currently registered editors"),
)
.subcommand(
SubCommand::with_name("create-editor")
@@ -42,41 +40,37 @@ fn run() -> Result<()> {
.args_from_usage(
"<username> 'username for editor'
--admin 'creates editor with admin privs'
- --bot 'this editor is a bot'"
- )
+ --bot 'this editor is a bot'",
+ ),
)
.subcommand(
SubCommand::with_name("create-token")
.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'", // TODO
+ ),
)
.subcommand(
SubCommand::with_name("inspect-token")
.about("Dumps token metadata (and whether it is valid)")
- .args_from_usage(
- "<token> 'base64-encoded token (macaroon)'"
- )
+ .args_from_usage("<token> 'base64-encoded token (macaroon)'"),
)
.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
- )
+ "--env-format 'outputs in a format that shells can source'", // TODO
+ ),
)
.subcommand(
SubCommand::with_name("revoke-tokens")
.about("Resets auth_epoch for a single editor (invalidating all existing tokens)")
- .args_from_usage(
- "<editor-id> 'identifier (fcid) of editor'"
- )
+ .args_from_usage("<editor-id> 'identifier (fcid) of editor'"),
)
.subcommand(
SubCommand::with_name("revoke-tokens-everyone")
- .about("Resets auth_epoch for all editors (invalidating tokens for all users!)")
+ .about("Resets auth_epoch for all editors (invalidating tokens for all users!)"),
)
.get_matches();
@@ -84,27 +78,30 @@ fn run() -> Result<()> {
match m.subcommand() {
("create-key", Some(_subm)) => {
println!("{}", fatcat::auth::create_key());
- return Ok(())
- },
+ return Ok(());
+ }
_ => (),
}
// Then the ones that do
- let db_conn = fatcat::database_worker_pool()?.get().expect("database pool");
+ let db_conn = fatcat::database_worker_pool()?
+ .get()
+ .expect("database pool");
let confectionary = fatcat::env_confectionary()?;
match m.subcommand() {
("list-editors", Some(_subm)) => {
fatcat::auth::print_editors(&db_conn)?;
- },
+ }
("create-editor", Some(subm)) => {
let editor = fatcat::api_helpers::create_editor(
&db_conn,
subm.value_of("username").unwrap().to_string(),
subm.is_present("admin"),
- subm.is_present("bot"))?;
+ subm.is_present("bot"),
+ )?;
//println!("{:?}", editor);
println!("{}", FatCatId::from_uuid(&editor.id).to_string());
- },
+ }
("create-token", Some(subm)) => {
let editor_id = FatCatId::from_str(subm.value_of("editor-id").unwrap())?;
// check that editor exists
@@ -112,19 +109,19 @@ fn run() -> Result<()> {
.find(&editor_id.to_uuid())
.get_result(&db_conn)?;
println!("{}", confectionary.create_token(editor_id, None)?);
- },
+ }
("inspect-token", Some(subm)) => {
confectionary.inspect_token(&db_conn, subm.value_of("token").unwrap())?;
- },
+ }
("revoke-tokens", Some(subm)) => {
let editor_id = FatCatId::from_str(subm.value_of("editor-id").unwrap())?;
fatcat::auth::revoke_tokens(&db_conn, editor_id)?;
println!("success!");
- },
+ }
("revoke-tokens-everyone", Some(_subm)) => {
fatcat::auth::revoke_tokens_everyone(&db_conn)?;
println!("success!");
- },
+ }
_ => {
println!("Missing or unimplemented command!");
println!("{}", m.usage());