Compare commits

..

6 Commits

Author SHA1 Message Date
97be15d6fd Version bump
All checks were successful
Release Tagging / release (pull_request) Successful in 33s
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 32s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 32s
Rust Build / build (pull_request) Successful in 30s
Breaking change
2025-10-10 13:25:46 -04:00
3cddc77542 Version bump
All checks were successful
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 32s
Rust Build / build (pull_request) Successful in 30s
2025-10-10 13:23:00 -04:00
c5ad65c93e Forgot to include code formatted file 2025-10-10 13:22:40 -04:00
951b0ec508 Code formatting 2025-10-10 13:21:49 -04:00
72d37722c0 Updated tests 2025-10-10 13:21:34 -04:00
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
4 changed files with 3 additions and 69 deletions

View File

@@ -90,15 +90,13 @@ pub async fn get_allowed_origins() -> crate::EnvVar {
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
crate::init_envvar(key, &value)
}
/// Get environment not specified in the code
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);
let value = std::env::var(environment).expect(&my_error);

View File

@@ -1,43 +1,15 @@
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;
}
}

View File

@@ -1,15 +0,0 @@
/// 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

@@ -114,28 +114,7 @@ mod tests {
"{} 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]