tsk-70: Remove src/lib.rs (#74)
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 39s
Rust Build / Test Suite (push) Successful in 1m8s
Rust Build / Rustfmt (push) Successful in 33s
Rust Build / Clippy (push) Successful in 41s
Rust Build / build (push) Successful in 59s
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 39s
Rust Build / Test Suite (push) Successful in 1m8s
Rust Build / Rustfmt (push) Successful in 33s
Rust Build / Clippy (push) Successful in 41s
Rust Build / build (push) Successful in 59s
Closes #70 Reviewed-on: #74 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -748,7 +748,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_auth"
|
name = "icarus_auth"
|
||||||
version = "0.6.3"
|
version = "0.6.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"axum",
|
"axum",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_auth"
|
name = "icarus_auth"
|
||||||
version = "0.6.3"
|
version = "0.6.4"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
20
src/db/init.rs
Normal file
20
src/db/init.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use sqlx::postgres::PgPoolOptions;
|
||||||
|
|
||||||
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
|
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");
|
||||||
|
}
|
5
src/db/mod.rs
Normal file
5
src/db/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod init;
|
||||||
|
|
||||||
|
mod connection_settings {
|
||||||
|
pub const MAXCONN: u32 = 5;
|
||||||
|
}
|
36
src/lib.rs
36
src/lib.rs
@@ -1,36 +0,0 @@
|
|||||||
// 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<sqlx::PgPool, sqlx::Error> {
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
34
src/main.rs
34
src/main.rs
@@ -1,5 +1,9 @@
|
|||||||
use icarus_auth::callers;
|
pub mod callers;
|
||||||
use icarus_auth::config;
|
pub mod config;
|
||||||
|
pub mod db;
|
||||||
|
pub mod hashing;
|
||||||
|
pub mod repo;
|
||||||
|
pub mod token_stuff;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@@ -21,7 +25,7 @@ mod init {
|
|||||||
};
|
};
|
||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
use crate::callers;
|
use super::callers;
|
||||||
use callers::common as common_callers;
|
use callers::common as common_callers;
|
||||||
use callers::login as login_caller;
|
use callers::login as login_caller;
|
||||||
use callers::register as register_caller;
|
use callers::register as register_caller;
|
||||||
@@ -124,11 +128,11 @@ mod init {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn app() -> Router {
|
pub async fn app() -> Router {
|
||||||
let pool = icarus_auth::db::create_pool()
|
let pool = super::db::init::create_pool()
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create pool");
|
.expect("Failed to create pool");
|
||||||
|
|
||||||
icarus_auth::db::migrations(&pool).await;
|
super::db::init::migrations(&pool).await;
|
||||||
|
|
||||||
routes()
|
routes()
|
||||||
.await
|
.await
|
||||||
@@ -216,8 +220,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_test_register_request() -> icarus_auth::callers::register::request::Request {
|
fn get_test_register_request() -> callers::register::request::Request {
|
||||||
icarus_auth::callers::register::request::Request {
|
callers::register::request::Request {
|
||||||
username: String::from("somethingsss"),
|
username: String::from("somethingsss"),
|
||||||
password: String::from("Raindown!"),
|
password: String::from("Raindown!"),
|
||||||
email: String::from("dev@null.com"),
|
email: String::from("dev@null.com"),
|
||||||
@@ -227,9 +231,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_test_register_payload(
|
fn get_test_register_payload(usr: &callers::register::request::Request) -> serde_json::Value {
|
||||||
usr: &icarus_auth::callers::register::request::Request,
|
|
||||||
) -> serde_json::Value {
|
|
||||||
json!({
|
json!({
|
||||||
"username": &usr.username,
|
"username": &usr.username,
|
||||||
"password": &usr.password,
|
"password": &usr.password,
|
||||||
@@ -245,7 +247,7 @@ mod tests {
|
|||||||
|
|
||||||
pub async fn register(
|
pub async fn register(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
usr: &icarus_auth::callers::register::request::Request,
|
usr: &super::callers::register::request::Request,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
let payload = super::get_test_register_payload(&usr);
|
let payload = super::get_test_register_payload(&usr);
|
||||||
let req = axum::http::Request::builder()
|
let req = axum::http::Request::builder()
|
||||||
@@ -298,7 +300,7 @@ mod tests {
|
|||||||
|
|
||||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
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 app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
@@ -355,7 +357,7 @@ mod tests {
|
|||||||
|
|
||||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
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 app = init::routes().await.layer(axum::Extension(pool));
|
||||||
|
|
||||||
@@ -443,7 +445,7 @@ mod tests {
|
|||||||
|
|
||||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
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 app = init::routes().await.layer(axum::Extension(pool));
|
||||||
let passphrase =
|
let passphrase =
|
||||||
@@ -497,13 +499,13 @@ mod tests {
|
|||||||
|
|
||||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
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 app = init::routes().await.layer(axum::Extension(pool));
|
||||||
let id = uuid::Uuid::parse_str("22f9c775-cce9-457a-a147-9dafbb801f61").unwrap();
|
let id = uuid::Uuid::parse_str("22f9c775-cce9-457a-a147-9dafbb801f61").unwrap();
|
||||||
let key = icarus_envy::environment::get_secret_key().await.value;
|
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)) => {
|
Ok((token, _expire)) => {
|
||||||
let payload = serde_json::json!({
|
let payload = serde_json::json!({
|
||||||
"access_token": token
|
"access_token": token
|
||||||
|
Reference in New Issue
Block a user