diff --git a/.gitignore b/.gitignore index 26ce53f..021583e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules dist result *.tgz +file-service/auth.sqlite diff --git a/Cargo.lock b/Cargo.lock index f3f6976..39219d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,6 +74,54 @@ dependencies = [ "winapi", ] +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -331,12 +379,52 @@ dependencies = [ "ansi_term", "atty", "bitflags 1.3.2", - "strsim", + "strsim 0.8.0", "textwrap", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.10.0", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.29", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + [[package]] name = "cloudabi" version = "0.0.3" @@ -352,6 +440,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "config" version = "0.1.0" @@ -747,6 +841,7 @@ dependencies = [ "build_html", "bytes", "chrono", + "clap 4.4.6", "cool_asserts", "futures-util", "hex-string", @@ -2421,7 +2516,7 @@ name = "orizentic" version = "1.0.1" dependencies = [ "chrono", - "clap", + "clap 2.34.0", "itertools 0.10.5", "jsonwebtoken", "serde 1.0.188", @@ -3679,6 +3774,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.5.0" @@ -4233,6 +4334,12 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "0.4.0" diff --git a/file-service/Cargo.toml b/file-service/Cargo.toml index 0aabb3c..0766c1e 100644 --- a/file-service/Cargo.toml +++ b/file-service/Cargo.toml @@ -9,6 +9,14 @@ edition = "2018" [features] auth-cli = [ "clap" ] +[lib] +name = "file_service" +path = "src/lib.rs" + +[[bin]] +name = "file-service" +path = "src/main.rs" + [[bin]] name = "auth-cli" path = "src/bin/cli.rs" diff --git a/file-service/src/bin/cli.rs b/file-service/src/bin/cli.rs new file mode 100644 index 0000000..5c1d3b5 --- /dev/null +++ b/file-service/src/bin/cli.rs @@ -0,0 +1,44 @@ +use clap::{Parser, Subcommand}; +use file_service::{AuthDB, Username}; +use std::path::PathBuf; + +#[derive(Subcommand, Debug)] +enum Commands { + AddUser { username: String }, + DeleteUser { username: String }, + ListUsers, +} + +#[derive(Parser, Debug)] +struct Args { + #[command(subcommand)] + command: Commands, +} + +#[tokio::main] +pub async fn main() { + let args = Args::parse(); + let authdb = AuthDB::new(PathBuf::from(&std::env::var("AUTHDB").unwrap())) + .await + .expect("to be able to open the database"); + + match args.command { + Commands::AddUser { username } => { + match authdb.add_user(Username::from(username.clone())).await { + Ok(token) => { + println!( + "User {} created. Auth token: {}", + username, + token.to_string() + ); + } + Err(err) => { + println!("Could not create user {}", username); + println!("\tError: {:?}", err); + } + } + } + Commands::DeleteUser { username } => {} + Commands::ListUsers => {} + } +} diff --git a/file-service/src/main.rs b/file-service/src/main.rs index 8c885de..7f5a3db 100644 --- a/file-service/src/main.rs +++ b/file-service/src/main.rs @@ -175,7 +175,9 @@ fn with_session() -> impl Filter + pub async fn main() { pretty_env_logger::init(); - let authdb = AuthDB::new(PathBuf::from(":memory:")).await.unwrap(); + let authdb = AuthDB::new(PathBuf::from(&std::env::var("AUTHDB").unwrap())) + .await + .unwrap(); let store = Store::new(PathBuf::from(&std::env::var("FILE_SHARE_DIR").unwrap())); let app = App::new(authdb, store);