Compare commits

..

1 Commits

Author SHA1 Message Date
515b228250 Added EnvVar and modified functions
Some checks failed
Release Tagging / release (pull_request) Successful in 40s
Rust Build / Check (pull_request) Successful in 32s
Rust Build / Test Suite (pull_request) Failing after 40s
Rust Build / Rustfmt (pull_request) Failing after 31s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 34s
2025-10-10 13:19:26 -04:00
2 changed files with 78 additions and 27 deletions

View File

@@ -1,67 +1,105 @@
pub async fn get_db_url() -> String { pub async fn get_db_url() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::DB_URL).expect(crate::keys::error::DB_URL) let key = crate::keys::DB_URL;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_secret_main_key() -> String { pub async fn get_secret_main_key() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::SECRET_MAIN_KEY).expect(crate::keys::error::SECRET_MAIN_KEY) let key = crate::keys::SECRET_MAIN_KEY;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_service_passphrase() -> String { pub async fn get_service_passphrase() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::SERVICE_PASSPHRASE).expect(crate::keys::error::SERVICE_LOGIN) let key = crate::keys::SERVICE_PASSPHRASE;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_secret_key() -> String { pub async fn get_secret_key() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::SECRET_KEY).expect(crate::keys::error::SECRET_KEY) let key = crate::keys::SECRET_KEY;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_root_directory() -> String { pub async fn get_root_directory() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::ROOT_DIRECTORY).expect(crate::keys::error::ROOT_DIRECTORY) let key = crate::keys::ROOT_DIRECTORY;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_icarus_base_api_url() -> String { pub async fn get_icarus_base_api_url() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::ICARUS_BASE_API_URL).expect(crate::keys::error::ICARUS_BASE_API_URL) let key = crate::keys::ICARUS_BASE_API_URL;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_icarus_auth_base_api_url() -> String { pub async fn get_icarus_auth_base_api_url() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::ICARUS_AUTH_BASE_API_URL) let key = crate::keys::ICARUS_AUTH_BASE_API_URL;
.expect(crate::keys::error::ICARUS_AUTH_BASE_API_URL) let value = std::env::var(key)
.expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_app_env() -> String { pub async fn get_app_env() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::APP_ENV).expect(crate::keys::error::APP_ENV) let key = crate::keys::APP_ENV;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_backend_port() -> String { pub async fn get_backend_port() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::BACKEND_PORT).expect(crate::keys::error::BACKEND_PORT) let key = crate::keys::BACKEND_PORT;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_frontend_url() -> String { pub async fn get_frontend_url() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::FRONTEND_URL).expect(crate::keys::error::FRONTEND_URL) let key = crate::keys::FRONTEND_URL;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_rust_log() -> String { pub async fn get_rust_log() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::RUST_LOG).expect(crate::keys::error::RUST_LOG) let key = crate::keys::RUST_LOG;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_allowed_origins() -> String { pub async fn get_allowed_origins() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::ALLOWED_ORIGINS).expect(crate::keys::error::ALLOWED_ORIGINS) let key = crate::keys::ALLOWED_ORIGINS;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
/// Get environment not specified in the code /// Get environment not specified in the code
pub async fn get_env(environment: &str) -> String { pub async fn get_env(environment: &str) -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
// let key = crate::keys::
let my_error = format!("{environment} {}", crate::keys::error::GENERAL_ERROR); let my_error = format!("{environment} {}", crate::keys::error::GENERAL_ERROR);
std::env::var(environment).expect(&my_error) let value = std::env::var(environment).expect(&my_error);
crate::init_envvar(environment, &value)
} }

View File

@@ -1,2 +1,15 @@
pub mod environment; pub mod environment;
pub mod keys; pub mod keys;
#[derive(Debug, Default, Clone)]
pub struct EnvVar {
pub key: String,
pub value: String,
}
pub fn init_envvar(key: &str, value: &str) -> EnvVar {
EnvVar {
key: key.to_string(),
value: value.to_string(),
}
}