diff --git a/Cargo.toml b/Cargo.toml index 7634e26..efa5485 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,12 +3,6 @@ name = "server" version = "0.1.0" edition = "2021" -# [target.x86_64-unknown-linux-gnu] -# rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"] - -[lints] -workspace = true - [dependencies] log = "0.4.21" env_logger = "0.11.3" @@ -24,12 +18,15 @@ json-patch = "1.2.0" sqlx = { version = "0.7.4", features = [ "sqlite", # "postgres", - "any", + # "any", "macros", "runtime-tokio", "tls-rustls", ] } +[lints] +workspace = true + [workspace.lints.clippy] uninlined_format_args = "warn" correctness = "warn" diff --git a/src/auth.rs b/src/auth.rs index 56990a4..d6e033d 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,12 +1,13 @@ use axum::Router; -use sqlx::{Any, Pool}; + +use crate::storage::DatabaseDriver; // route prefix: `/auth/token/` // mod token; // use self::token::token_auth_router; -pub fn auth_router(pool: Pool) -> Router> { +pub fn auth_router(pool: DatabaseDriver) -> Router { Router::new().with_state(pool) // .nest("/token", token_auth_router()) } diff --git a/src/engines.rs b/src/engines.rs index d57a55a..27cd879 100644 --- a/src/engines.rs +++ b/src/engines.rs @@ -7,15 +7,14 @@ use axum::{ Router, }; use log::*; -use sqlx::{Any, Pool}; -pub fn secrets_router(pool: Pool) -> Router> { +use crate::storage::DatabaseDriver; + +pub fn secrets_router(pool: DatabaseDriver) -> Router { Router::new().fallback(map_mount_points).with_state(pool) } -async fn map_mount_points(State(_pool): State>, req: Request) -> Response { - // let mount_path = mount_path.trim_start_matches('/'); - // debug!("Mount path: {}", mount_path); +async fn map_mount_points(State(pool): State, req: Request) -> Response { debug!("Mount path: {:?}", req); let mut mount_path: Vec<&str> = req.uri().path().split("/").collect(); diff --git a/src/engines/kv.rs b/src/engines/kv.rs index 21db586..2ba9349 100644 --- a/src/engines/kv.rs +++ b/src/engines/kv.rs @@ -1,14 +1,17 @@ +// TODO: Remove +#![allow(dead_code)] + pub mod logic; pub mod structs; -#[cfg(tests)] + +#[cfg(test)] mod tests; -use crate::engines::kv::logic::body_to_json; +use crate::{engines::kv::logic::body_to_json, storage::DatabaseDriver}; use crate::engines::kv::structs::KvSecret; use axum::{routing::*, Router, extract::Path}; -use sqlx::{Any, Pool}; -pub fn kv_router(pool: Pool) -> Router> { +pub fn kv_router(pool: DatabaseDriver) -> Router { Router::new() .route("/:mount_path/config", get(get_config)) .route("/:mount_path/config", post(post_config)) diff --git a/src/identity.rs b/src/identity.rs index 7a6f408..3bdce76 100644 --- a/src/identity.rs +++ b/src/identity.rs @@ -1,6 +1,7 @@ use axum::Router; -use sqlx::{Any, Pool}; -pub fn identity_router(pool: Pool) -> Router> { +use crate::storage::DatabaseDriver; + +pub fn identity_router(pool: DatabaseDriver) -> Router { Router::new().with_state(pool) } diff --git a/src/main.rs b/src/main.rs index 58e5217..261a121 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,8 @@ use axum::{extract::Request, http::StatusCode, routing::get, Router}; use log::*; -use sqlx::{Any, Pool}; use std::{env, net::SocketAddr, str::FromStr}; use tokio::net::TcpListener; -use crate::storage::create_pool; - mod auth; mod common; mod engines; @@ -27,7 +24,7 @@ async fn main() { let db_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); - let pool: Pool = create_pool(db_url).await; + let pool = storage::create_pool(db_url).await; // build our application with routes let app = Router::new() diff --git a/src/storage.rs b/src/storage.rs index 062e055..517737e 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1,12 +1,11 @@ use std::{fs::File, path::Path}; use log::*; -use sqlx::{any::AnyPoolOptions, AnyPool}; +use sqlx::{sqlite::SqlitePoolOptions, Pool, Sqlite}; -pub async fn create_pool(db_url: String) -> AnyPool { - // TODO: Change to solely install applicable driver - sqlx::any::install_default_drivers(); +pub(crate) type DatabaseDriver = Pool; +pub async fn create_pool(db_url: String) -> DatabaseDriver { // Create SQLite database file if it does not exist if db_url.starts_with("sqlite:") && db_url != ("sqlite::memory:") { let path = db_url.replace("sqlite:", ""); @@ -16,7 +15,7 @@ pub async fn create_pool(db_url: String) -> AnyPool { } } - let pool = AnyPoolOptions::new() + let pool = SqlitePoolOptions::new() .max_connections(5) .test_before_acquire(true) .connect(&db_url) diff --git a/src/sys.rs b/src/sys.rs index da4b7da..3dd38dd 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -1,8 +1,8 @@ use axum::Router; -use sqlx::{Any, Pool}; + +use crate::storage::DatabaseDriver; /// System routes -/// -pub fn sys_router(pool: Pool) -> Router> { +pub fn sys_router(pool: DatabaseDriver) -> Router { Router::new().with_state(pool) }