Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
453830b208 | ||
|
|
2d376524eb | ||
|
|
e518b1e096 | ||
|
|
54b0710298 | ||
|
|
4233876bb0 | ||
|
|
907a2dbfc3 | ||
|
|
cba3e3db79 | ||
|
|
5407462def | ||
|
|
eb6ddbc97a | ||
|
|
e86ca4b2c8 | ||
|
|
6ec3b25e7d | ||
|
|
7e44d523f2 |
+5
-3
@@ -5,8 +5,10 @@ RUST_LOG=debug
|
|||||||
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
||||||
SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
||||||
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||||
POSTGRES_AUTH_USER=icarus_op
|
POSTGRES_AUTH_USER=soaricarus_op
|
||||||
POSTGRES_AUTH_PASSWORD=password
|
POSTGRES_AUTH_PASSWORD=password
|
||||||
POSTGRES_AUTH_DB=icarus_auth_db
|
POSTGRES_AUTH_DB=soaricarus_auth_db
|
||||||
POSTGRES_AUTH_HOST=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
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ RUST_LOG=debug
|
|||||||
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
||||||
SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
SECRET_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
||||||
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||||
POSTGRES_AUTH_USER=icarus_op_test
|
POSTGRES_AUTH_USER=soaricarus_op_test
|
||||||
POSTGRES_AUTH_PASSWORD=password
|
POSTGRES_AUTH_PASSWORD=password
|
||||||
POSTGRES_AUTH_DB=icarus_auth_test_db
|
POSTGRES_AUTH_DB=soaricarus_auth_test_db
|
||||||
POSTGRES_AUTH_HOST=localhost
|
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
|
||||||
@@ -3,22 +3,23 @@ name: Release Tagging
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- devel
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Important for git describe --tags
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.97
|
||||||
components: cargo
|
components: cargo
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
- name: Extract Version from Cargo.toml
|
- name: Extract Version from Cargo.toml
|
||||||
id: version
|
id: version
|
||||||
@@ -27,8 +28,10 @@ jobs:
|
|||||||
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
||||||
BRANCH_REF="${GITHUB_REF}"
|
BRANCH_REF="${GITHUB_REF}"
|
||||||
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||||
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH"
|
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-950"
|
||||||
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-950"
|
|
||||||
|
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE"
|
||||||
|
|
||||||
echo "Version: $VERSION"
|
echo "Version: $VERSION"
|
||||||
echo "Hash: $PROJECT_COMMIT_HASH"
|
echo "Hash: $PROJECT_COMMIT_HASH"
|
||||||
echo "Branch: $BRANCH_NAME"
|
echo "Branch: $BRANCH_NAME"
|
||||||
|
|||||||
@@ -1,48 +1,44 @@
|
|||||||
name: Rust Build
|
name: soaricarus_auth Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- devel
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- devel
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
|
|
||||||
cargo check
|
cargo check
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test Suite
|
name: Test Suite
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
# --- Add database service definition ---
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:17.5
|
image: postgres:18.4-alpine
|
||||||
env:
|
env:
|
||||||
# Use secrets for DB init, with fallbacks for flexibility
|
|
||||||
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
|
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
|
||||||
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
|
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
|
||||||
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
|
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
# Options to wait until the database is ready
|
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
@@ -50,11 +46,11 @@ jobs:
|
|||||||
--health-retries 5
|
--health-retries 5
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.97
|
||||||
# --- Add this step for explicit verification ---
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Verify Docker Environment
|
- name: Verify Docker Environment
|
||||||
run: |
|
run: |
|
||||||
echo "Runner User Info:"
|
echo "Runner User Info:"
|
||||||
@@ -66,24 +62,22 @@ jobs:
|
|||||||
echo "Checking Docker Daemon Status (ps):"
|
echo "Checking Docker Daemon Status (ps):"
|
||||||
docker ps -a
|
docker ps -a
|
||||||
echo "Docker environment check complete."
|
echo "Docker environment check complete."
|
||||||
# NOTE: Do NOT use continue-on-error here.
|
|
||||||
# If Docker isn't working as expected, the job SHOULD fail here.
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
env:
|
env:
|
||||||
# Define DATABASE_URL for tests to use
|
# Define DATABASE_URL for tests to use
|
||||||
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:5432/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:5432/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
RUST_LOG: info # Optional: configure test log level
|
RUST_LOG: info # Optional: configure test log level
|
||||||
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
||||||
# Make SSH agent available if tests fetch private dependencies
|
|
||||||
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
|
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
|
||||||
|
ENABLE_REGISTRATION: 'TRUE'
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
|
|
||||||
cargo test
|
cargo test
|
||||||
|
|
||||||
@@ -91,54 +85,57 @@ jobs:
|
|||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
cargo fmt --all -- --check
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
cargo clippy -- -D warnings
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: build
|
name: build
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.90.0
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: |
|
- run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
|
||||||
chmod 600 ~/.ssh/icarus_models_deploy_key
|
chmod 600 ~/.ssh/soaricarus_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
|||||||
Generated
+504
-908
File diff suppressed because it is too large
Load Diff
+20
-20
@@ -1,30 +1,30 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_auth"
|
name = "soaricarus_auth"
|
||||||
version = "0.6.0"
|
version = "0.8.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.95"
|
||||||
|
license = "MIT"
|
||||||
|
description = "Auth API for soaricarus"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { version = "0.8.6" }
|
axum = { version = "0.8.9" }
|
||||||
|
openssl = { version = "0.10.81", features = ["vendored"] }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.145" }
|
serde_json = { version = "1.0.150" }
|
||||||
tokio = { version = "1.47.1", features = ["rt-multi-thread"] }
|
tokio = { version = "1.52.3", features = ["rt-multi-thread"] }
|
||||||
tracing-subscriber = { version = "0.3.20" }
|
tracing-subscriber = { version = "0.3.23" }
|
||||||
tower = { version = "0.5.2", features = ["full"] }
|
tower = { version = "0.5.3", features = ["full"] }
|
||||||
tower-http = { version = "0.6.6", features = ["cors"] }
|
tower-http = { version = "0.7.0", features = ["cors"] }
|
||||||
hyper = { version = "1.7.0" }
|
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
|
||||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
uuid = { version = "1.23.5", features = ["v4", "serde"] }
|
||||||
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
argon2 = { version = "0.5.3", features = ["std"] }
|
||||||
argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version
|
time = { version = "0.3.53", features = ["macros", "serde"] }
|
||||||
rand = { version = "0.9.2" }
|
|
||||||
time = { version = "0.3.41", features = ["macros", "serde"] }
|
|
||||||
josekit = { version = "0.10.3" }
|
josekit = { version = "0.10.3" }
|
||||||
utoipa = { version = "5.4.0", features = ["axum_extras"] }
|
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
||||||
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.7.0" }
|
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" }
|
||||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" }
|
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
http-body-util = { version = "0.1.3" }
|
http-body-util = { version = "0.1.3" }
|
||||||
url = { version = "2.5.7" }
|
url = { version = "2.5.8" }
|
||||||
once_cell = { version = "1.21.3" } # Useful for lazy initialization in tests/app setup
|
|
||||||
|
|||||||
+6
-25
@@ -1,14 +1,8 @@
|
|||||||
# Stage 1: Build the application
|
FROM rust:1.97 as builder
|
||||||
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
|
|
||||||
# Using slim variant for smaller base image
|
|
||||||
FROM rust:1.90 as builder
|
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
WORKDIR /usr/src/app
|
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)
|
# Install build dependencies if needed (e.g., git for cloning)
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
pkg-config libssl3 \
|
pkg-config libssl3 \
|
||||||
@@ -16,37 +10,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
openssh-client git \
|
openssh-client git \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& 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 && \
|
RUN mkdir -p -m 0700 ~/.ssh && \
|
||||||
ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
|
ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
# Copy Cargo manifests
|
# Copy Cargo manifests
|
||||||
COPY Cargo.toml Cargo.lock ./
|
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 && \
|
RUN --mount=type=ssh mkdir src && \
|
||||||
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
|
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
|
||||||
cargo build --release --quiet && \
|
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
|
COPY src ./src
|
||||||
# If you have other directories like `templates` or `static`, copy them too
|
# If you have other directories like `templates` or `static`, copy them too
|
||||||
COPY .env ./.env
|
COPY .env ./.env
|
||||||
COPY migrations ./migrations
|
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 \
|
RUN --mount=type=ssh \
|
||||||
cargo build --release --quiet
|
cargo build --release --quiet
|
||||||
|
|
||||||
# Stage 2: Create the final, smaller runtime image
|
FROM debian:trixie-slim
|
||||||
# Use a minimal base image like debian-slim or even distroless for security/size
|
|
||||||
FROM ubuntu:24.04
|
|
||||||
|
|
||||||
# Install runtime dependencies if needed (e.g., SSL certificates)
|
# Install runtime dependencies if needed (e.g., SSL certificates)
|
||||||
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
|
||||||
@@ -55,17 +38,15 @@ RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && r
|
|||||||
WORKDIR /usr/local/bin
|
WORKDIR /usr/local/bin
|
||||||
|
|
||||||
# Copy the compiled binary from the builder stage
|
# 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/soaricarus_auth .
|
||||||
COPY --from=builder /usr/src/app/target/release/icarus_auth .
|
|
||||||
|
|
||||||
# Copy other necessary files like .env (if used for runtime config) or static assets
|
# 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
|
# 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/.env .
|
||||||
COPY --from=builder /usr/src/app/migrations ./migrations
|
COPY --from=builder /usr/src/app/migrations ./migrations
|
||||||
|
|
||||||
# Expose the port your Axum app listens on (e.g., 3000 or 8000)
|
EXPOSE 8001
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
# Set the command to run your application
|
# Set the command to run your application
|
||||||
# Ensure this matches the binary name copied above
|
# Ensure this matches the binary name copied above
|
||||||
CMD ["./icarus_auth"]
|
CMD ["./soaricarus_auth"]
|
||||||
|
|||||||
+22
@@ -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.
|
||||||
@@ -1,32 +1,44 @@
|
|||||||
A auth web API services for the Icarus project.
|
# soaricarus_auth
|
||||||
|
A auth web API services for the soaricarus project.
|
||||||
|
|
||||||
|
|
||||||
# Getting Started
|
# Getting Started
|
||||||
|
Install the `sqlx` tool to use migrations.
|
||||||
|
```
|
||||||
|
cargo install sqlx-cli
|
||||||
|
```
|
||||||
|
This will be used to scaffold development for local environments.
|
||||||
|
|
||||||
|
|
||||||
The easiest way to get started is through docker. This assumes that docker is already installed
|
The easiest way to get started is through docker. This assumes that docker is already installed
|
||||||
on your system. Copy the `.env.docker.sample` as `.env`. Most of the data in the env file doesn't
|
on your system. Copy the `.env.docker.sample` as `.env`. Most of the data in the env file doesn't
|
||||||
need to be modified. The `SECRET_KEY` variable should be changed since it will be used for token
|
need to be modified. The `SECRET_KEY` variable should be changed since it will be used for token
|
||||||
generation. The `SECRET_PASSPHASE` should also be changed when in production mode, but make sure
|
generation. The `SECRET_PASSPHASE` should also be changed when in production mode, but make sure
|
||||||
the respective `passphrase` database table record exists.
|
the respective `passphrase` database table record exists.
|
||||||
|
|
||||||
Build image
|
To enable or disable registrations, use `TRUE` or `FALSE` for the `ENABLE_REGISTRATION` variable.
|
||||||
|
By default it is `TRUE`.
|
||||||
|
|
||||||
|
|
||||||
|
### Build image
|
||||||
```
|
```
|
||||||
docker compose build
|
docker compose build
|
||||||
```
|
```
|
||||||
|
|
||||||
Start images
|
### Start images
|
||||||
```
|
```
|
||||||
docker compose up -d --force-recreate
|
docker compose up -d --force-recreate
|
||||||
```
|
```
|
||||||
|
|
||||||
Bring it down
|
### Bring it down
|
||||||
```
|
```
|
||||||
docker compose down -v
|
docker compose down -v
|
||||||
```
|
```
|
||||||
|
|
||||||
Pruning
|
### Pruning
|
||||||
```
|
```
|
||||||
docker system prune -a
|
docker system prune -a
|
||||||
```
|
```
|
||||||
|
|
||||||
To view the OpenAPI spec, run the project and access `/swagger-ui`. If running through docker,
|
To view the OpenAPI spec, run the project and access `/swagger-ui`. If running through docker,
|
||||||
the url would be something like `http://localhost:8000/swagger-ui`.
|
the url would be something like `http://localhost:8001/swagger-ui`.
|
||||||
|
|||||||
+13
-18
@@ -1,35 +1,31 @@
|
|||||||
version: '3.8' # Use a recent version
|
version: '3.8' # Use a recent version
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# Your Rust Application Service
|
|
||||||
auth_api:
|
auth_api:
|
||||||
build: # Tells docker-compose to build the Dockerfile in the current directory
|
build:
|
||||||
context: .
|
context: .
|
||||||
ssh: ["default"] # Uses host's SSH agent
|
ssh: ["default"]
|
||||||
container_name: icarus_auth # Optional: Give the container a specific name
|
container_name: soaricarus_auth
|
||||||
ports:
|
ports:
|
||||||
# Map host port 8000 to container port 3000 (adjust as needed)
|
|
||||||
- "8001:8001"
|
- "8001:8001"
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
depends_on:
|
depends_on:
|
||||||
auth_db:
|
auth_db:
|
||||||
condition: service_healthy # Wait for the DB to be healthy before starting the app
|
condition: service_healthy
|
||||||
restart: unless-stopped # Optional: Restart policy
|
restart: unless-stopped
|
||||||
|
|
||||||
# PostgreSQL Database Service
|
|
||||||
auth_db:
|
auth_db:
|
||||||
image: postgres:17.5-alpine # Use an official Postgres image (Alpine variant is smaller)
|
image: postgres:18.4-alpine
|
||||||
container_name: icarus_auth_db # Optional: Give the container a specific name
|
container_name: soaricarus_auth_db
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
POSTGRES_USER: ${POSTGRES_AUTH_USER:-soaricarus_op}
|
||||||
POSTGRES_USER: ${POSTGRES_AUTH_USER:-icarus_op}
|
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_AUTH_PASSWORD:-password}
|
POSTGRES_PASSWORD: ${POSTGRES_AUTH_PASSWORD:-password}
|
||||||
POSTGRES_DB: ${POSTGRES_AUTH_DB:-icarus_auth_db}
|
POSTGRES_DB: ${POSTGRES_AUTH_DB:-soaricarus_auth_db}
|
||||||
volumes:
|
volumes:
|
||||||
# Persist database data using a named volume
|
- postgres_data:/var/lib/postgresql
|
||||||
- postgres_data:/var/lib/postgresql/data
|
ports:
|
||||||
ports: []
|
- "5433:5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
# Checks if Postgres is ready to accept connections
|
# Checks if Postgres is ready to accept connections
|
||||||
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
||||||
@@ -37,9 +33,8 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
restart: always # Optional: Restart policy
|
restart: always
|
||||||
|
|
||||||
# Define the named volume for data persistence
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS "salt" (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS "passphrase" (
|
CREATE TABLE IF NOT EXISTS "passphrase" (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
username TEXT NOT NULL,
|
||||||
passphrase TEXT NOT NULL,
|
passphrase TEXT NOT NULL,
|
||||||
date_created TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
date_created TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
-- Add migration script here
|
-- Add migration script here
|
||||||
INSERT INTO "passphrase" (id, passphrase) VALUES('22f9c775-cce9-457a-a147-9dafbb801f61', 'iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH');
|
INSERT INTO "passphrase" (id, username, passphrase) VALUES('22f9c775-cce9-457a-a147-9dafbb801f61', 'service', 'iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH');
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
TODO: At some point, move this somewhere that is appropriate
|
|
||||||
|
|
||||||
# Make sure role has CREATEDB
|
|
||||||
ALTER ROLE username_that_needs_permission CREATEDB;
|
|
||||||
|
|
||||||
# Install migrations
|
|
||||||
cargo install sqlx-cli
|
|
||||||
|
|
||||||
# Make sure to populate DATABASE_URL with correct value.
|
|
||||||
# By default, the DATABASE_URL found in .env file will be used
|
|
||||||
export DATABASE_URL="postgres://icarus_op_test:password@localhost/icarus_auth_test"
|
|
||||||
|
|
||||||
# init
|
|
||||||
sqlx migrate add init_migration
|
|
||||||
sqlx migrate run
|
|
||||||
|
|
||||||
# Create
|
|
||||||
sqlx database create
|
|
||||||
|
|
||||||
# Drop
|
|
||||||
sqlx database drop
|
|
||||||
|
|
||||||
# setup
|
|
||||||
sqlx database setup
|
|
||||||
|
|
||||||
# Reset
|
|
||||||
sqlx database reset
|
|
||||||
+19
-23
@@ -28,14 +28,14 @@ pub mod response {
|
|||||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
pub data: Vec<simodels::login_result::LoginResult>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod service_login {
|
pub mod service_login {
|
||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
pub data: Vec<simodels::login_result::LoginResult>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
pub data: Vec<simodels::login_result::LoginResult>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,10 +59,6 @@ pub mod endpoint {
|
|||||||
use super::request;
|
use super::request;
|
||||||
use super::response;
|
use super::response;
|
||||||
|
|
||||||
// TODO: At some point, get the username from the DB
|
|
||||||
// Name of service username when returning a login result
|
|
||||||
pub const SERVICE_USERNAME: &str = "service";
|
|
||||||
|
|
||||||
async fn not_found(message: &str) -> (StatusCode, Json<response::Response>) {
|
async fn not_found(message: &str) -> (StatusCode, Json<response::Response>) {
|
||||||
(
|
(
|
||||||
StatusCode::NOT_FOUND,
|
StatusCode::NOT_FOUND,
|
||||||
@@ -96,7 +92,7 @@ pub mod endpoint {
|
|||||||
Ok(user) => {
|
Ok(user) => {
|
||||||
if hashing::verify_password(&payload.password, user.password.clone()).unwrap() {
|
if hashing::verify_password(&payload.password, user.password.clone()).unwrap() {
|
||||||
// Create token
|
// Create token
|
||||||
let key = icarus_envy::environment::get_secret_key().await.value;
|
let key = sienvy::environment::get_secret_key().value;
|
||||||
let (token_literal, duration) =
|
let (token_literal, duration) =
|
||||||
token_stuff::create_token(&key, &user.id).unwrap();
|
token_stuff::create_token(&key, &user.id).unwrap();
|
||||||
|
|
||||||
@@ -108,17 +104,17 @@ pub mod endpoint {
|
|||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
Json(response::Response {
|
Json(response::Response {
|
||||||
message: String::from("Successful"),
|
message: String::from("Successful"),
|
||||||
data: vec![icarus_models::login_result::LoginResult {
|
data: vec![simodels::login_result::LoginResult {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.username.clone(),
|
username: user.username.clone(),
|
||||||
token: token_literal,
|
token: token_literal,
|
||||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
token_type: String::from(simodels::token::TOKEN_TYPE),
|
||||||
expiration: duration,
|
expiration: duration,
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return not_found("Could not verify password").await;
|
return not_found("Could not verify token").await;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return not_found("Error Hashing").await;
|
return not_found("Error Hashing").await;
|
||||||
@@ -154,17 +150,17 @@ pub mod endpoint {
|
|||||||
let mut response = response::service_login::Response::default();
|
let mut response = response::service_login::Response::default();
|
||||||
|
|
||||||
match repo::service::valid_passphrase(&pool, &payload.passphrase).await {
|
match repo::service::valid_passphrase(&pool, &payload.passphrase).await {
|
||||||
Ok((id, _passphrase, _date_created)) => {
|
Ok((id, username, _date_created)) => {
|
||||||
let key = icarus_envy::environment::get_secret_key().await.value;
|
let key = sienvy::environment::get_secret_key().value;
|
||||||
let (token_literal, duration) =
|
let (token_literal, duration) =
|
||||||
token_stuff::create_service_token(&key, &id).unwrap();
|
token_stuff::create_service_token(&key, &id).unwrap();
|
||||||
|
|
||||||
if token_stuff::verify_token(&key, &token_literal) {
|
if token_stuff::verify_token(&key, &token_literal) {
|
||||||
let login_result = icarus_models::login_result::LoginResult {
|
let login_result = simodels::login_result::LoginResult {
|
||||||
id,
|
id,
|
||||||
username: String::from(SERVICE_USERNAME),
|
username,
|
||||||
token: token_literal,
|
token: token_literal,
|
||||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
token_type: String::from(simodels::token::TOKEN_TYPE),
|
||||||
expiration: duration,
|
expiration: duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -207,7 +203,7 @@ pub mod endpoint {
|
|||||||
axum::Json<response::refresh_token::Response>,
|
axum::Json<response::refresh_token::Response>,
|
||||||
) {
|
) {
|
||||||
let mut response = response::refresh_token::Response::default();
|
let mut response = response::refresh_token::Response::default();
|
||||||
let key = icarus_envy::environment::get_secret_key().await.value;
|
let key = sienvy::environment::get_secret_key().value;
|
||||||
|
|
||||||
if token_stuff::verify_token(&key, &payload.access_token) {
|
if token_stuff::verify_token(&key, &payload.access_token) {
|
||||||
let token_type = token_stuff::get_token_type(&key, &payload.access_token).unwrap();
|
let token_type = token_stuff::get_token_type(&key, &payload.access_token).unwrap();
|
||||||
@@ -216,15 +212,15 @@ pub mod endpoint {
|
|||||||
// Get passphrase record with id
|
// Get passphrase record with id
|
||||||
match token_stuff::extract_id_from_token(&key, &payload.access_token) {
|
match token_stuff::extract_id_from_token(&key, &payload.access_token) {
|
||||||
Ok(id) => match repo::service::get_passphrase(&pool, &id).await {
|
Ok(id) => match repo::service::get_passphrase(&pool, &id).await {
|
||||||
Ok((returned_id, _, _)) => {
|
Ok((username, _, _)) => {
|
||||||
match token_stuff::create_service_refresh_token(&key, &returned_id) {
|
match token_stuff::create_service_refresh_token(&key, &id) {
|
||||||
Ok((access_token, exp_dur)) => {
|
Ok((access_token, exp_dur)) => {
|
||||||
let login_result = icarus_models::login_result::LoginResult {
|
let login_result = simodels::login_result::LoginResult {
|
||||||
id: returned_id,
|
id,
|
||||||
token: access_token,
|
token: access_token,
|
||||||
expiration: exp_dur,
|
expiration: exp_dur,
|
||||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
token_type: String::from(simodels::token::TOKEN_TYPE),
|
||||||
username: String::from(SERVICE_USERNAME),
|
username,
|
||||||
};
|
};
|
||||||
response.message = String::from("Successful");
|
response.message = String::from("Successful");
|
||||||
response.data.push(login_result);
|
response.data.push(login_result);
|
||||||
|
|||||||
+49
-10
@@ -29,7 +29,7 @@ pub mod response {
|
|||||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<icarus_models::user::User>,
|
pub data: Vec<simodels::user::User>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +52,22 @@ pub async fn register_user(
|
|||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
Json(payload): Json<request::Request>,
|
Json(payload): Json<request::Request>,
|
||||||
) -> (StatusCode, Json<response::Response>) {
|
) -> (StatusCode, Json<response::Response>) {
|
||||||
let mut user = icarus_models::user::User {
|
let registration_enabled = match is_registration_enabled().await {
|
||||||
id: uuid::Uuid::nil(),
|
Ok(value) => value,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
return (
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
Json(response::Response {
|
||||||
|
message: String::from("Registration check failed"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if registration_enabled {
|
||||||
|
let mut user = simodels::user::User {
|
||||||
username: payload.username.clone(),
|
username: payload.username.clone(),
|
||||||
password: payload.password.clone(),
|
password: payload.password.clone(),
|
||||||
email: payload.email.clone(),
|
email: payload.email.clone(),
|
||||||
@@ -62,24 +76,22 @@ pub async fn register_user(
|
|||||||
lastname: payload.lastname.clone(),
|
lastname: payload.lastname.clone(),
|
||||||
status: String::from("Active"),
|
status: String::from("Active"),
|
||||||
email_verified: true,
|
email_verified: true,
|
||||||
date_created: Some(time::OffsetDateTime::now_utc()),
|
..Default::default()
|
||||||
last_login: None,
|
|
||||||
salt_id: uuid::Uuid::nil(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match repo::user::exists(&pool, &user.username).await {
|
match repo::user::exists(&pool, &user.username).await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if res {
|
if res {
|
||||||
(
|
(
|
||||||
StatusCode::NOT_FOUND,
|
StatusCode::BAD_REQUEST,
|
||||||
Json(response::Response {
|
Json(response::Response {
|
||||||
message: String::from("Error"),
|
message: String::from("Error"),
|
||||||
data: vec![user],
|
data: Vec::new(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let salt_string = hashing::generate_salt().unwrap();
|
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;
|
let generated_salt = salt_string;
|
||||||
salt.salt = generated_salt.to_string();
|
salt.salt = generated_salt.to_string();
|
||||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||||
@@ -89,8 +101,9 @@ pub async fn register_user(
|
|||||||
user.password = hashed_password;
|
user.password = hashed_password;
|
||||||
|
|
||||||
match repo::user::insert(&pool, &user).await {
|
match repo::user::insert(&pool, &user).await {
|
||||||
Ok(id) => {
|
Ok((id, date_created)) => {
|
||||||
user.id = id;
|
user.id = id;
|
||||||
|
user.date_created = date_created;
|
||||||
(
|
(
|
||||||
StatusCode::CREATED,
|
StatusCode::CREATED,
|
||||||
Json(response::Response {
|
Json(response::Response {
|
||||||
@@ -117,4 +130,30 @@ pub async fn register_user(
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::NOT_ACCEPTABLE,
|
||||||
|
Json(response::Response {
|
||||||
|
message: String::from("Registration is not enabled"),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks to see if registration is enabled
|
||||||
|
async fn is_registration_enabled() -> Result<bool, std::io::Error> {
|
||||||
|
let key = String::from("ENABLE_REGISTRATION");
|
||||||
|
let var = sienvy::environment::get_env(&key);
|
||||||
|
let parsed_value = var.value.to_uppercase();
|
||||||
|
|
||||||
|
if parsed_value == "TRUE" {
|
||||||
|
Ok(true)
|
||||||
|
} else if parsed_value == "FALSE" {
|
||||||
|
Ok(false)
|
||||||
|
} else {
|
||||||
|
Err(std::io::Error::other(
|
||||||
|
"Could not determine value of ENABLE_REGISTRATION",
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
use sqlx::postgres::PgPoolOptions;
|
||||||
|
|
||||||
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
|
let database_url = sienvy::environment::get_db_url().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");
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod init;
|
||||||
|
|
||||||
|
mod connection_settings {
|
||||||
|
pub const MAXCONN: u32 = 5;
|
||||||
|
}
|
||||||
-36
@@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+33
-26
@@ -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;
|
||||||
@@ -40,7 +44,7 @@ mod init {
|
|||||||
register_responses::Response,
|
register_responses::Response,
|
||||||
login_responses::Response, login_responses::service_login::Response, login_responses::refresh_token::Response)),
|
login_responses::Response, login_responses::service_login::Response, login_responses::refresh_token::Response)),
|
||||||
tags(
|
tags(
|
||||||
(name = "Icarus Auth API", description = "Auth API for Icarus API")
|
(name = "soaricarus Auth API", description = "Auth API for soaricarus API")
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
struct ApiDoc;
|
struct ApiDoc;
|
||||||
@@ -63,10 +67,10 @@ mod init {
|
|||||||
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
|
.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
|
// 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") => {
|
Ok("production") => {
|
||||||
let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await;
|
let allowed_origins_env = sienvy::environment::get_allowed_origins();
|
||||||
match icarus_envy::utility::delimitize(&allowed_origins_env) {
|
match sienvy::utility::delimitize(&allowed_origins_env) {
|
||||||
Ok(alwd) => {
|
Ok(alwd) => {
|
||||||
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -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
|
||||||
@@ -158,7 +162,7 @@ mod tests {
|
|||||||
pub const LIMIT: usize = 6;
|
pub const LIMIT: usize = 6;
|
||||||
|
|
||||||
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let tm_db_url = icarus_envy::environment::get_db_url().await.value;
|
let tm_db_url = sienvy::environment::get_db_url().value;
|
||||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||||
sqlx::PgPool::connect_with(tm_options).await
|
sqlx::PgPool::connect_with(tm_options).await
|
||||||
}
|
}
|
||||||
@@ -171,7 +175,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let db_url = icarus_envy::environment::get_db_url().await.value;
|
let db_url = sienvy::environment::get_db_url().value;
|
||||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||||
sqlx::PgPool::connect_with(options).await
|
sqlx::PgPool::connect_with(options).await
|
||||||
}
|
}
|
||||||
@@ -181,7 +185,10 @@ mod tests {
|
|||||||
db_name: &str,
|
db_name: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
let create_query = format!("CREATE DATABASE {}", db_name);
|
let create_query = format!("CREATE DATABASE {}", db_name);
|
||||||
match sqlx::query(&create_query).execute(template_pool).await {
|
match sqlx::query(sqlx::AssertSqlSafe(create_query))
|
||||||
|
.execute(template_pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
@@ -193,12 +200,14 @@ mod tests {
|
|||||||
db_name: &str,
|
db_name: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
let drop_query = format!("DROP DATABASE IF EXISTS {} WITH (FORCE)", db_name);
|
let drop_query = format!("DROP DATABASE IF EXISTS {} WITH (FORCE)", db_name);
|
||||||
sqlx::query(&drop_query).execute(template_pool).await?;
|
sqlx::query(sqlx::AssertSqlSafe(drop_query))
|
||||||
|
.execute(template_pool)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let database_url = icarus_envy::environment::get_db_url().await.value;
|
let database_url = sienvy::environment::get_db_url().value;
|
||||||
|
|
||||||
let parsed_url = url::Url::parse(&database_url)?;
|
let parsed_url = url::Url::parse(&database_url)?;
|
||||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||||
@@ -216,8 +225,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 +236,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 +252,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 +305,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 +362,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 +450,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 +504,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 = sienvy::environment::get_secret_key().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
|
||||||
|
|||||||
+13
-64
@@ -1,3 +1,5 @@
|
|||||||
|
pub mod service;
|
||||||
|
|
||||||
pub mod user {
|
pub mod user {
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
|
|
||||||
@@ -10,7 +12,7 @@ pub mod user {
|
|||||||
pub async fn get(
|
pub async fn get(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
username: &String,
|
username: &String,
|
||||||
) -> Result<icarus_models::user::User, sqlx::Error> {
|
) -> Result<simodels::user::User, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT * FROM "user" WHERE username = $1
|
SELECT * FROM "user" WHERE username = $1
|
||||||
@@ -22,7 +24,7 @@ pub mod user {
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => match r {
|
Ok(r) => match r {
|
||||||
Some(r) => Ok(icarus_models::user::User {
|
Some(r) => Ok(simodels::user::User {
|
||||||
id: r.try_get("id")?,
|
id: r.try_get("id")?,
|
||||||
username: r.try_get("username")?,
|
username: r.try_get("username")?,
|
||||||
password: r.try_get("password")?,
|
password: r.try_get("password")?,
|
||||||
@@ -44,7 +46,7 @@ pub mod user {
|
|||||||
|
|
||||||
pub async fn update_last_login(
|
pub async fn update_last_login(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
user: &icarus_models::user::User,
|
user: &simodels::user::User,
|
||||||
time: &time::OffsetDateTime,
|
time: &time::OffsetDateTime,
|
||||||
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
@@ -93,8 +95,8 @@ pub mod user {
|
|||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
user: &icarus_models::user::User,
|
user: &simodels::user::User,
|
||||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
) -> Result<(uuid::Uuid, std::option::Option<time::OffsetDateTime>), sqlx::Error> {
|
||||||
let row = sqlx::query(
|
let row = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status, salt_id)
|
INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status, salt_id)
|
||||||
@@ -124,10 +126,10 @@ pub mod user {
|
|||||||
.map_err(|_e| sqlx::Error::RowNotFound)?,
|
.map_err(|_e| sqlx::Error::RowNotFound)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !result.id.is_nil() {
|
if result.id.is_nil() && result.date_created.is_none() {
|
||||||
Ok(result.id)
|
|
||||||
} else {
|
|
||||||
Err(sqlx::Error::RowNotFound)
|
Err(sqlx::Error::RowNotFound)
|
||||||
|
} else {
|
||||||
|
Ok((result.id, result.date_created))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +145,7 @@ pub mod salt {
|
|||||||
pub async fn get(
|
pub async fn get(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<icarus_models::user::salt::Salt, sqlx::Error> {
|
) -> Result<simodels::user::salt::Salt, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT * FROM "salt" WHERE id = $1
|
SELECT * FROM "salt" WHERE id = $1
|
||||||
@@ -155,7 +157,7 @@ pub mod salt {
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => match r {
|
Ok(r) => match r {
|
||||||
Some(r) => Ok(icarus_models::user::salt::Salt {
|
Some(r) => Ok(simodels::user::salt::Salt {
|
||||||
id: r.try_get("id")?,
|
id: r.try_get("id")?,
|
||||||
salt: r.try_get("salt")?,
|
salt: r.try_get("salt")?,
|
||||||
}),
|
}),
|
||||||
@@ -167,7 +169,7 @@ pub mod salt {
|
|||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
salt: &icarus_models::user::salt::Salt,
|
salt: &simodels::user::salt::Salt,
|
||||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
let row = sqlx::query(
|
let row = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
@@ -195,56 +197,3 @@ pub mod salt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod service {
|
|
||||||
use sqlx::Row;
|
|
||||||
|
|
||||||
pub async fn valid_passphrase(
|
|
||||||
pool: &sqlx::PgPool,
|
|
||||||
passphrase: &String,
|
|
||||||
) -> Result<(uuid::Uuid, String, time::OffsetDateTime), sqlx::Error> {
|
|
||||||
let result = sqlx::query(
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "passphrase" WHERE passphrase = $1
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.bind(passphrase)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(row) => {
|
|
||||||
let id: uuid::Uuid = row.try_get("id")?;
|
|
||||||
let passphrase: String = row.try_get("passphrase")?;
|
|
||||||
let date_created: Option<time::OffsetDateTime> = row.try_get("date_created")?;
|
|
||||||
|
|
||||||
Ok((id, passphrase, date_created.unwrap()))
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_passphrase(
|
|
||||||
pool: &sqlx::PgPool,
|
|
||||||
id: &uuid::Uuid,
|
|
||||||
) -> Result<(uuid::Uuid, String, time::OffsetDateTime), sqlx::Error> {
|
|
||||||
let result = sqlx::query(
|
|
||||||
r#"
|
|
||||||
SELECT * FROM "passphrase" WHERE id = $1;
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.bind(id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(row) => {
|
|
||||||
let returned_id: uuid::Uuid = row.try_get("id")?;
|
|
||||||
let passphrase: String = row.try_get("passphrase")?;
|
|
||||||
let date_created: time::OffsetDateTime = row.try_get("date_created")?;
|
|
||||||
Ok((returned_id, passphrase, date_created))
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
use sqlx::Row;
|
||||||
|
|
||||||
|
pub async fn valid_passphrase(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
passphrase: &String,
|
||||||
|
) -> Result<(uuid::Uuid, String, time::OffsetDateTime), sqlx::Error> {
|
||||||
|
let result = sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT id, username, date_created FROM "passphrase" WHERE passphrase = $1
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(passphrase)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(row) => {
|
||||||
|
let id: uuid::Uuid = row.try_get("id")?;
|
||||||
|
let username: String = row.try_get("username")?;
|
||||||
|
let date_created: Option<time::OffsetDateTime> = row.try_get("date_created")?;
|
||||||
|
|
||||||
|
Ok((id, username, date_created.unwrap()))
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_passphrase(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<(String, String, time::OffsetDateTime), sqlx::Error> {
|
||||||
|
let result = sqlx::query(
|
||||||
|
r#"
|
||||||
|
SELECT username, passphrase, date_created FROM "passphrase" WHERE id = $1;
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(id)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(row) => {
|
||||||
|
let username: String = row.try_get("username")?;
|
||||||
|
let passphrase: String = row.try_get("passphrase")?;
|
||||||
|
let date_created: time::OffsetDateTime = row.try_get("date_created")?;
|
||||||
|
Ok((username, passphrase, date_created))
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-14
@@ -8,8 +8,8 @@ use time;
|
|||||||
|
|
||||||
pub const KEY_ENV: &str = "SECRET_KEY";
|
pub const KEY_ENV: &str = "SECRET_KEY";
|
||||||
pub const MESSAGE: &str = "Something random";
|
pub const MESSAGE: &str = "Something random";
|
||||||
pub const ISSUER: &str = "icarus_auth";
|
pub const ISSUER: &str = "soaricarus_auth";
|
||||||
pub const AUDIENCE: &str = "icarus";
|
pub const AUDIENCE: &str = "soaricarus";
|
||||||
|
|
||||||
pub fn get_issued() -> time::Result<time::OffsetDateTime> {
|
pub fn get_issued() -> time::Result<time::OffsetDateTime> {
|
||||||
Ok(time::OffsetDateTime::now_utc())
|
Ok(time::OffsetDateTime::now_utc())
|
||||||
@@ -24,39 +24,39 @@ pub fn create_token(
|
|||||||
provided_key: &String,
|
provided_key: &String,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<(String, i64), josekit::JoseError> {
|
) -> Result<(String, i64), josekit::JoseError> {
|
||||||
let resource = icarus_models::token::TokenResource {
|
let resource = simodels::token::TokenResource {
|
||||||
message: String::from(MESSAGE),
|
message: String::from(MESSAGE),
|
||||||
issuer: String::from(ISSUER),
|
issuer: String::from(ISSUER),
|
||||||
audiences: vec![String::from(AUDIENCE)],
|
audiences: vec![String::from(AUDIENCE)],
|
||||||
id: *id,
|
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(
|
pub fn create_service_token(
|
||||||
provided: &String,
|
provided: &String,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<(String, i64), josekit::JoseError> {
|
) -> Result<(String, i64), josekit::JoseError> {
|
||||||
let resource = icarus_models::token::TokenResource {
|
let resource = simodels::token::TokenResource {
|
||||||
message: String::from(SERVICE_SUBJECT),
|
message: String::from(SERVICE_SUBJECT),
|
||||||
issuer: String::from(ISSUER),
|
issuer: String::from(ISSUER),
|
||||||
audiences: vec![String::from(AUDIENCE)],
|
audiences: vec![String::from(AUDIENCE)],
|
||||||
id: *id,
|
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(
|
pub fn create_service_refresh_token(
|
||||||
key: &String,
|
key: &String,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<(String, i64), josekit::JoseError> {
|
) -> Result<(String, i64), josekit::JoseError> {
|
||||||
let resource = icarus_models::token::TokenResource {
|
let resource = simodels::token::TokenResource {
|
||||||
message: String::from(SERVICE_SUBJECT),
|
message: String::from(SERVICE_SUBJECT),
|
||||||
issuer: String::from(ISSUER),
|
issuer: String::from(ISSUER),
|
||||||
audiences: vec![String::from(AUDIENCE)],
|
audiences: vec![String::from(AUDIENCE)],
|
||||||
id: *id,
|
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 {
|
pub fn verify_token(key: &String, token: &String) -> bool {
|
||||||
@@ -82,9 +82,9 @@ pub fn extract_id_from_token(key: &String, token: &String) -> Result<uuid::Uuid,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const APP_TOKEN_TYPE: &str = "Icarus_App";
|
pub const APP_TOKEN_TYPE: &str = "SoarIcarus_App";
|
||||||
pub const APP_SUBJECT: &str = "Something random";
|
pub const APP_SUBJECT: &str = "Something random";
|
||||||
pub const SERVICE_TOKEN_TYPE: &str = "Icarus_Service";
|
pub const SERVICE_TOKEN_TYPE: &str = "SoarIcarus_Service";
|
||||||
pub const SERVICE_SUBJECT: &str = "Service random";
|
pub const SERVICE_SUBJECT: &str = "Service random";
|
||||||
|
|
||||||
pub fn get_token_type(key: &String, token: &String) -> Result<String, std::io::Error> {
|
pub fn get_token_type(key: &String, token: &String) -> Result<String, std::io::Error> {
|
||||||
@@ -123,10 +123,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tokenize() {
|
fn test_tokenize() {
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let special_key = sienvy::environment::get_secret_key().value;
|
||||||
let special_key = rt
|
|
||||||
.block_on(icarus_envy::environment::get_secret_key())
|
|
||||||
.value;
|
|
||||||
let id = uuid::Uuid::new_v4();
|
let id = uuid::Uuid::new_v4();
|
||||||
match create_token(&special_key, &id) {
|
match create_token(&special_key, &id) {
|
||||||
Ok((token, _duration)) => {
|
Ok((token, _duration)) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user