Compare commits
4 Commits
v0.6.4-mai
...
7881a865ae
| Author | SHA1 | Date | |
|---|---|---|---|
|
7881a865ae
|
|||
|
8a9bcce8f2
|
|||
|
a89415178d
|
|||
|
130e7cc25e
|
@@ -10,4 +10,3 @@ POSTGRES_AUTH_PASSWORD=password
|
||||
POSTGRES_AUTH_DB=icarus_auth_db
|
||||
POSTGRES_AUTH_HOST=auth_db
|
||||
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
||||
ENABLE_REGISTRATION=TRUE
|
||||
|
||||
@@ -10,4 +10,3 @@ POSTGRES_AUTH_PASSWORD=password
|
||||
POSTGRES_AUTH_DB=icarus_auth_test_db
|
||||
POSTGRES_AUTH_HOST=localhost
|
||||
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
|
||||
ENABLE_REGISTRATION=TRUE
|
||||
@@ -3,21 +3,21 @@ name: Release Tagging
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- devel
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0 # Important for git describe --tags
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.90.0
|
||||
toolchain: 1.88.0
|
||||
components: cargo
|
||||
|
||||
- name: Extract Version from Cargo.toml
|
||||
@@ -27,10 +27,8 @@ jobs:
|
||||
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
||||
BRANCH_REF="${GITHUB_REF}"
|
||||
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-950"
|
||||
|
||||
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE"
|
||||
|
||||
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH"
|
||||
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-950"
|
||||
echo "Version: $VERSION"
|
||||
echo "Hash: $PROJECT_COMMIT_HASH"
|
||||
echo "Branch: $BRANCH_NAME"
|
||||
|
||||
@@ -15,10 +15,10 @@ jobs:
|
||||
name: Check
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.90.0
|
||||
toolchain: 1.88.0
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||
@@ -50,10 +50,10 @@ jobs:
|
||||
--health-retries 5
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.90.0
|
||||
toolchain: 1.88.0
|
||||
# --- Add this step for explicit verification ---
|
||||
- name: Verify Docker Environment
|
||||
run: |
|
||||
@@ -76,7 +76,6 @@ jobs:
|
||||
SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
||||
# Make SSH agent available if tests fetch private dependencies
|
||||
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
|
||||
ENABLE_REGISTRATION: 'TRUE'
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||
@@ -92,10 +91,10 @@ jobs:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.90.0
|
||||
toolchain: 1.88.0
|
||||
- run: rustup component add rustfmt
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
@@ -111,10 +110,10 @@ jobs:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.90.0
|
||||
toolchain: 1.88.0
|
||||
- run: rustup component add clippy
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
@@ -130,10 +129,10 @@ jobs:
|
||||
name: build
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.90.0
|
||||
toolchain: 1.88.0
|
||||
- run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||
|
||||
831
Cargo.lock
generated
831
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
26
Cargo.toml
26
Cargo.toml
@@ -1,30 +1,30 @@
|
||||
[package]
|
||||
name = "icarus_auth"
|
||||
version = "0.6.4"
|
||||
version = "0.5.2"
|
||||
edition = "2024"
|
||||
rust-version = "1.90"
|
||||
rust-version = "1.88"
|
||||
|
||||
[dependencies]
|
||||
axum = { version = "0.8.6" }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = { version = "1.0.145" }
|
||||
tokio = { version = "1.47.1", features = ["rt-multi-thread"] }
|
||||
tracing-subscriber = { version = "0.3.20" }
|
||||
axum = { version = "0.8.4" }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = { version = "1.0.140" }
|
||||
tokio = { version = "1.45.1", features = ["rt-multi-thread"] }
|
||||
tracing-subscriber = { version = "0.3.19" }
|
||||
tower = { version = "0.5.2", features = ["full"] }
|
||||
tower-http = { version = "0.6.6", features = ["cors"] }
|
||||
hyper = { version = "1.7.0" }
|
||||
hyper = { version = "1.6.0" }
|
||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
||||
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||
argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version
|
||||
rand = { version = "0.9.2" }
|
||||
rand = { version = "0.9.1" }
|
||||
time = { version = "0.3.41", features = ["macros", "serde"] }
|
||||
josekit = { version = "0.10.3" }
|
||||
utoipa = { version = "5.4.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.8.0" }
|
||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.5.0" }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" }
|
||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.4.1-main-8f0d123db5-006" }
|
||||
|
||||
[dev-dependencies]
|
||||
http-body-util = { version = "0.1.3" }
|
||||
url = { version = "2.5.7" }
|
||||
url = { version = "2.5.4" }
|
||||
once_cell = { version = "1.21.3" } # Useful for lazy initialization in tests/app setup
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 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.90 as builder
|
||||
FROM rust:1.88 as builder
|
||||
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
12
README.md
12
README.md
@@ -8,26 +8,22 @@ need to be modified. The `SECRET_KEY` variable should be changed since it will b
|
||||
generation. The `SECRET_PASSPHASE` should also be changed when in production mode, but make sure
|
||||
the respective `passphrase` database table record exists.
|
||||
|
||||
To enable or disable registrations, use `TRUE` or `FALSE` for the `ENABLE_REGISTRATION` variable.
|
||||
By default it is `TRUE`.
|
||||
|
||||
|
||||
### Build image
|
||||
Build image
|
||||
```
|
||||
docker compose build
|
||||
```
|
||||
|
||||
### Start images
|
||||
Start images
|
||||
```
|
||||
docker compose up -d --force-recreate
|
||||
```
|
||||
|
||||
### Bring it down
|
||||
Bring it down
|
||||
```
|
||||
docker compose down -v
|
||||
```
|
||||
|
||||
### Pruning
|
||||
Pruning
|
||||
```
|
||||
docker system prune -a
|
||||
```
|
||||
|
||||
@@ -52,22 +52,8 @@ pub async fn register_user(
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
Json(payload): Json<request::Request>,
|
||||
) -> (StatusCode, Json<response::Response>) {
|
||||
let registration_enabled = match is_registration_enabled().await {
|
||||
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 = icarus_models::user::User {
|
||||
id: uuid::Uuid::nil(),
|
||||
username: payload.username.clone(),
|
||||
password: payload.password.clone(),
|
||||
email: payload.email.clone(),
|
||||
@@ -76,17 +62,19 @@ pub async fn register_user(
|
||||
lastname: payload.lastname.clone(),
|
||||
status: String::from("Active"),
|
||||
email_verified: true,
|
||||
..Default::default()
|
||||
date_created: Some(time::OffsetDateTime::now_utc()),
|
||||
last_login: None,
|
||||
salt_id: uuid::Uuid::nil(),
|
||||
};
|
||||
|
||||
match repo::user::exists(&pool, &user.username).await {
|
||||
Ok(res) => {
|
||||
if res {
|
||||
(
|
||||
StatusCode::BAD_REQUEST,
|
||||
StatusCode::NOT_FOUND,
|
||||
Json(response::Response {
|
||||
message: String::from("Error"),
|
||||
data: Vec::new(),
|
||||
data: vec![user],
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
@@ -101,9 +89,8 @@ pub async fn register_user(
|
||||
user.password = hashed_password;
|
||||
|
||||
match repo::user::insert(&pool, &user).await {
|
||||
Ok((id, date_created)) => {
|
||||
Ok(id) => {
|
||||
user.id = id;
|
||||
user.date_created = date_created;
|
||||
(
|
||||
StatusCode::CREATED,
|
||||
Json(response::Response {
|
||||
@@ -130,30 +117,4 @@ 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 = icarus_envy::environment::get_env(&key).await;
|
||||
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",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let database_url = icarus_envy::environment::get_db_url().await.value;
|
||||
println!("Database url: {database_url}");
|
||||
|
||||
PgPoolOptions::new()
|
||||
.max_connections(super::connection_settings::MAXCONN)
|
||||
.connect(&database_url)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn migrations(pool: &sqlx::PgPool) {
|
||||
// Run migrations using the sqlx::migrate! macro
|
||||
// Assumes your migrations are in a ./migrations folder relative to Cargo.toml
|
||||
sqlx::migrate!("./migrations")
|
||||
.run(pool)
|
||||
.await
|
||||
.expect("Failed to run migrations");
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
pub mod init;
|
||||
|
||||
mod connection_settings {
|
||||
pub const MAXCONN: u32 = 5;
|
||||
}
|
||||
36
src/lib.rs
Normal file
36
src/lib.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
42
src/main.rs
42
src/main.rs
@@ -1,9 +1,5 @@
|
||||
pub mod callers;
|
||||
pub mod config;
|
||||
pub mod db;
|
||||
pub mod hashing;
|
||||
pub mod repo;
|
||||
pub mod token_stuff;
|
||||
use icarus_auth::callers;
|
||||
use icarus_auth::config;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@@ -25,7 +21,7 @@ mod init {
|
||||
};
|
||||
use utoipa::OpenApi;
|
||||
|
||||
use super::callers;
|
||||
use crate::callers;
|
||||
use callers::common as common_callers;
|
||||
use callers::login as login_caller;
|
||||
use callers::register as register_caller;
|
||||
@@ -128,11 +124,11 @@ mod init {
|
||||
}
|
||||
|
||||
pub async fn app() -> Router {
|
||||
let pool = super::db::init::create_pool()
|
||||
let pool = icarus_auth::db::create_pool()
|
||||
.await
|
||||
.expect("Failed to create pool");
|
||||
|
||||
super::db::init::migrations(&pool).await;
|
||||
icarus_auth::db::migrations(&pool).await;
|
||||
|
||||
routes()
|
||||
.await
|
||||
@@ -162,7 +158,7 @@ mod tests {
|
||||
pub const LIMIT: usize = 6;
|
||||
|
||||
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 = icarus_envy::environment::get_db_url().await;
|
||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||
sqlx::PgPool::connect_with(tm_options).await
|
||||
}
|
||||
@@ -175,7 +171,7 @@ mod tests {
|
||||
}
|
||||
|
||||
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 = icarus_envy::environment::get_db_url().await;
|
||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||
sqlx::PgPool::connect_with(options).await
|
||||
}
|
||||
@@ -202,7 +198,7 @@ mod tests {
|
||||
}
|
||||
|
||||
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 = icarus_envy::environment::get_db_url().await;
|
||||
|
||||
let parsed_url = url::Url::parse(&database_url)?;
|
||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||
@@ -220,8 +216,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_test_register_request() -> callers::register::request::Request {
|
||||
callers::register::request::Request {
|
||||
fn get_test_register_request() -> icarus_auth::callers::register::request::Request {
|
||||
icarus_auth::callers::register::request::Request {
|
||||
username: String::from("somethingsss"),
|
||||
password: String::from("Raindown!"),
|
||||
email: String::from("dev@null.com"),
|
||||
@@ -231,7 +227,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_test_register_payload(usr: &callers::register::request::Request) -> serde_json::Value {
|
||||
fn get_test_register_payload(
|
||||
usr: &icarus_auth::callers::register::request::Request,
|
||||
) -> serde_json::Value {
|
||||
json!({
|
||||
"username": &usr.username,
|
||||
"password": &usr.password,
|
||||
@@ -247,7 +245,7 @@ mod tests {
|
||||
|
||||
pub async fn register(
|
||||
app: &axum::Router,
|
||||
usr: &super::callers::register::request::Request,
|
||||
usr: &icarus_auth::callers::register::request::Request,
|
||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||
let payload = super::get_test_register_payload(&usr);
|
||||
let req = axum::http::Request::builder()
|
||||
@@ -300,7 +298,7 @@ mod tests {
|
||||
|
||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||
|
||||
db::init::migrations(&pool).await;
|
||||
icarus_auth::db::migrations(&pool).await;
|
||||
|
||||
let app = init::routes().await.layer(axum::Extension(pool));
|
||||
|
||||
@@ -357,7 +355,7 @@ mod tests {
|
||||
|
||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||
|
||||
db::init::migrations(&pool).await;
|
||||
icarus_auth::db::migrations(&pool).await;
|
||||
|
||||
let app = init::routes().await.layer(axum::Extension(pool));
|
||||
|
||||
@@ -445,7 +443,7 @@ mod tests {
|
||||
|
||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||
|
||||
db::init::migrations(&pool).await;
|
||||
icarus_auth::db::migrations(&pool).await;
|
||||
|
||||
let app = init::routes().await.layer(axum::Extension(pool));
|
||||
let passphrase =
|
||||
@@ -499,13 +497,13 @@ mod tests {
|
||||
|
||||
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||
|
||||
db::init::migrations(&pool).await;
|
||||
icarus_auth::db::migrations(&pool).await;
|
||||
|
||||
let app = init::routes().await.layer(axum::Extension(pool));
|
||||
let id = uuid::Uuid::parse_str("22f9c775-cce9-457a-a147-9dafbb801f61").unwrap();
|
||||
let key = icarus_envy::environment::get_secret_key().await.value;
|
||||
let key = icarus_envy::environment::get_secret_key().await;
|
||||
|
||||
match token_stuff::create_service_token(&key, &id) {
|
||||
match icarus_auth::token_stuff::create_service_token(&key, &id) {
|
||||
Ok((token, _expire)) => {
|
||||
let payload = serde_json::json!({
|
||||
"access_token": token
|
||||
|
||||
@@ -94,7 +94,7 @@ pub mod user {
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
user: &icarus_models::user::User,
|
||||
) -> Result<(uuid::Uuid, std::option::Option<time::OffsetDateTime>), sqlx::Error> {
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
let row = sqlx::query(
|
||||
r#"
|
||||
INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status, salt_id)
|
||||
@@ -124,10 +124,10 @@ pub mod user {
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)?,
|
||||
};
|
||||
|
||||
if result.id.is_nil() && result.date_created.is_none() {
|
||||
Err(sqlx::Error::RowNotFound)
|
||||
if !result.id.is_nil() {
|
||||
Ok(result.id)
|
||||
} else {
|
||||
Ok((result.id, result.date_created))
|
||||
Err(sqlx::Error::RowNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user