Compare commits

...

12 Commits

Author SHA1 Message Date
101547dbf4 Code formatting
Some checks failed
Release Tagging / release (pull_request) Successful in 32s
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 32s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Failing after 33s
Rust Build / build (pull_request) Successful in 35s
2025-10-10 14:25:13 -04:00
797430c9d2 Changed name of function 2025-10-10 14:24:04 -04:00
218b0f60a9 Removing comment 2025-10-10 14:19:48 -04:00
c06d546ae7 Updated test 2025-10-10 14:11:01 -04:00
d9e43a80e4 Made modifications to the test and related code 2025-10-10 13:58:29 -04:00
a7a2a8080e Added code to initialize an envvar delimiter 2025-10-10 13:54:10 -04:00
38e0073cbe 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>
2025-10-10 17:37:32 +00:00
86c5050c7b Refactoring (#21)
All checks were successful
Rust Build / Check (push) Successful in 33s
Rust Build / Test Suite (push) Successful in 37s
Release Tagging / release (push) Successful in 46s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / Clippy (push) Successful in 36s
Rust Build / build (push) Successful in 40s
Reviewed-on: #21
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-09-29 20:38:53 +00:00
0f470ef723 Added general environment function (#20)
All checks were successful
Rust Build / Check (push) Successful in 40s
Release Tagging / release (push) Successful in 45s
Rust Build / Test Suite (push) Successful in 34s
Rust Build / Rustfmt (push) Successful in 36s
Rust Build / Clippy (push) Successful in 42s
Rust Build / build (push) Successful in 36s
Reviewed-on: #20
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-09-29 19:22:10 +00:00
e51df82f09 CORS env variables (#19)
All checks were successful
Release Tagging / release (push) Successful in 41s
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 38s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 35s
Rust Build / build (push) Successful in 31s
Reviewed-on: #19
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-09-28 23:08:32 +00:00
d84a8144ae tsk-17: Add ICARUS_AUTH_BASE_API_URL env key (#18)
All checks were successful
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 30s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / build (push) Successful in 30s
Rust Build / Clippy (push) Successful in 34s
Release Tagging / release (push) Successful in 33s
Closes #17

Reviewed-on: #18
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-14 22:58:45 +00:00
3cd42dab6b Service passphrase (#16)
All checks were successful
Rust Build / Check (push) Successful in 28s
Release Tagging / release (push) Successful in 51s
Rust Build / Test Suite (push) Successful in 28s
Rust Build / Clippy (push) Successful in 29s
Rust Build / Rustfmt (push) Successful in 46s
Rust Build / build (push) Successful in 27s
Reviewed-on: #16
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-02 21:26:14 +00:00
10 changed files with 320 additions and 25 deletions

9
.env
View File

@@ -1,5 +1,8 @@
RANDOM_ENV_KEY="YouDon'tWantToButYouGottaChange|It'sGoingToHurtYouTryingToStayTheSame|AreYouInItOrYouInItForTheFame?|I'mTryingToFigureOutWhoLoveMeForMe"
MODNAR_ENV_KEY="FeelingTheMonsterClimbDeepserInsideOfMe|FeelingHimGnawingMyHeartAwayHungrily|I'llNeverLoseThisPain|NeverDreamOfYouAgain"
SECRET_MAIN_KEY=Somesupersecretpassword!!!45345435
SECRET_KEY=AmIGoodEnoughForYou?
SERVICE_PASSPHRASE=T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO
ROOT_DIRECTORY=/path/to/root
POSTGRES_MAIN_USER=myuser
POSTGRES_MAIN_PASSWORD=password
@@ -7,3 +10,9 @@ POSTGRES_MAIN_DB=my_db
POSTGRES_MAIN_HOST=localhost
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
ICARUS_BASE_API_URL=https://icarus.com
ICARUS_AUTH_BASE_API_URL=https://auth.icarus.com
APP_ENV=development
BACKEND_PORT=8001
FRONTEND_URL=http://localhost:4200
RUST_LOG=debug
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com

View File

@@ -1,5 +1,8 @@
RANDOM_ENV_KEY="YouDon'tWantToButYouGottaChange|It'sGoingToHurtYouTryingToStayTheSame|AreYouInItOrYouInItForTheFame?|I'mTryingToFigureOutWhoLoveMeForMe"
MODNAR_ENV_KEY="FeelingTheMonsterClimbDeepserInsideOfMe|FeelingHimGnawingMyHeartAwayHungrily|I'llNeverLoseThisPain|NeverDreamOfYouAgain"
SECRET_MAIN_KEY=Somesupersecretpassword!!!45345435
SECRET_KEY=AmIGoodEnoughForYou?
SERVICE_PASSPHRASE=T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO
ROOT_DIRECTORY=/path/to/root
POSTGRES_MAIN_USER=myuser
POSTGRES_MAIN_PASSWORD=password
@@ -7,3 +10,9 @@ POSTGRES_MAIN_DB=my_db
POSTGRES_MAIN_HOST=localhost
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
ICARUS_BASE_API_URL=https://icarus.com
ICARUS_AUTH_BASE_API_URL=https://auth.icarus.com
APP_ENV=development
BACKEND_PORT=8001
FRONTEND_URL=http://localhost:4200
RUST_LOG=debug
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com

View File

@@ -4,6 +4,9 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
release:

2
Cargo.lock generated
View File

@@ -297,7 +297,7 @@ checksum = "f154ce46856750ed433c8649605bf7ed2de3bc35fd9d2a9f30cddd873c80cb08"
[[package]]
name = "icarus_envy"
version = "0.3.0"
version = "0.4.0"
dependencies = [
"async-std",
"const_format",

View File

@@ -1,6 +1,6 @@
[package]
name = "icarus_envy"
version = "0.3.0"
version = "0.4.0"
edition = "2024"
rust-version = "1.88"

View File

@@ -1,24 +1,106 @@
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_secret_key() -> String {
pub async fn get_service_passphrase() -> crate::EnvVar {
dotenvy::dotenv().ok();
std::env::var(crate::keys::SECRET_KEY).expect(crate::keys::error::SECRET_KEY)
let key = crate::keys::SERVICE_PASSPHRASE;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_root_directory() -> String {
pub async fn get_secret_key() -> crate::EnvVar {
dotenvy::dotenv().ok();
std::env::var(crate::keys::ROOT_DIRECTORY).expect(crate::keys::error::ROOT_DIRECTORY)
let key = crate::keys::SECRET_KEY;
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_root_directory() -> 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::ROOT_DIRECTORY;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_icarus_base_api_url() -> crate::EnvVar {
dotenvy::dotenv().ok();
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() -> crate::EnvVar {
dotenvy::dotenv().ok();
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() -> crate::EnvVar {
dotenvy::dotenv().ok();
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() -> crate::EnvVar {
dotenvy::dotenv().ok();
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() -> crate::EnvVar {
dotenvy::dotenv().ok();
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() -> crate::EnvVar {
dotenvy::dotenv().ok();
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() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::ALLOWED_ORIGINS;
let value = std::env::var(key).expect(key);
let mut envvar = crate::init_envvar(key, &value);
crate::init_delimiter(&mut envvar, ',');
envvar
}
/// Get environment not specified in the code
pub async fn get_env(environment: &str) -> crate::EnvVar {
dotenvy::dotenv().ok();
let my_error = format!("{environment} {}", crate::keys::error::GENERAL_ERROR);
let value = std::env::var(environment).expect(&my_error);
crate::init_envvar(environment, &value)
}

View File

@@ -1,27 +1,52 @@
// Environment key for Database management
/// Environment key for Database management
pub const DB_URL: &str = "DATABASE_URL";
// Environment key for secret main key
// Used for the icarus app
/// Environment key for secret main key
/// Used for the icarus app
pub const SECRET_MAIN_KEY: &str = "SECRET_MAIN_KEY";
// Environment key for secret key
// Generic use of secret key that could be found in various apps
/// Environment key for service logins
pub const SERVICE_PASSPHRASE: &str = "SERVICE_PASSPHRASE";
/// Environment key for secret key
/// Generic use of secret key that could be found in various apps
pub const SECRET_KEY: &str = "SECRET_KEY";
// Environment key for root directory for the icarus app
/// Environment key for root directory for the icarus app
pub const ROOT_DIRECTORY: &str = "ROOT_DIRECTORY";
// Environment key for icarus api url
/// Environment key for icarus api url
pub const ICARUS_BASE_API_URL: &str = "ICARUS_BASE_API_URL";
/// Environment key for icarus auth api url
pub const ICARUS_AUTH_BASE_API_URL: &str = "ICARUS_AUTH_BASE_API_URL";
/// Environment key for App status
pub const APP_ENV: &str = "APP_ENV";
/// Environment key for backend port. Used for both auth and core functionality
pub const BACKEND_PORT: &str = "BACKEND_PORT";
/// Environment key for frontend url
pub const FRONTEND_URL: &str = "FRONTEND_URL";
/// Environment key for application logging
pub const RUST_LOG: &str = "RUST_LOG";
/// Environment key for allowed origins for CORS support
pub const ALLOWED_ORIGINS: &str = "ALLOWED_ORIGINS";
pub mod error {
use const_format::concatcp;
pub const GENERAL_ERROR: &str = "must not be set in enviornment file";
pub const DB_URL: &str = concatcp!(super::DB_URL, " ", GENERAL_ERROR);
pub const SECRET_KEY: &str = concatcp!(super::SECRET_KEY, " ", GENERAL_ERROR);
pub const SECRET_MAIN_KEY: &str = concatcp!(super::SECRET_MAIN_KEY, " ", GENERAL_ERROR);
pub const SERVICE_LOGIN: &str = concatcp!(super::SERVICE_PASSPHRASE, " ", GENERAL_ERROR);
pub const SECRET_KEY: &str = concatcp!(super::SECRET_KEY, " ", GENERAL_ERROR);
pub const ROOT_DIRECTORY: &str = concatcp!(super::ROOT_DIRECTORY, " ", GENERAL_ERROR);
pub const ICARUS_BASE_API_URL: &str = concatcp!(super::ICARUS_BASE_API_URL, " ", GENERAL_ERROR);
pub const ICARUS_AUTH_BASE_API_URL: &str =
concatcp!(super::ICARUS_AUTH_BASE_API_URL, " ", GENERAL_ERROR);
pub const APP_ENV: &str = concatcp!(super::APP_ENV, " ", GENERAL_ERROR);
pub const BACKEND_PORT: &str = concatcp!(super::BACKEND_PORT, " ", GENERAL_ERROR);
pub const FRONTEND_URL: &str = concatcp!(super::FRONTEND_URL, " ", GENERAL_ERROR);
pub const RUST_LOG: &str = concatcp!(super::RUST_LOG, " ", GENERAL_ERROR);
pub const ALLOWED_ORIGINS: &str = concatcp!(super::ALLOWED_ORIGINS, " ", GENERAL_ERROR);
}

View File

@@ -1,2 +1,43 @@
pub mod environment;
pub mod keys;
pub mod utility;
#[derive(Debug, Default, Clone)]
pub struct EnvVar {
pub key: String,
pub value: String,
pub has_delimiter: bool,
pub delimiter: char,
}
pub fn init_envvar(key: &str, value: &str) -> EnvVar {
EnvVar {
key: key.to_string(),
value: value.to_string(),
has_delimiter: false,
..Default::default()
}
}
pub fn init_delimiter(envvar: &mut EnvVar, delimiter: char) {
let mut amount_of_delimiters_found: i32 = 0;
for v in envvar.value.chars() {
if v == delimiter {
amount_of_delimiters_found += 1;
}
}
let has_delimiter = if amount_of_delimiters_found >= 1 {
true
} else {
false
};
if has_delimiter {
envvar.has_delimiter = has_delimiter;
envvar.delimiter = delimiter;
} else {
envvar.has_delimiter = has_delimiter;
}
}

15
src/utility.rs Normal file
View File

@@ -0,0 +1,15 @@
/// Take the Environment variable and delimitize it. If the value has a delimiter,
/// extract it into some strings
pub fn delimitize(var: &crate::EnvVar) -> Result<Vec<String>, std::io::Error> {
if var.has_delimiter {
Ok(var
.value
.split(var.delimiter)
.map(|c| c.parse::<String>().unwrap())
.collect())
} else {
Err(std::io::Error::other(
"Environment variable does not have a delimiter",
))
}
}

View File

@@ -4,7 +4,7 @@ mod tests {
fn test_dburl() {
let result = async_std::task::block_on(icarus_envy::environment::get_db_url());
assert_eq!(
result, "postgres://myuser:password@localhost:5432/my_db",
result.value, "postgres://myuser:password@localhost:5432/my_db",
"DATABASE_URL does not match {:?}",
result
);
@@ -14,17 +14,27 @@ mod tests {
fn test_get_secret_main_key() {
let result = async_std::task::block_on(icarus_envy::environment::get_secret_main_key());
assert_eq!(
result, "Somesupersecretpassword!!!45345435",
result.value, "Somesupersecretpassword!!!45345435",
"SECRET_MAIN_KEY does not match {:?}",
result
)
}
#[test]
fn test_get_service_passphrase() {
let result = async_std::task::block_on(icarus_envy::environment::get_service_passphrase());
assert_eq!(
result.value, "T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO",
"SERVICE_PASSPHRASE does not match {:?}",
result
)
}
#[test]
fn test_get_secret_key() {
let result = async_std::task::block_on(icarus_envy::environment::get_secret_key());
assert_eq!(
result, "AmIGoodEnoughForYou?",
result.value, "AmIGoodEnoughForYou?",
"SECRET_KEY does not match {:?}",
result
)
@@ -34,7 +44,7 @@ mod tests {
fn test_get_root_directory() {
let result = async_std::task::block_on(icarus_envy::environment::get_root_directory());
assert_eq!(
result, "/path/to/root",
result.value, "/path/to/root",
"ROOT_DIRECTORY does not match {:?}",
result
)
@@ -44,9 +54,110 @@ mod tests {
fn test_get_icarus_base_api_url() {
let result = async_std::task::block_on(icarus_envy::environment::get_icarus_base_api_url());
assert_eq!(
result, "https://icarus.com",
result.value, "https://icarus.com",
"ICARUS_BASE_API_URL does not match {:?}",
result
)
}
#[test]
fn test_get_app_env() {
let result = async_std::task::block_on(icarus_envy::environment::get_app_env());
assert_eq!(
result.value,
"development",
"{} does not match {:?}",
icarus_envy::keys::APP_ENV,
result
)
}
#[test]
fn test_get_backend_port() {
let result = async_std::task::block_on(icarus_envy::environment::get_backend_port());
assert_eq!(
result.value,
"8001",
"{} does not match {:?}",
icarus_envy::keys::BACKEND_PORT,
result
)
}
#[test]
fn test_get_frontend_url() {
let result = async_std::task::block_on(icarus_envy::environment::get_frontend_url());
assert_eq!(
result.value,
"http://localhost:4200",
"{} does not match {:?}",
icarus_envy::keys::FRONTEND_URL,
result
)
}
#[test]
fn test_get_rust_log() {
let result = async_std::task::block_on(icarus_envy::environment::get_rust_log());
assert_eq!(
result.value,
"debug",
"{} does not match {:?}",
icarus_envy::keys::RUST_LOG,
result
)
}
#[test]
fn test_get_allowed_origins() {
let result = async_std::task::block_on(icarus_envy::environment::get_allowed_origins());
assert_eq!(
result.value,
"https://soaricarus.com,https://www.soaricarus.com",
"{} does not match {:?}",
icarus_envy::keys::ALLOWED_ORIGINS,
result
);
assert_eq!(
result.has_delimiter, true,
"The {} variable has an issue finding the delimiter",
result.key
);
match icarus_envy::utility::delimitize(&result) {
Ok(allowed_origins) => {
assert_eq!(
allowed_origins.len(),
2,
"The amount of allowed origins does not match. {} {}",
allowed_origins.len(),
2
)
}
Err(err) => {
assert!(false, "Error: {:?}", err)
}
}
}
#[test]
fn test_get_env() {
let keys = vec![
(
"RANDOM_ENV_KEY",
"YouDon'tWantToButYouGottaChange|It'sGoingToHurtYouTryingToStayTheSame|AreYouInItOrYouInItForTheFame?|I'mTryingToFigureOutWhoLoveMeForMe",
),
(
"MODNAR_ENV_KEY",
"FeelingTheMonsterClimbDeepserInsideOfMe|FeelingHimGnawingMyHeartAwayHungrily|I'llNeverLoseThisPain|NeverDreamOfYouAgain",
),
];
for (key, value) in keys.iter() {
let result = async_std::task::block_on(icarus_envy::environment::get_env(key));
assert_eq!(
result.value, *value,
"{:?} does not match {:?}",
key, result
)
}
}
}