Database setup started

This commit is contained in:
Nevernown 2025-11-15 11:27:51 +01:00
parent 966ad6809b
commit 194b564e43
7 changed files with 120 additions and 6 deletions

73
Cargo.lock generated
View File

@ -78,12 +78,30 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 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]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]] [[package]]
name = "form_urlencoded" name = "form_urlencoded"
version = "1.2.2" version = "1.2.2"
@ -126,6 +144,24 @@ dependencies = [
"pin-utils", "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]] [[package]]
name = "http" name = "http"
version = "1.3.1" version = "1.3.1"
@ -215,6 +251,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"axum", "axum",
"log", "log",
"rusqlite",
"serde", "serde",
"sigma", "sigma",
"tokio", "tokio",
@ -240,6 +277,16 @@ version = "0.2.177"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" 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]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.14" version = "0.4.14"
@ -340,6 +387,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.103" version = "1.0.103"
@ -367,6 +420,20 @@ dependencies = [
"bitflags", "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]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.20" version = "1.0.20"
@ -652,6 +719,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.1+wasi-snapshot-preview1" version = "0.11.1+wasi-snapshot-preview1"

View File

@ -1,3 +1,3 @@
[workspace] [workspace]
resolver = "3" resolver = "3"
members = ["core", "identity"] members = ["core", "identity", "sigma"]

BIN
identity.db Normal file

Binary file not shown.

View File

@ -11,3 +11,4 @@ tokio = { version = "1.43.0", features = ["full"] }
tracing = "0.1.41" tracing = "0.1.41"
tracing-subscriber = "0.3.19" tracing-subscriber = "0.3.19"
sigma = { path = "../sigma" } sigma = { path = "../sigma" }
rusqlite = "0.37.0"

View File

@ -1,22 +1,58 @@
use axum::{routing::get, Json, Router}; use axum::{Json, Router, http::StatusCode, routing::get};
#[allow(unused)] #[allow(unused)]
use log::{info, debug, warn, error, trace}; use log::{info, debug, warn, error, trace};
use rusqlite::Connection;
use sigma::repsonse::SigmaInformation; use sigma::repsonse::SigmaInformation;
use tracing::instrument; use tracing::instrument;
const NAME: &str = "TinyIdentity"; const NAME: &str = "TinyIdentity";
const VERSION: &str = "0.0.0.1"; 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 { pub fn router() -> Router {
info!("Loading {NAME} app routes"); info!("Loading {NAME} app routes");
debug!("{NAME} version is {VERSION}"); debug!("{NAME} version is {VERSION}");
Router::new() Router::new()
.route("/", get(information)) .route("/", get(information))
.route("/setup", get(dummy)) .route("/setup", get(setup))
.route("/me", get(dummy)) .route("/me", get(dummy))
} }
#[instrument]
async fn setup() -> Result<StatusCode, StatusCode> {
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] #[instrument]
async fn dummy() -> Json<()> { async fn dummy() -> Json<()> {
Json(()) Json(())

View File

@ -5,3 +5,7 @@ GET http://127.0.0.1:3000/
GET http://127.0.0.1:3000/identity GET http://127.0.0.1:3000/identity
### ###
GET http://127.0.0.1:3000/identity/setup
###