Added EnvVar (#24)
All checks were successful
Release Tagging / release (push) Successful in 34s
Rust Build / Check (push) Successful in 30s
Rust Build / Test Suite (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 34s
Rust Build / build (push) Successful in 30s
Release Tagging / release (pull_request) Successful in 33s
Rust Build / Check (pull_request) Successful in 30s
Rust Build / Test Suite (pull_request) Successful in 31s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Successful in 35s
Rust Build / build (pull_request) Successful in 31s

Reviewed-on: #24
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
2025-10-10 17:37:32 +00:00
committed by phoenix
parent 86c5050c7b
commit 38e0073cbe
5 changed files with 95 additions and 41 deletions

View File

@@ -1,67 +1,104 @@
pub async fn get_db_url() -> String {
pub async fn get_db_url() -> crate::EnvVar {
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();
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();
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();
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();
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();
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();
std::env::var(crate::keys::ICARUS_AUTH_BASE_API_URL)
.expect(crate::keys::error::ICARUS_AUTH_BASE_API_URL)
let key = crate::keys::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();
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();
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();
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();
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();
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
pub async fn get_env(environment: &str) -> String {
pub async fn get_env(environment: &str) -> crate::EnvVar {
dotenvy::dotenv().ok();
// let key = crate::keys::
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 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(),
}
}