diff --git a/.env.docker.sample b/.env.docker.sample index a5a0bb3..47c97ce 100644 --- a/.env.docker.sample +++ b/.env.docker.sample @@ -5,9 +5,10 @@ RUST_LOG=debug ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH -POSTGRES_AUTH_USER=icarus_op +POSTGRES_AUTH_USER=soaricarus_op POSTGRES_AUTH_PASSWORD=password -POSTGRES_AUTH_DB=icarus_auth_db +POSTGRES_AUTH_DB=soaricarus_auth_db POSTGRES_AUTH_HOST=auth_db -DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB} +POSTGRES_AUTH_PORT=5432 +DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:${POSTGRES_AUTH_PORT}/${POSTGRES_AUTH_DB} ENABLE_REGISTRATION=TRUE diff --git a/.env.local.sample b/.env.local.sample index fa15119..92502c6 100644 --- a/.env.local.sample +++ b/.env.local.sample @@ -5,9 +5,10 @@ RUST_LOG=debug ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH -POSTGRES_AUTH_USER=icarus_op_test +POSTGRES_AUTH_USER=soaricarus_op_test POSTGRES_AUTH_PASSWORD=password -POSTGRES_AUTH_DB=icarus_auth_test_db +POSTGRES_AUTH_DB=soaricarus_auth_test_db POSTGRES_AUTH_HOST=localhost -DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB} +POSTGRES_AUTH_PORT=5432 +DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:${POSTGRES_AUTH_PORT}/${POSTGRES_AUTH_DB} ENABLE_REGISTRATION=TRUE diff --git a/.gitea/workflows/tag_release.yml b/.gitea/workflows/tag_release.yml index 4ada6b1..8441314 100644 --- a/.gitea/workflows/tag_release.yml +++ b/.gitea/workflows/tag_release.yml @@ -12,12 +12,12 @@ jobs: - name: Checkout code uses: actions/checkout@v6 with: - fetch-depth: 0 # Important for git describe --tags + fetch-depth: 0 - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 components: cargo - uses: Swatinem/rust-cache@v2 diff --git a/.gitea/workflows/workflow.yml b/.gitea/workflows/workflow.yml index 8b17200..9129b6f 100644 --- a/.gitea/workflows/workflow.yml +++ b/.gitea/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: icarus_auth Build +name: soaricarus_auth Build on: push: @@ -16,16 +16,16 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh - echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key - chmod 600 ~/.ssh/icarus_models_deploy_key + echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key + chmod 600 ~/.ssh/soaricarus_models_deploy_key ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) - ssh-add -v ~/.ssh/icarus_models_deploy_key + ssh-add -v ~/.ssh/soaricarus_models_deploy_key cargo check @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - name: Verify Docker Environment run: | @@ -72,12 +72,12 @@ jobs: ENABLE_REGISTRATION: 'TRUE' run: | mkdir -p ~/.ssh - echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key - chmod 600 ~/.ssh/icarus_models_deploy_key + echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key + chmod 600 ~/.ssh/soaricarus_models_deploy_key ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) - ssh-add -v ~/.ssh/icarus_models_deploy_key + ssh-add -v ~/.ssh/soaricarus_models_deploy_key cargo test @@ -88,17 +88,17 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - run: rustup component add rustfmt - run: | mkdir -p ~/.ssh - echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key - chmod 600 ~/.ssh/icarus_models_deploy_key + echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key + chmod 600 ~/.ssh/soaricarus_models_deploy_key ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) - ssh-add -v ~/.ssh/icarus_models_deploy_key + ssh-add -v ~/.ssh/soaricarus_models_deploy_key cargo fmt --all -- --check clippy: @@ -108,17 +108,17 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - run: rustup component add clippy - run: | mkdir -p ~/.ssh - echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key - chmod 600 ~/.ssh/icarus_models_deploy_key + echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key + chmod 600 ~/.ssh/soaricarus_models_deploy_key ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) - ssh-add -v ~/.ssh/icarus_models_deploy_key + ssh-add -v ~/.ssh/soaricarus_models_deploy_key cargo clippy -- -D warnings build: @@ -128,14 +128,14 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh - echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key - chmod 600 ~/.ssh/icarus_models_deploy_key + echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key + chmod 600 ~/.ssh/soaricarus_models_deploy_key ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) - ssh-add -v ~/.ssh/icarus_models_deploy_key + ssh-add -v ~/.ssh/soaricarus_models_deploy_key cargo build --release diff --git a/Cargo.lock b/Cargo.lock index 37463ce..77e0074 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -781,54 +781,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "icarus_auth" -version = "0.8.1" -dependencies = [ - "argon2", - "axum", - "http-body-util", - "icarus_envy", - "icarus_models", - "josekit", - "openssl", - "serde", - "serde_json", - "sqlx", - "time", - "tokio", - "tower", - "tower-http", - "tracing-subscriber", - "url", - "utoipa", - "utoipa-swagger-ui", - "uuid", -] - -[[package]] -name = "icarus_envy" -version = "0.8.0" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.8.0#349056db6e6254c2eb778fdcdd1d64de339f1309" -dependencies = [ - "const_format", - "dotenvy", -] - -[[package]] -name = "icarus_models" -version = "0.11.3" -source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.11.3#859b0fb1b377370d8171e22e59893d86e41b258b" -dependencies = [ - "josekit", - "rand", - "serde", - "serde_json", - "time", - "utoipa", - "uuid", -] - [[package]] name = "icu_collections" version = "2.2.0" @@ -1583,12 +1535,35 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "sienvy" +version = "0.8.0" +source = "git+ssh://git@git.kundeng.us/phoenix/sienvy.git?tag=v0.8.0-main-d06c8fdf49-006#d06c8fdf49920cf4d8ba0487c20f5bdc851c36de" +dependencies = [ + "const_format", + "dotenvy", +] + [[package]] name = "simd-adler32" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214" +[[package]] +name = "simodels" +version = "0.11.3" +source = "git+ssh://git@git.kundeng.us/phoenix/simodels.git?tag=v0.11.3-main-fe9d101bd0-111#fe9d101bd019f91fe8c99c29721ccb0e6e90c92c" +dependencies = [ + "josekit", + "rand", + "serde", + "serde_json", + "time", + "utoipa", + "uuid", +] + [[package]] name = "slab" version = "0.4.12" @@ -1604,6 +1579,31 @@ dependencies = [ "serde", ] +[[package]] +name = "soaricarus_auth" +version = "0.8.1" +dependencies = [ + "argon2", + "axum", + "http-body-util", + "josekit", + "openssl", + "serde", + "serde_json", + "sienvy", + "simodels", + "sqlx", + "time", + "tokio", + "tower", + "tower-http", + "tracing-subscriber", + "url", + "utoipa", + "utoipa-swagger-ui", + "uuid", +] + [[package]] name = "socket2" version = "0.6.4" @@ -2214,9 +2214,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.23.4" +version = "1.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf80a72845275afea99e7f2b434723d3bc7e38470fcd1c7ed39a599c73319a53" +checksum = "bf3923a6f5c4c6382e0b653c4117f48d631ea17f38ed86e2a828e6f7412f5239" dependencies = [ "getrandom 0.4.3", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index 5b5e0a9..10344a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,10 @@ [package] -name = "icarus_auth" +name = "soaricarus_auth" version = "0.8.1" edition = "2024" rust-version = "1.95" +license = "MIT" +description = "Auth API for soaricarus" [dependencies] axum = { version = "0.8.9" } @@ -14,14 +16,14 @@ tracing-subscriber = { version = "0.3.23" } tower = { version = "0.5.3", features = ["full"] } tower-http = { version = "0.7.0", features = ["cors"] } sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] } -uuid = { version = "1.23.4", features = ["v4", "serde"] } +uuid = { version = "1.23.5", features = ["v4", "serde"] } argon2 = { version = "0.5.3", features = ["std"] } time = { version = "0.3.53", features = ["macros", "serde"] } josekit = { version = "0.10.3" } utoipa = { version = "5.5.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.11.3" } -icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.8.0" } +simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" } +sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" } [dev-dependencies] http-body-util = { version = "0.1.3" } diff --git a/Dockerfile b/Dockerfile index e5952ad..24a2c3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,8 @@ -# Stage 1: Build the application -# Use a specific Rust version for reproducibility. Choose one that matches your development environment. -# Using slim variant for smaller base image -FROM rust:1.96.1 as builder +FROM rust:1.97 as builder # Set the working directory inside the container WORKDIR /usr/src/app -# Install build dependencies if needed (e.g., for certain crates like sqlx with native TLS) -# RUN apt-get update && apt-get install -y pkg-config libssl-dev - # Install build dependencies if needed (e.g., git for cloning) RUN apt-get update && apt-get install -y --no-install-recommends \ pkg-config libssl3 \ @@ -16,36 +10,25 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ openssh-client git \ && rm -rf /var/lib/apt/lists/* -# << --- ADD HOST KEY HERE --- >> -# Replace 'yourgithost.com' with the actual hostname (e.g., github.com) RUN mkdir -p -m 0700 ~/.ssh && \ ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts # Copy Cargo manifests COPY Cargo.toml Cargo.lock ./ -# Build *only* dependencies to leverage Docker cache -# This dummy build caches dependencies as a separate layer RUN --mount=type=ssh mkdir src && \ echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \ cargo build --release --quiet && \ - rm -rf src target/release/deps/icarus_auth* # Clean up dummy build artifacts (replace icarus_auth) + rm -rf src target/release/deps/soaricarus_auth* -# Copy the actual source code COPY src ./src # If you have other directories like `templates` or `static`, copy them too COPY .env ./.env COPY migrations ./migrations -# << --- SSH MOUNT ADDED HERE --- >> -# Build *only* dependencies to leverage Docker cache -# This dummy build caches dependencies as a separate layer -# Mount the SSH agent socket for this command RUN --mount=type=ssh \ cargo build --release --quiet -# Stage 2: Create the final, smaller runtime image -# Use a minimal base image like debian-slim or even distroless for security/size FROM debian:trixie-slim # Install runtime dependencies if needed (e.g., SSL certificates) @@ -55,17 +38,15 @@ RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && r WORKDIR /usr/local/bin # Copy the compiled binary from the builder stage -# Replace 'icarus_auth' with the actual name of your binary (usually the crate name) -COPY --from=builder /usr/src/app/target/release/icarus_auth . +COPY --from=builder /usr/src/app/target/release/soaricarus_auth . # Copy other necessary files like .env (if used for runtime config) or static assets # It's generally better to configure via environment variables in Docker though COPY --from=builder /usr/src/app/.env . COPY --from=builder /usr/src/app/migrations ./migrations -# Expose the port your Axum app listens on (e.g., 3000 or 8000) EXPOSE 8001 # Set the command to run your application # Ensure this matches the binary name copied above -CMD ["./icarus_auth"] +CMD ["./soaricarus_auth"] diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1ba694a --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,22 @@ +Copyright (c) 2026 Kun Deng. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index a0cdba5..fe934af 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -A auth web API services for the Icarus project. +# soaricarus_auth +A auth web API services for the soaricarus project. # Getting Started diff --git a/docker-compose.yaml b/docker-compose.yaml index 62d9ff3..95ec49c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,7 +5,7 @@ services: build: context: . ssh: ["default"] - container_name: icarus_auth + container_name: soaricarus_auth ports: - "8001:8001" env_file: @@ -17,14 +17,15 @@ services: auth_db: image: postgres:18.4-alpine - container_name: icarus_auth_db + container_name: soaricarus_auth_db environment: - POSTGRES_USER: ${POSTGRES_AUTH_USER:-icarus_op} + POSTGRES_USER: ${POSTGRES_AUTH_USER:-soaricarus_op} POSTGRES_PASSWORD: ${POSTGRES_AUTH_PASSWORD:-password} - POSTGRES_DB: ${POSTGRES_AUTH_DB:-icarus_auth_db} + POSTGRES_DB: ${POSTGRES_AUTH_DB:-soaricarus_auth_db} volumes: - postgres_data:/var/lib/postgresql - ports: [] + ports: + - "5433:5432" healthcheck: # Checks if Postgres is ready to accept connections test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] diff --git a/src/callers/login.rs b/src/callers/login.rs index 9a3c6b1..c583d97 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -28,14 +28,14 @@ pub mod response { #[derive(Default, Deserialize, Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, - pub data: Vec, + pub data: Vec, } pub mod service_login { #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, - pub data: Vec, + pub data: Vec, } } @@ -43,7 +43,7 @@ pub mod response { #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, - pub data: Vec, + pub data: Vec, } } } @@ -92,7 +92,7 @@ pub mod endpoint { Ok(user) => { if hashing::verify_password(&payload.password, user.password.clone()).unwrap() { // Create token - let key = icarus_envy::environment::get_secret_key().value; + let key = sienvy::environment::get_secret_key().value; let (token_literal, duration) = token_stuff::create_token(&key, &user.id).unwrap(); @@ -104,11 +104,11 @@ pub mod endpoint { StatusCode::OK, Json(response::Response { message: String::from("Successful"), - data: vec![icarus_models::login_result::LoginResult { + data: vec![simodels::login_result::LoginResult { id: user.id, username: user.username.clone(), token: token_literal, - token_type: String::from(icarus_models::token::TOKEN_TYPE), + token_type: String::from(simodels::token::TOKEN_TYPE), expiration: duration, }], }), @@ -151,16 +151,16 @@ pub mod endpoint { match repo::service::valid_passphrase(&pool, &payload.passphrase).await { Ok((id, username, _date_created)) => { - let key = icarus_envy::environment::get_secret_key().value; + let key = sienvy::environment::get_secret_key().value; let (token_literal, duration) = token_stuff::create_service_token(&key, &id).unwrap(); if token_stuff::verify_token(&key, &token_literal) { - let login_result = icarus_models::login_result::LoginResult { + let login_result = simodels::login_result::LoginResult { id, username, token: token_literal, - token_type: String::from(icarus_models::token::TOKEN_TYPE), + token_type: String::from(simodels::token::TOKEN_TYPE), expiration: duration, }; @@ -203,7 +203,7 @@ pub mod endpoint { axum::Json, ) { let mut response = response::refresh_token::Response::default(); - let key = icarus_envy::environment::get_secret_key().value; + let key = sienvy::environment::get_secret_key().value; if token_stuff::verify_token(&key, &payload.access_token) { let token_type = token_stuff::get_token_type(&key, &payload.access_token).unwrap(); @@ -215,11 +215,11 @@ pub mod endpoint { Ok((username, _, _)) => { match token_stuff::create_service_refresh_token(&key, &id) { Ok((access_token, exp_dur)) => { - let login_result = icarus_models::login_result::LoginResult { + let login_result = simodels::login_result::LoginResult { id, token: access_token, expiration: exp_dur, - token_type: String::from(icarus_models::token::TOKEN_TYPE), + token_type: String::from(simodels::token::TOKEN_TYPE), username, }; response.message = String::from("Successful"); diff --git a/src/callers/register.rs b/src/callers/register.rs index 0370aa2..15d3924 100644 --- a/src/callers/register.rs +++ b/src/callers/register.rs @@ -29,7 +29,7 @@ pub mod response { #[derive(Deserialize, Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, - pub data: Vec, + pub data: Vec, } } @@ -67,7 +67,7 @@ pub async fn register_user( }; if registration_enabled { - let mut user = icarus_models::user::User { + let mut user = simodels::user::User { username: payload.username.clone(), password: payload.password.clone(), email: payload.email.clone(), @@ -91,7 +91,7 @@ pub async fn register_user( ) } else { let salt_string = hashing::generate_salt().unwrap(); - let mut salt = icarus_models::user::salt::Salt::default(); + let mut salt = simodels::user::salt::Salt::default(); let generated_salt = salt_string; salt.salt = generated_salt.to_string(); salt.id = repo::salt::insert(&pool, &salt).await.unwrap(); @@ -144,7 +144,7 @@ pub async fn register_user( /// Checks to see if registration is enabled async fn is_registration_enabled() -> Result { let key = String::from("ENABLE_REGISTRATION"); - let var = icarus_envy::environment::get_env(&key); + let var = sienvy::environment::get_env(&key); let parsed_value = var.value.to_uppercase(); if parsed_value == "TRUE" { diff --git a/src/db/init.rs b/src/db/init.rs index 05bdc0d..df5efa5 100644 --- a/src/db/init.rs +++ b/src/db/init.rs @@ -1,7 +1,7 @@ use sqlx::postgres::PgPoolOptions; pub async fn create_pool() -> Result { - let database_url = icarus_envy::environment::get_db_url().value; + let database_url = sienvy::environment::get_db_url().value; println!("Database url: {database_url}"); PgPoolOptions::new() diff --git a/src/main.rs b/src/main.rs index 691aa74..71ef3ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ mod init { register_responses::Response, login_responses::Response, login_responses::service_login::Response, login_responses::refresh_token::Response)), tags( - (name = "Icarus Auth API", description = "Auth API for Icarus API") + (name = "soaricarus Auth API", description = "Auth API for soaricarus API") ) )] struct ApiDoc; @@ -67,10 +67,10 @@ mod init { .max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2] // Dynamically set the allowed origin based on the environment - match std::env::var(icarus_envy::keys::APP_ENV).as_deref() { + match std::env::var(sienvy::keys::APP_ENV).as_deref() { Ok("production") => { - let allowed_origins_env = icarus_envy::environment::get_allowed_origins(); - match icarus_envy::utility::delimitize(&allowed_origins_env) { + let allowed_origins_env = sienvy::environment::get_allowed_origins(); + match sienvy::utility::delimitize(&allowed_origins_env) { Ok(alwd) => { let allowed_origins: Vec = alwd .into_iter() @@ -162,7 +162,7 @@ mod tests { pub const LIMIT: usize = 6; pub async fn get_pool() -> Result { - let tm_db_url = icarus_envy::environment::get_db_url().value; + let tm_db_url = sienvy::environment::get_db_url().value; let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap(); sqlx::PgPool::connect_with(tm_options).await } @@ -175,7 +175,7 @@ mod tests { } pub async fn connect_to_db(db_name: &str) -> Result { - let db_url = icarus_envy::environment::get_db_url().value; + let db_url = sienvy::environment::get_db_url().value; let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name); sqlx::PgPool::connect_with(options).await } @@ -207,7 +207,7 @@ mod tests { } pub async fn get_database_name() -> Result> { - let database_url = icarus_envy::environment::get_db_url().value; + let database_url = sienvy::environment::get_db_url().value; let parsed_url = url::Url::parse(&database_url)?; if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" { @@ -508,7 +508,7 @@ mod tests { 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().value; + let key = sienvy::environment::get_secret_key().value; match token_stuff::create_service_token(&key, &id) { Ok((token, _expire)) => { diff --git a/src/repo/mod.rs b/src/repo/mod.rs index 15482e9..b127180 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -12,7 +12,7 @@ pub mod user { pub async fn get( pool: &sqlx::PgPool, username: &String, - ) -> Result { + ) -> Result { let result = sqlx::query( r#" SELECT * FROM "user" WHERE username = $1 @@ -24,7 +24,7 @@ pub mod user { match result { Ok(r) => match r { - Some(r) => Ok(icarus_models::user::User { + Some(r) => Ok(simodels::user::User { id: r.try_get("id")?, username: r.try_get("username")?, password: r.try_get("password")?, @@ -46,7 +46,7 @@ pub mod user { pub async fn update_last_login( pool: &sqlx::PgPool, - user: &icarus_models::user::User, + user: &simodels::user::User, time: &time::OffsetDateTime, ) -> Result { let result = sqlx::query( @@ -95,7 +95,7 @@ pub mod user { pub async fn insert( pool: &sqlx::PgPool, - user: &icarus_models::user::User, + user: &simodels::user::User, ) -> Result<(uuid::Uuid, std::option::Option), sqlx::Error> { let row = sqlx::query( r#" @@ -145,7 +145,7 @@ pub mod salt { pub async fn get( pool: &sqlx::PgPool, id: &uuid::Uuid, - ) -> Result { + ) -> Result { let result = sqlx::query( r#" SELECT * FROM "salt" WHERE id = $1 @@ -157,7 +157,7 @@ pub mod salt { match result { Ok(r) => match r { - Some(r) => Ok(icarus_models::user::salt::Salt { + Some(r) => Ok(simodels::user::salt::Salt { id: r.try_get("id")?, salt: r.try_get("salt")?, }), @@ -169,7 +169,7 @@ pub mod salt { pub async fn insert( pool: &sqlx::PgPool, - salt: &icarus_models::user::salt::Salt, + salt: &simodels::user::salt::Salt, ) -> Result { let row = sqlx::query( r#" diff --git a/src/token_stuff/mod.rs b/src/token_stuff/mod.rs index cc734ec..25c9cb7 100644 --- a/src/token_stuff/mod.rs +++ b/src/token_stuff/mod.rs @@ -8,8 +8,8 @@ use time; pub const KEY_ENV: &str = "SECRET_KEY"; pub const MESSAGE: &str = "Something random"; -pub const ISSUER: &str = "icarus_auth"; -pub const AUDIENCE: &str = "icarus"; +pub const ISSUER: &str = "soaricarus_auth"; +pub const AUDIENCE: &str = "soaricarus"; pub fn get_issued() -> time::Result { Ok(time::OffsetDateTime::now_utc()) @@ -24,39 +24,39 @@ pub fn create_token( provided_key: &String, id: &uuid::Uuid, ) -> Result<(String, i64), josekit::JoseError> { - let resource = icarus_models::token::TokenResource { + let resource = simodels::token::TokenResource { message: String::from(MESSAGE), issuer: String::from(ISSUER), audiences: vec![String::from(AUDIENCE)], id: *id, }; - icarus_models::token::create_token(provided_key, &resource, time::Duration::hours(4)) + simodels::token::create_token(provided_key, &resource, time::Duration::hours(4)) } pub fn create_service_token( provided: &String, id: &uuid::Uuid, ) -> Result<(String, i64), josekit::JoseError> { - let resource = icarus_models::token::TokenResource { + let resource = simodels::token::TokenResource { message: String::from(SERVICE_SUBJECT), issuer: String::from(ISSUER), audiences: vec![String::from(AUDIENCE)], id: *id, }; - icarus_models::token::create_token(provided, &resource, time::Duration::hours(1)) + simodels::token::create_token(provided, &resource, time::Duration::hours(1)) } pub fn create_service_refresh_token( key: &String, id: &uuid::Uuid, ) -> Result<(String, i64), josekit::JoseError> { - let resource = icarus_models::token::TokenResource { + let resource = simodels::token::TokenResource { message: String::from(SERVICE_SUBJECT), issuer: String::from(ISSUER), audiences: vec![String::from(AUDIENCE)], id: *id, }; - icarus_models::token::create_token(key, &resource, time::Duration::hours(4)) + simodels::token::create_token(key, &resource, time::Duration::hours(4)) } pub fn verify_token(key: &String, token: &String) -> bool { @@ -82,9 +82,9 @@ pub fn extract_id_from_token(key: &String, token: &String) -> Result Result { @@ -123,7 +123,7 @@ mod tests { #[test] fn test_tokenize() { - let special_key = icarus_envy::environment::get_secret_key().value; + let special_key = sienvy::environment::get_secret_key().value; let id = uuid::Uuid::new_v4(); match create_token(&special_key, &id) { Ok((token, _duration)) => {