From bc5c3e5e8d9f04d29e0fb2d99a7291ef15d5fa67 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 13:02:48 -0400 Subject: [PATCH 1/5] tsk-70: Moved contents of src/lib.rs elsewhere --- src/db/init.rs | 20 ++++++++++++++++++++ src/db/mod.rs | 5 +++++ src/main.rs | 33 +++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 src/db/init.rs create mode 100644 src/db/mod.rs diff --git a/src/db/init.rs b/src/db/init.rs new file mode 100644 index 0000000..aeb92d9 --- /dev/null +++ b/src/db/init.rs @@ -0,0 +1,20 @@ +use sqlx::postgres::PgPoolOptions; + +pub async fn create_pool() -> Result { + let database_url = icarus_envy::environment::get_db_url().await.value; + println!("Database url: {database_url}"); + + PgPoolOptions::new() + .max_connections(super::connection_settings::MAXCONN) + .connect(&database_url) + .await +} + +pub async fn migrations(pool: &sqlx::PgPool) { + // Run migrations using the sqlx::migrate! macro + // Assumes your migrations are in a ./migrations folder relative to Cargo.toml + sqlx::migrate!("./migrations") + .run(pool) + .await + .expect("Failed to run migrations"); +} diff --git a/src/db/mod.rs b/src/db/mod.rs new file mode 100644 index 0000000..823d2d7 --- /dev/null +++ b/src/db/mod.rs @@ -0,0 +1,5 @@ +pub mod init; + +mod connection_settings { + pub const MAXCONN: u32 = 5; +} diff --git a/src/main.rs b/src/main.rs index 8e3db29..388e3dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,10 @@ -use icarus_auth::callers; -use icarus_auth::config; +pub mod callers; +pub mod config; +pub mod db; +pub mod hashing; +pub mod repo; +pub mod token_stuff; + #[tokio::main] async fn main() { @@ -21,7 +26,7 @@ mod init { }; use utoipa::OpenApi; - use crate::callers; + use super::callers; use callers::common as common_callers; use callers::login as login_caller; use callers::register as register_caller; @@ -124,11 +129,11 @@ mod init { } pub async fn app() -> Router { - let pool = icarus_auth::db::create_pool() + let pool = super::db::init::create_pool() .await .expect("Failed to create pool"); - icarus_auth::db::migrations(&pool).await; + super::db::init::migrations(&pool).await; routes() .await @@ -216,8 +221,8 @@ mod tests { } } - fn get_test_register_request() -> icarus_auth::callers::register::request::Request { - icarus_auth::callers::register::request::Request { + fn get_test_register_request() -> callers::register::request::Request { + callers::register::request::Request { username: String::from("somethingsss"), password: String::from("Raindown!"), email: String::from("dev@null.com"), @@ -228,7 +233,7 @@ mod tests { } fn get_test_register_payload( - usr: &icarus_auth::callers::register::request::Request, + usr: &callers::register::request::Request, ) -> serde_json::Value { json!({ "username": &usr.username, @@ -245,7 +250,7 @@ mod tests { pub async fn register( app: &axum::Router, - usr: &icarus_auth::callers::register::request::Request, + usr: &super::callers::register::request::Request, ) -> Result { let payload = super::get_test_register_payload(&usr); let req = axum::http::Request::builder() @@ -298,7 +303,7 @@ mod tests { let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); - icarus_auth::db::migrations(&pool).await; + db::init::migrations(&pool).await; let app = init::routes().await.layer(axum::Extension(pool)); @@ -355,7 +360,7 @@ mod tests { let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); - icarus_auth::db::migrations(&pool).await; + db::init::migrations(&pool).await; let app = init::routes().await.layer(axum::Extension(pool)); @@ -443,7 +448,7 @@ mod tests { let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); - icarus_auth::db::migrations(&pool).await; + db::init::migrations(&pool).await; let app = init::routes().await.layer(axum::Extension(pool)); let passphrase = @@ -497,13 +502,13 @@ mod tests { let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); - icarus_auth::db::migrations(&pool).await; + db::init::migrations(&pool).await; let app = init::routes().await.layer(axum::Extension(pool)); let id = uuid::Uuid::parse_str("22f9c775-cce9-457a-a147-9dafbb801f61").unwrap(); let key = icarus_envy::environment::get_secret_key().await.value; - match icarus_auth::token_stuff::create_service_token(&key, &id) { + match token_stuff::create_service_token(&key, &id) { Ok((token, _expire)) => { let payload = serde_json::json!({ "access_token": token -- 2.43.0 From 3c710c33677d91bc2fe26e72721538f1e943a115 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 13:03:05 -0400 Subject: [PATCH 2/5] tsk-70: Saving changes --- src/lib.rs | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 19c66a2..9c6d32f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,36 +1,2 @@ // TODO: Get rid of this file and place the code in more appropriate places -pub mod callers; -pub mod config; -pub mod hashing; -pub mod repo; -pub mod token_stuff; -mod connection_settings { - pub const MAXCONN: u32 = 5; -} - -pub mod db { - - use sqlx::postgres::PgPoolOptions; - - use crate::connection_settings; - - pub async fn create_pool() -> Result { - let database_url = icarus_envy::environment::get_db_url().await.value; - println!("Database url: {database_url}"); - - PgPoolOptions::new() - .max_connections(connection_settings::MAXCONN) - .connect(&database_url) - .await - } - - pub async fn migrations(pool: &sqlx::PgPool) { - // Run migrations using the sqlx::migrate! macro - // Assumes your migrations are in a ./migrations folder relative to Cargo.toml - sqlx::migrate!("./migrations") - .run(pool) - .await - .expect("Failed to run migrations"); - } -} -- 2.43.0 From d67673584e8e9145759f412c683c7e2c7c7eb943 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 13:03:26 -0400 Subject: [PATCH 3/5] tsk-70: Removing src/lib.rs --- src/lib.rs | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 src/lib.rs diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 9c6d32f..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -// TODO: Get rid of this file and place the code in more appropriate places - -- 2.43.0 From ff93dd801669511c5bf41fd175a1c4e32138de5d Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 13:03:44 -0400 Subject: [PATCH 4/5] tsk-70: Code formatting --- src/main.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 388e3dc..05967a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ pub mod hashing; pub mod repo; pub mod token_stuff; - #[tokio::main] async fn main() { // initialize tracing @@ -232,9 +231,7 @@ mod tests { } } - fn get_test_register_payload( - usr: &callers::register::request::Request, - ) -> serde_json::Value { + fn get_test_register_payload(usr: &callers::register::request::Request) -> serde_json::Value { json!({ "username": &usr.username, "password": &usr.password, -- 2.43.0 From 711581f8a745dc2355c9effc4b24b8f2fc79eeb2 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 13:04:08 -0400 Subject: [PATCH 5/5] tsk-70: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32da969..20a1c23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -748,7 +748,7 @@ dependencies = [ [[package]] name = "icarus_auth" -version = "0.6.3" +version = "0.6.4" dependencies = [ "argon2", "axum", diff --git a/Cargo.toml b/Cargo.toml index 2c46d94..d5b3042 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_auth" -version = "0.6.3" +version = "0.6.4" edition = "2024" rust-version = "1.90" -- 2.43.0