diff --git a/Cargo.lock b/Cargo.lock index 64d32c1..ceace74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,12 +78,30 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -126,6 +144,24 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown", +] + [[package]] name = "http" version = "1.3.1" @@ -215,6 +251,7 @@ version = "0.1.0" dependencies = [ "axum", "log", + "rusqlite", "serde", "sigma", "tokio", @@ -240,6 +277,16 @@ version = "0.2.177" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" +[[package]] +name = "libsqlite3-sys" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f" +dependencies = [ + "pkg-config", + "vcpkg", +] + [[package]] name = "lock_api" version = "0.4.14" @@ -340,6 +387,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "proc-macro2" version = "1.0.103" @@ -367,6 +420,20 @@ dependencies = [ "bitflags", ] +[[package]] +name = "rusqlite" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f" +dependencies = [ + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", +] + [[package]] name = "ryu" version = "1.0.20" @@ -652,6 +719,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index b7ed8bd..62b9cd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "3" -members = ["core", "identity"] \ No newline at end of file +members = ["core", "identity", "sigma"] \ No newline at end of file diff --git a/identity.db b/identity.db new file mode 100644 index 0000000..ca64474 Binary files /dev/null and b/identity.db differ diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 151f243..a356c6d 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -10,4 +10,5 @@ serde = { version = "1.0.217", features = ["derive"] } tokio = { version = "1.43.0", features = ["full"] } tracing = "0.1.41" tracing-subscriber = "0.3.19" -sigma = { path = "../sigma" } \ No newline at end of file +sigma = { path = "../sigma" } +rusqlite = "0.37.0" diff --git a/identity/src/lib.rs b/identity/src/lib.rs index 14ba309..3f55b55 100644 --- a/identity/src/lib.rs +++ b/identity/src/lib.rs @@ -1,22 +1,58 @@ -use axum::{routing::get, Json, Router}; +use axum::{Json, Router, http::StatusCode, routing::get}; #[allow(unused)] use log::{info, debug, warn, error, trace}; +use rusqlite::Connection; use sigma::repsonse::SigmaInformation; use tracing::instrument; - const NAME: &str = "TinyIdentity"; const VERSION: &str = "0.0.0.1"; +const DB_PATH: &str = "identity.db"; +const DB_CREATE_USER_TABLE: &str = + "CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + pass TEXT NOT NULL + )"; +const DB_CREATE_META_TABLE: &str = + "CREATE TABLE IF NOT EXISTS meta ( + key VARCHAR(16) PRIMARY KEY, + value TEXT NOT NULL + )"; + + pub fn router() -> Router { info!("Loading {NAME} app routes"); debug!("{NAME} version is {VERSION}"); Router::new() .route("/", get(information)) - .route("/setup", get(dummy)) + .route("/setup", get(setup)) .route("/me", get(dummy)) } +#[instrument] +async fn setup() -> Result { + let connection = Connection::open(DB_PATH); + if let Err(e) = connection { + error!("{:?}", e); + return Err(StatusCode::INTERNAL_SERVER_ERROR) + } + let connection = connection.expect("Connection cannot be an error here."); + + if let Err(e) = connection.execute(DB_CREATE_USER_TABLE, [],) { + error!("{:?}", e); + return Err(StatusCode::INTERNAL_SERVER_ERROR) + } + + if let Err(e) = connection.execute(DB_CREATE_META_TABLE, [],) { + error!("{:?}", e); + return Err(StatusCode::INTERNAL_SERVER_ERROR) + } + + Ok(StatusCode::OK) +} + #[instrument] async fn dummy() -> Json<()> { Json(()) diff --git a/sigma/src/repsonse.rs b/sigma/src/repsonse.rs index 7b6a2f5..f1e1493 100644 --- a/sigma/src/repsonse.rs +++ b/sigma/src/repsonse.rs @@ -12,4 +12,4 @@ impl SigmaInformation { name: name.into() } } -} \ No newline at end of file +} diff --git a/test.http b/test.http index 56da423..d9498d9 100644 --- a/test.http +++ b/test.http @@ -4,4 +4,8 @@ GET http://127.0.0.1:3000/ GET http://127.0.0.1:3000/identity +### + +GET http://127.0.0.1:3000/identity/setup + ### \ No newline at end of file