diff options
| -rw-r--r-- | .github/workflows/build.yml | 1 | ||||
| -rw-r--r-- | Cargo.lock | 15 | ||||
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | src/main.rs | 33 |
5 files changed, 37 insertions, 17 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9e7f700..ae8f4a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,6 @@ jobs: job: - { os: macos-latest } - { os: ubuntu-latest } - - { os: windows-latest } name: Build @@ -350,7 +350,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cgit-simple-authentication" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "base64", @@ -366,9 +366,9 @@ dependencies = [ "serde_derive", "serde_json", "sha2", - "simple-logging", "sqlx", "tokio 1.5.0", + "tokio-stream", "toml", "url", ] @@ -1704,17 +1704,6 @@ dependencies = [ ] [[package]] -name = "simple-logging" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00d48e85675326bb182a2286ea7c1a0b264333ae10f27a937a72be08628b542" -dependencies = [ - "lazy_static", - "log", - "thread-id", -] - -[[package]] name = "slab" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1,6 +1,6 @@ [package] name = "cgit-simple-authentication" -version = "0.1.3" +version = "0.1.4" authors = ["KunoiSayami <[email protected]>"] edition = "2018" @@ -21,8 +21,8 @@ url = "2.1" redis = { version = "0.17", features = ["tokio-comp"] } sha2 = "0.9" base64 = "0.13" -simple-logging = "2" log4rs = "1" +tokio-stream = "0.1" [target.aarch64-unknown-linux-musl.dependencies] openssl = { version = "0.10", features = ["vendored"] }
\ No newline at end of file @@ -1,5 +1,6 @@ # Cgit simple authentication +This project is currently developing, minor version may incompatible with previous minor version. ## Source diff --git a/src/main.rs b/src/main.rs index 9d6f78e..9c15d87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,7 @@ use sqlx::Connection; use std::env; use std::io::{stdin, Read}; use std::result::Result::Ok; +use tokio_stream::StreamExt as _; const COOKIE_LENGTH: usize = 45; @@ -256,6 +257,32 @@ async fn cmd_add_user(matches: &ArgMatches<'_>, cfg: Config) -> Result<()> { Ok(()) } +async fn cmd_list_user(cfg: Config) -> Result<()> { + let mut conn = sqlx::SqliteConnection::connect(cfg.get_database_location()).await?; + + let (count,) = sqlx::query_as::<_, (i32,)>(r#"SELECT COUNT(*) FROM "accounts""#) + .fetch_one(&mut conn) + .await?; + + if count > 0 { + let mut iter = + sqlx::query_as::<_, (String,)>(r#"SELECT "user" FROM "accounts""#).fetch(&mut conn); + + println!( + "There is {} user{} in database", + count, + if count > 1 { "s" } else { "" } + ); + while let Some(Ok((row,))) = iter.next().await { + println!("{}", row) + } + } else { + println!("There is not user exists.") + } + + Ok(()) +} + async fn async_main(arg_matches: ArgMatches<'_>, cfg: Config) -> Result<i32> { match arg_matches.subcommand() { ("authenticate-cookie", Some(matches)) => { @@ -278,6 +305,9 @@ async fn async_main(arg_matches: ArgMatches<'_>, cfg: Config) -> Result<i32> { ("adduser", Some(matches)) => { cmd_add_user(matches, cfg).await?; } + ("users", Some(_matches)) => { + cmd_list_user(cfg).await?; + } _ => {} } Ok(0) @@ -286,7 +316,7 @@ async fn async_main(arg_matches: ArgMatches<'_>, cfg: Config) -> Result<i32> { fn main() -> Result<()> { let logfile = FileAppender::builder() .encoder(Box::new(PatternEncoder::new( - "{d(%H:%M:%S)}-{M}-{l} - {m}\n", + "{d(%Y-%m-%d %H:%M:%S)}- {h({l})} - {m}{n}", ))) .build("/tmp/output.log")?; @@ -350,6 +380,7 @@ fn main() -> Result<()> { .args(sub_args), ) .subcommand(SubCommand::with_name("init").about("Init sqlite database")) + .subcommand(SubCommand::with_name("users").about("List all register user in database")) .subcommand( SubCommand::with_name("adduser") .about("Add user to database") |
