From a7a2a8080e305c2cb39d276ce73a163effc8c512 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 13:54:10 -0400 Subject: [PATCH 1/8] Added code to initialize an envvar delimiter --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5e88d16..ab8f471 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +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; } } -- 2.43.0 From d9e43a80e4620409d3140adf67cb55c25c936fcf Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 13:58:29 -0400 Subject: [PATCH 2/8] Made modifications to the test and related code --- src/environment.rs | 5 ++++- tests/test.rs | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/environment.rs b/src/environment.rs index b0e9972..dc7c48c 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -90,7 +90,10 @@ pub async fn get_allowed_origins() -> crate::EnvVar { let key = crate::keys::ALLOWED_ORIGINS; let value = std::env::var(key).expect(key); - crate::init_envvar(key, &value) + let mut envvar = crate::init_envvar(key, &value); + crate::init_delimiter(&mut envvar, ','); + + envvar } /// Get environment not specified in the code diff --git a/tests/test.rs b/tests/test.rs index d92de61..62f23ed 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -114,7 +114,9 @@ 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) } #[test] -- 2.43.0 From c06d546ae78154eaa1777466a7e5c32a48fca693 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 14:11:01 -0400 Subject: [PATCH 3/8] Updated test --- src/utility.rs | 7 +++++++ tests/test.rs | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/utility.rs diff --git a/src/utility.rs b/src/utility.rs new file mode 100644 index 0000000..0c749f0 --- /dev/null +++ b/src/utility.rs @@ -0,0 +1,7 @@ +pub fn split_words(var: &crate::EnvVar) -> Result, std::io::Error> { + if var.has_delimiter { + Ok(var.value.split(var.delimiter).map(|c| c.parse::().unwrap()).collect()) + } else { + Err(std::io::Error::other("Environment variable does not have a delimiter")) + } +} diff --git a/tests/test.rs b/tests/test.rs index 62f23ed..c09967e 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -116,7 +116,16 @@ mod tests { result ); - assert_eq!(result.has_delimiter, true, "The {} variable has an issue finding the delimiter", result.key) + assert_eq!(result.has_delimiter, true, "The {} variable has an issue finding the delimiter", result.key); + + match icarus_envy::utility::split_words(&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] -- 2.43.0 From 218b0f60a964c41e904fba10779d9824da387b52 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 14:19:48 -0400 Subject: [PATCH 4/8] Removing comment --- src/environment.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/environment.rs b/src/environment.rs index dc7c48c..5848c7d 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -99,7 +99,6 @@ pub async fn get_allowed_origins() -> crate::EnvVar { /// 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); -- 2.43.0 From 797430c9d20887768b2a8b7d171aee0aebfcf6d4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 14:24:04 -0400 Subject: [PATCH 5/8] Changed name of function --- src/utility.rs | 4 +++- tests/test.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utility.rs b/src/utility.rs index 0c749f0..ebc966d 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -1,4 +1,6 @@ -pub fn split_words(var: &crate::EnvVar) -> Result, std::io::Error> { +/// 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, std::io::Error> { if var.has_delimiter { Ok(var.value.split(var.delimiter).map(|c| c.parse::().unwrap()).collect()) } else { diff --git a/tests/test.rs b/tests/test.rs index c09967e..20a9468 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -118,7 +118,7 @@ mod tests { assert_eq!(result.has_delimiter, true, "The {} variable has an issue finding the delimiter", result.key); - match icarus_envy::utility::split_words(&result) { + 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) } -- 2.43.0 From 101547dbf49fcf17867ffb647557d9bc3061d04b Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 14:25:13 -0400 Subject: [PATCH 6/8] Code formatting --- src/lib.rs | 2 +- src/utility.rs | 10 ++++++++-- tests/test.rs | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ab8f471..bc3dd1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ pub struct EnvVar { pub key: String, pub value: String, pub has_delimiter: bool, - pub delimiter: char + pub delimiter: char, } pub fn init_envvar(key: &str, value: &str) -> EnvVar { diff --git a/src/utility.rs b/src/utility.rs index ebc966d..11b5476 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -2,8 +2,14 @@ /// extract it into some strings pub fn delimitize(var: &crate::EnvVar) -> Result, std::io::Error> { if var.has_delimiter { - Ok(var.value.split(var.delimiter).map(|c| c.parse::().unwrap()).collect()) + Ok(var + .value + .split(var.delimiter) + .map(|c| c.parse::().unwrap()) + .collect()) } else { - Err(std::io::Error::other("Environment variable does not have a delimiter")) + Err(std::io::Error::other( + "Environment variable does not have a delimiter", + )) } } diff --git a/tests/test.rs b/tests/test.rs index 20a9468..59bc259 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -116,11 +116,21 @@ mod tests { result ); - assert_eq!(result.has_delimiter, true, "The {} variable has an issue finding the delimiter", result.key); + 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) + assert_eq!( + allowed_origins.len(), + 2, + "The amount of allowed origins does not match. {} {}", + allowed_origins.len(), + 2 + ) } Err(err) => { assert!(false, "Error: {:?}", err) -- 2.43.0 From 50e77edddc03529ebb49feca3abbf4fe8c061a19 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 14:38:46 -0400 Subject: [PATCH 7/8] Clippy fix --- src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bc3dd1d..d3d1bde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,11 +28,7 @@ pub fn init_delimiter(envvar: &mut EnvVar, delimiter: char) { } } - let has_delimiter = if amount_of_delimiters_found >= 1 { - true - } else { - false - }; + let has_delimiter = amount_of_delimiters_found >= 1; if has_delimiter { envvar.has_delimiter = has_delimiter; -- 2.43.0 From 1823a3a4aa188042ad6f77223cdf47c3b007d46f Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 10 Oct 2025 14:39:40 -0400 Subject: [PATCH 8/8] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0ae075..fec5334 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ checksum = "f154ce46856750ed433c8649605bf7ed2de3bc35fd9d2a9f30cddd873c80cb08" [[package]] name = "icarus_envy" -version = "0.4.0" +version = "0.4.1" dependencies = [ "async-std", "const_format", diff --git a/Cargo.toml b/Cargo.toml index 72a3b8c..9b1a7d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_envy" -version = "0.4.0" +version = "0.4.1" edition = "2024" rust-version = "1.88" -- 2.43.0