Updating name (#4)
Release Tagging / release (push) Failing after 1m40s
soaricarus_auth Build / Rustfmt (push) Successful in 52s
soaricarus_auth Build / Check (push) Successful in 2m5s
soaricarus_auth Build / Clippy (push) Successful in 2m48s
soaricarus_auth Build / build (push) Successful in 3m12s
soaricarus_auth Build / Test Suite (push) Successful in 4m35s
Release Tagging / release (push) Failing after 1m40s
soaricarus_auth Build / Rustfmt (push) Successful in 52s
soaricarus_auth Build / Check (push) Successful in 2m5s
soaricarus_auth Build / Clippy (push) Successful in 2m48s
soaricarus_auth Build / build (push) Successful in 3m12s
soaricarus_auth Build / Test Suite (push) Successful in 4m35s
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
+12
-12
@@ -28,14 +28,14 @@ pub mod response {
|
||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
||||
pub data: Vec<simodels::login_result::LoginResult>,
|
||||
}
|
||||
|
||||
pub mod service_login {
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
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)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
||||
pub data: Vec<simodels::login_result::LoginResult>,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ pub mod endpoint {
|
||||
Ok(user) => {
|
||||
if hashing::verify_password(&payload.password, user.password.clone()).unwrap() {
|
||||
// Create token
|
||||
let key = icarus_envy::environment::get_secret_key().value;
|
||||
let key = sienvy::environment::get_secret_key().value;
|
||||
let (token_literal, duration) =
|
||||
token_stuff::create_token(&key, &user.id).unwrap();
|
||||
|
||||
@@ -104,11 +104,11 @@ pub mod endpoint {
|
||||
StatusCode::OK,
|
||||
Json(response::Response {
|
||||
message: String::from("Successful"),
|
||||
data: vec![icarus_models::login_result::LoginResult {
|
||||
data: vec![simodels::login_result::LoginResult {
|
||||
id: user.id,
|
||||
username: user.username.clone(),
|
||||
token: token_literal,
|
||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||
token_type: String::from(simodels::token::TOKEN_TYPE),
|
||||
expiration: duration,
|
||||
}],
|
||||
}),
|
||||
@@ -151,16 +151,16 @@ pub mod endpoint {
|
||||
|
||||
match repo::service::valid_passphrase(&pool, &payload.passphrase).await {
|
||||
Ok((id, username, _date_created)) => {
|
||||
let key = icarus_envy::environment::get_secret_key().value;
|
||||
let key = sienvy::environment::get_secret_key().value;
|
||||
let (token_literal, duration) =
|
||||
token_stuff::create_service_token(&key, &id).unwrap();
|
||||
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
let login_result = icarus_models::login_result::LoginResult {
|
||||
let login_result = simodels::login_result::LoginResult {
|
||||
id,
|
||||
username,
|
||||
token: token_literal,
|
||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||
token_type: String::from(simodels::token::TOKEN_TYPE),
|
||||
expiration: duration,
|
||||
};
|
||||
|
||||
@@ -203,7 +203,7 @@ pub mod endpoint {
|
||||
axum::Json<response::refresh_token::Response>,
|
||||
) {
|
||||
let mut response = response::refresh_token::Response::default();
|
||||
let key = icarus_envy::environment::get_secret_key().value;
|
||||
let key = sienvy::environment::get_secret_key().value;
|
||||
|
||||
if token_stuff::verify_token(&key, &payload.access_token) {
|
||||
let token_type = token_stuff::get_token_type(&key, &payload.access_token).unwrap();
|
||||
@@ -215,11 +215,11 @@ pub mod endpoint {
|
||||
Ok((username, _, _)) => {
|
||||
match token_stuff::create_service_refresh_token(&key, &id) {
|
||||
Ok((access_token, exp_dur)) => {
|
||||
let login_result = icarus_models::login_result::LoginResult {
|
||||
let login_result = simodels::login_result::LoginResult {
|
||||
id,
|
||||
token: access_token,
|
||||
expiration: exp_dur,
|
||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||
token_type: String::from(simodels::token::TOKEN_TYPE),
|
||||
username,
|
||||
};
|
||||
response.message = String::from("Successful");
|
||||
|
||||
@@ -29,7 +29,7 @@ pub mod response {
|
||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::user::User>,
|
||||
pub data: Vec<simodels::user::User>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ pub async fn register_user(
|
||||
};
|
||||
|
||||
if registration_enabled {
|
||||
let mut user = icarus_models::user::User {
|
||||
let mut user = simodels::user::User {
|
||||
username: payload.username.clone(),
|
||||
password: payload.password.clone(),
|
||||
email: payload.email.clone(),
|
||||
@@ -91,7 +91,7 @@ pub async fn register_user(
|
||||
)
|
||||
} else {
|
||||
let salt_string = hashing::generate_salt().unwrap();
|
||||
let mut salt = icarus_models::user::salt::Salt::default();
|
||||
let mut salt = simodels::user::salt::Salt::default();
|
||||
let generated_salt = salt_string;
|
||||
salt.salt = generated_salt.to_string();
|
||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||
@@ -144,7 +144,7 @@ pub async fn register_user(
|
||||
/// Checks to see if registration is enabled
|
||||
async fn is_registration_enabled() -> Result<bool, std::io::Error> {
|
||||
let key = String::from("ENABLE_REGISTRATION");
|
||||
let var = icarus_envy::environment::get_env(&key);
|
||||
let var = sienvy::environment::get_env(&key);
|
||||
let parsed_value = var.value.to_uppercase();
|
||||
|
||||
if parsed_value == "TRUE" {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let database_url = icarus_envy::environment::get_db_url().value;
|
||||
let database_url = sienvy::environment::get_db_url().value;
|
||||
println!("Database url: {database_url}");
|
||||
|
||||
PgPoolOptions::new()
|
||||
|
||||
+8
-8
@@ -44,7 +44,7 @@ mod init {
|
||||
register_responses::Response,
|
||||
login_responses::Response, login_responses::service_login::Response, login_responses::refresh_token::Response)),
|
||||
tags(
|
||||
(name = "Icarus Auth API", description = "Auth API for Icarus API")
|
||||
(name = "soaricarus Auth API", description = "Auth API for soaricarus API")
|
||||
)
|
||||
)]
|
||||
struct ApiDoc;
|
||||
@@ -67,10 +67,10 @@ mod init {
|
||||
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
|
||||
|
||||
// Dynamically set the allowed origin based on the environment
|
||||
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
||||
match std::env::var(sienvy::keys::APP_ENV).as_deref() {
|
||||
Ok("production") => {
|
||||
let allowed_origins_env = icarus_envy::environment::get_allowed_origins();
|
||||
match icarus_envy::utility::delimitize(&allowed_origins_env) {
|
||||
let allowed_origins_env = sienvy::environment::get_allowed_origins();
|
||||
match sienvy::utility::delimitize(&allowed_origins_env) {
|
||||
Ok(alwd) => {
|
||||
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
||||
.into_iter()
|
||||
@@ -162,7 +162,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().value;
|
||||
let tm_db_url = sienvy::environment::get_db_url().value;
|
||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||
sqlx::PgPool::connect_with(tm_options).await
|
||||
}
|
||||
@@ -175,7 +175,7 @@ mod tests {
|
||||
}
|
||||
|
||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let db_url = icarus_envy::environment::get_db_url().value;
|
||||
let db_url = sienvy::environment::get_db_url().value;
|
||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||
sqlx::PgPool::connect_with(options).await
|
||||
}
|
||||
@@ -207,7 +207,7 @@ mod tests {
|
||||
}
|
||||
|
||||
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let database_url = icarus_envy::environment::get_db_url().value;
|
||||
let database_url = sienvy::environment::get_db_url().value;
|
||||
|
||||
let parsed_url = url::Url::parse(&database_url)?;
|
||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||
@@ -508,7 +508,7 @@ mod tests {
|
||||
|
||||
let app = init::routes().await.layer(axum::Extension(pool));
|
||||
let id = uuid::Uuid::parse_str("22f9c775-cce9-457a-a147-9dafbb801f61").unwrap();
|
||||
let key = icarus_envy::environment::get_secret_key().value;
|
||||
let key = sienvy::environment::get_secret_key().value;
|
||||
|
||||
match token_stuff::create_service_token(&key, &id) {
|
||||
Ok((token, _expire)) => {
|
||||
|
||||
+7
-7
@@ -12,7 +12,7 @@ pub mod user {
|
||||
pub async fn get(
|
||||
pool: &sqlx::PgPool,
|
||||
username: &String,
|
||||
) -> Result<icarus_models::user::User, sqlx::Error> {
|
||||
) -> Result<simodels::user::User, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT * FROM "user" WHERE username = $1
|
||||
@@ -24,7 +24,7 @@ pub mod user {
|
||||
|
||||
match result {
|
||||
Ok(r) => match r {
|
||||
Some(r) => Ok(icarus_models::user::User {
|
||||
Some(r) => Ok(simodels::user::User {
|
||||
id: r.try_get("id")?,
|
||||
username: r.try_get("username")?,
|
||||
password: r.try_get("password")?,
|
||||
@@ -46,7 +46,7 @@ pub mod user {
|
||||
|
||||
pub async fn update_last_login(
|
||||
pool: &sqlx::PgPool,
|
||||
user: &icarus_models::user::User,
|
||||
user: &simodels::user::User,
|
||||
time: &time::OffsetDateTime,
|
||||
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
@@ -95,7 +95,7 @@ pub mod user {
|
||||
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
user: &icarus_models::user::User,
|
||||
user: &simodels::user::User,
|
||||
) -> Result<(uuid::Uuid, std::option::Option<time::OffsetDateTime>), sqlx::Error> {
|
||||
let row = sqlx::query(
|
||||
r#"
|
||||
@@ -145,7 +145,7 @@ pub mod salt {
|
||||
pub async fn get(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<icarus_models::user::salt::Salt, sqlx::Error> {
|
||||
) -> Result<simodels::user::salt::Salt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT * FROM "salt" WHERE id = $1
|
||||
@@ -157,7 +157,7 @@ pub mod salt {
|
||||
|
||||
match result {
|
||||
Ok(r) => match r {
|
||||
Some(r) => Ok(icarus_models::user::salt::Salt {
|
||||
Some(r) => Ok(simodels::user::salt::Salt {
|
||||
id: r.try_get("id")?,
|
||||
salt: r.try_get("salt")?,
|
||||
}),
|
||||
@@ -169,7 +169,7 @@ pub mod salt {
|
||||
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
salt: &icarus_models::user::salt::Salt,
|
||||
salt: &simodels::user::salt::Salt,
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
let row = sqlx::query(
|
||||
r#"
|
||||
|
||||
+11
-11
@@ -8,8 +8,8 @@ use time;
|
||||
|
||||
pub const KEY_ENV: &str = "SECRET_KEY";
|
||||
pub const MESSAGE: &str = "Something random";
|
||||
pub const ISSUER: &str = "icarus_auth";
|
||||
pub const AUDIENCE: &str = "icarus";
|
||||
pub const ISSUER: &str = "soaricarus_auth";
|
||||
pub const AUDIENCE: &str = "soaricarus";
|
||||
|
||||
pub fn get_issued() -> time::Result<time::OffsetDateTime> {
|
||||
Ok(time::OffsetDateTime::now_utc())
|
||||
@@ -24,39 +24,39 @@ pub fn create_token(
|
||||
provided_key: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<(String, i64), josekit::JoseError> {
|
||||
let resource = icarus_models::token::TokenResource {
|
||||
let resource = simodels::token::TokenResource {
|
||||
message: String::from(MESSAGE),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
};
|
||||
icarus_models::token::create_token(provided_key, &resource, time::Duration::hours(4))
|
||||
simodels::token::create_token(provided_key, &resource, time::Duration::hours(4))
|
||||
}
|
||||
|
||||
pub fn create_service_token(
|
||||
provided: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<(String, i64), josekit::JoseError> {
|
||||
let resource = icarus_models::token::TokenResource {
|
||||
let resource = simodels::token::TokenResource {
|
||||
message: String::from(SERVICE_SUBJECT),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
};
|
||||
icarus_models::token::create_token(provided, &resource, time::Duration::hours(1))
|
||||
simodels::token::create_token(provided, &resource, time::Duration::hours(1))
|
||||
}
|
||||
|
||||
pub fn create_service_refresh_token(
|
||||
key: &String,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<(String, i64), josekit::JoseError> {
|
||||
let resource = icarus_models::token::TokenResource {
|
||||
let resource = simodels::token::TokenResource {
|
||||
message: String::from(SERVICE_SUBJECT),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
};
|
||||
icarus_models::token::create_token(key, &resource, time::Duration::hours(4))
|
||||
simodels::token::create_token(key, &resource, time::Duration::hours(4))
|
||||
}
|
||||
|
||||
pub fn verify_token(key: &String, token: &String) -> bool {
|
||||
@@ -82,9 +82,9 @@ pub fn extract_id_from_token(key: &String, token: &String) -> Result<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 SERVICE_TOKEN_TYPE: &str = "Icarus_Service";
|
||||
pub const SERVICE_TOKEN_TYPE: &str = "SoarIcarus_Service";
|
||||
pub const SERVICE_SUBJECT: &str = "Service random";
|
||||
|
||||
pub fn get_token_type(key: &String, token: &String) -> Result<String, std::io::Error> {
|
||||
@@ -123,7 +123,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_tokenize() {
|
||||
let special_key = icarus_envy::environment::get_secret_key().value;
|
||||
let special_key = sienvy::environment::get_secret_key().value;
|
||||
let id = uuid::Uuid::new_v4();
|
||||
match create_token(&special_key, &id) {
|
||||
Ok((token, _duration)) => {
|
||||
|
||||
Reference in New Issue
Block a user