Compare commits
3 Commits
v0.5.0
...
a02b15c65c
Author | SHA1 | Date | |
---|---|---|---|
a02b15c65c | |||
ebe29df991 | |||
473b4ec762 |
@@ -1,3 +1,8 @@
|
|||||||
|
APP_ENV=development
|
||||||
|
BACKEND_PORT=8001
|
||||||
|
FRONTEND_URL=http://localhost:4200
|
||||||
|
RUST_LOG=debug
|
||||||
|
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=icarus_op
|
||||||
|
@@ -1,3 +1,8 @@
|
|||||||
|
APP_ENV=development
|
||||||
|
BACKEND_PORT=8001
|
||||||
|
FRONTEND_URL=http://localhost:4200
|
||||||
|
RUST_LOG=debug
|
||||||
|
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=icarus_op_test
|
||||||
|
52
Cargo.lock
generated
52
Cargo.lock
generated
@@ -627,6 +627,16 @@ dependencies = [
|
|||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hdrhistogram"
|
||||||
|
version = "7.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -749,7 +759,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_auth"
|
name = "icarus_auth"
|
||||||
version = "0.5.0"
|
version = "0.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -766,6 +776,7 @@ dependencies = [
|
|||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
|
"tower-http",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"url",
|
"url",
|
||||||
"utoipa",
|
"utoipa",
|
||||||
@@ -775,8 +786,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_envy"
|
name = "icarus_envy"
|
||||||
version = "0.3.2"
|
version = "0.4.1"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.2#d84a8144aedf02e1b459d67c4023a7e0833f89fd"
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.4.1-main-8f0d123db5-006#8f0d123db51b18e9cc4ab5bd39a474ba99bd39c3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"const_format",
|
"const_format",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
@@ -784,8 +795,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.5.6"
|
version = "0.6.6"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.6#2d6b550ae6721b41ecc3039799f6a5e873869077"
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.6.6-65-eac7562b80-111#eac7562b80b9f82d21ab737d1e84ba4f12e472dd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"josekit",
|
"josekit",
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
@@ -2152,6 +2163,19 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-util"
|
||||||
|
version = "0.7.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower"
|
name = "tower"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@@ -2160,14 +2184,32 @@ checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"hdrhistogram",
|
||||||
|
"indexmap",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"slab",
|
||||||
"sync_wrapper",
|
"sync_wrapper",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tower-http"
|
||||||
|
version = "0.6.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"bytes",
|
||||||
|
"http",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-layer"
|
name = "tower-layer"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_auth"
|
name = "icarus_auth"
|
||||||
version = "0.5.0"
|
version = "0.5.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
|
|
||||||
@@ -10,7 +10,8 @@ serde = { version = "1.0.219", features = ["derive"] }
|
|||||||
serde_json = { version = "1.0.140" }
|
serde_json = { version = "1.0.140" }
|
||||||
tokio = { version = "1.45.1", features = ["rt-multi-thread"] }
|
tokio = { version = "1.45.1", features = ["rt-multi-thread"] }
|
||||||
tracing-subscriber = { version = "0.3.19" }
|
tracing-subscriber = { version = "0.3.19" }
|
||||||
tower = { version = "0.5.2" }
|
tower = { version = "0.5.2", features = ["full"] }
|
||||||
|
tower-http = { version = "0.6.6", features = ["cors"] }
|
||||||
hyper = { version = "1.6.0" }
|
hyper = { version = "1.6.0" }
|
||||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
||||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||||
@@ -20,8 +21,8 @@ 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.4.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.5.6" }
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.6.6-65-eac7562b80-111" }
|
||||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.2" }
|
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.4.1-main-8f0d123db5-006" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
http-body-util = { version = "0.1.3" }
|
http-body-util = { version = "0.1.3" }
|
||||||
|
@@ -9,7 +9,7 @@ services:
|
|||||||
container_name: icarus_auth # Optional: Give the container a specific name
|
container_name: icarus_auth # Optional: Give the container a specific name
|
||||||
ports:
|
ports:
|
||||||
# Map host port 8000 to container port 3000 (adjust as needed)
|
# Map host port 8000 to container port 3000 (adjust as needed)
|
||||||
- "8000:3000"
|
- "8001:8001"
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
depends_on:
|
depends_on:
|
||||||
|
@@ -96,7 +96,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;
|
let key = icarus_envy::environment::get_secret_key().await.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();
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ pub mod endpoint {
|
|||||||
|
|
||||||
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, _passphrase, _date_created)) => {
|
||||||
let key = icarus_envy::environment::get_secret_key().await;
|
let key = icarus_envy::environment::get_secret_key().await.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();
|
||||||
|
|
||||||
@@ -207,7 +207,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;
|
let key = icarus_envy::environment::get_secret_key().await.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();
|
||||||
|
@@ -6,5 +6,5 @@ fn get_address() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_port() -> String {
|
fn get_port() -> String {
|
||||||
String::from("3000")
|
String::from("8001")
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
// TODO: Get rid of this file and place the code in more appropriate places
|
||||||
pub mod callers;
|
pub mod callers;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod hashing;
|
pub mod hashing;
|
||||||
@@ -15,7 +16,7 @@ pub mod db {
|
|||||||
use crate::connection_settings;
|
use crate::connection_settings;
|
||||||
|
|
||||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let database_url = icarus_envy::environment::get_db_url().await;
|
let database_url = icarus_envy::environment::get_db_url().await.value;
|
||||||
println!("Database url: {database_url}");
|
println!("Database url: {database_url}");
|
||||||
|
|
||||||
PgPoolOptions::new()
|
PgPoolOptions::new()
|
||||||
|
59
src/main.rs
59
src/main.rs
@@ -8,7 +8,7 @@ async fn main() {
|
|||||||
|
|
||||||
let app = init::app().await;
|
let app = init::app().await;
|
||||||
|
|
||||||
// run our app with hyper, listening globally on port 3000
|
// run our app with hyper, listening globally on port 8001
|
||||||
let url = config::get_full();
|
let url = config::get_full();
|
||||||
let listener = tokio::net::TcpListener::bind(url).await.unwrap();
|
let listener = tokio::net::TcpListener::bind(url).await.unwrap();
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
@@ -45,6 +45,54 @@ mod init {
|
|||||||
)]
|
)]
|
||||||
struct ApiDoc;
|
struct ApiDoc;
|
||||||
|
|
||||||
|
mod cors {
|
||||||
|
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
|
||||||
|
// Start building the CORS layer with common settings
|
||||||
|
let cors = tower_http::cors::CorsLayer::new()
|
||||||
|
.allow_methods([
|
||||||
|
axum::http::Method::GET,
|
||||||
|
axum::http::Method::POST,
|
||||||
|
axum::http::Method::PUT,
|
||||||
|
axum::http::Method::DELETE,
|
||||||
|
]) // Specify allowed methods:cite[2]
|
||||||
|
.allow_headers([
|
||||||
|
axum::http::header::CONTENT_TYPE,
|
||||||
|
axum::http::header::AUTHORIZATION,
|
||||||
|
]) // Specify allowed headers:cite[2]
|
||||||
|
.allow_credentials(true) // If you need to send cookies or authentication headers: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
|
||||||
|
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
||||||
|
Ok("production") => {
|
||||||
|
let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await;
|
||||||
|
match icarus_envy::utility::delimitize(&allowed_origins_env) {
|
||||||
|
Ok(alwd) => {
|
||||||
|
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.parse::<axum::http::HeaderValue>().unwrap())
|
||||||
|
.collect();
|
||||||
|
cors.allow_origin(allowed_origins)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Could not parse out allowed origins from env: Error: {err:?}"
|
||||||
|
);
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Development (default): Allow localhost origins
|
||||||
|
cors.allow_origin(vec![
|
||||||
|
"http://localhost:4200".parse().unwrap(),
|
||||||
|
"http://127.0.0.1:4200".parse().unwrap(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn routes() -> Router {
|
pub async fn routes() -> Router {
|
||||||
// build our application with a route
|
// build our application with a route
|
||||||
Router::new()
|
Router::new()
|
||||||
@@ -72,6 +120,7 @@ mod init {
|
|||||||
callers::endpoints::REFRESH_TOKEN,
|
callers::endpoints::REFRESH_TOKEN,
|
||||||
post(callers::login::endpoint::refresh_token),
|
post(callers::login::endpoint::refresh_token),
|
||||||
)
|
)
|
||||||
|
.layer(cors::configure_cors().await)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn app() -> Router {
|
pub async fn app() -> Router {
|
||||||
@@ -109,7 +158,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;
|
let tm_db_url = icarus_envy::environment::get_db_url().await.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
|
||||||
}
|
}
|
||||||
@@ -122,7 +171,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;
|
let db_url = icarus_envy::environment::get_db_url().await.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
|
||||||
}
|
}
|
||||||
@@ -149,7 +198,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
let database_url = icarus_envy::environment::get_db_url().await.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" {
|
||||||
@@ -452,7 +501,7 @@ mod tests {
|
|||||||
|
|
||||||
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;
|
let key = icarus_envy::environment::get_secret_key().await.value;
|
||||||
|
|
||||||
match icarus_auth::token_stuff::create_service_token(&key, &id) {
|
match icarus_auth::token_stuff::create_service_token(&key, &id) {
|
||||||
Ok((token, _expire)) => {
|
Ok((token, _expire)) => {
|
||||||
|
@@ -124,7 +124,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_tokenize() {
|
fn test_tokenize() {
|
||||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
let special_key = rt.block_on(icarus_envy::environment::get_secret_key());
|
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