Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6508c6c535 |
Generated
+10
-10
@@ -732,14 +732,14 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.17"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f02ab6bace2054fb888a3c16f990117b579d14a3088e472d63c6011fa185c9d3"
|
||||
checksum = "c943259e342f1e06ff2da7a83eabdfe7f92ce10262688dbf1895ff0b3e6e4652"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
"plain",
|
||||
"redox_syscall 0.8.1",
|
||||
"redox_syscall 0.9.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1106,9 +1106,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.8.1"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b44b894f2a6e36457d665d1e08c3866add6ed5e70050c1b4ba8a8ddedb02ce7"
|
||||
checksum = "c5102a6aaa05aa011a238e178e6bca86d2cb56fc9f586d37cb80f5bca6e07759"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
@@ -1626,7 +1626,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "textsender_models"
|
||||
version = "0.4.10"
|
||||
version = "0.4.11"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"dotenvy",
|
||||
@@ -1661,9 +1661,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.51"
|
||||
version = "0.3.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85c17d80feb7334b40c484e45ed1a5273dfd8bfda537c3be2e74a06a6686f327"
|
||||
checksum = "18dfaaeddcb932337b5e7866ee7d0ce9b76d2fd092997146f187ec09b4558a50"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"num-conv",
|
||||
@@ -1681,9 +1681,9 @@ checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.30"
|
||||
version = "0.2.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcef1a61bdb119096e153208ec5cbec23944ce8bca13be5c7f60c634f7403935"
|
||||
checksum = "c431b87111666e491a90baa837f914fb45cd5dc3c268591b0220ff5057f2085f"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "textsender_models"
|
||||
version = "0.4.10"
|
||||
version = "0.4.11"
|
||||
edition = "2024"
|
||||
rust-version = "1.96"
|
||||
description = "Models used for the textsender project"
|
||||
|
||||
@@ -20,12 +20,11 @@ impl TwilioConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove the async at a later point
|
||||
pub async fn load_config() -> Result<TwilioConfig, std::io::Error> {
|
||||
let auth_sid_var = crate::envy::environment::get_env("TWILIO_AUTH_SID").await;
|
||||
let service_sid_var = crate::envy::environment::get_env("TWILIO_SERVICE_SID").await;
|
||||
let auth_token_var = crate::envy::environment::get_env("TWILIO_AUTH_TOKEN").await;
|
||||
let phone_number_var = crate::envy::environment::get_env("TWILIO_PHONE_NUMBER").await;
|
||||
pub fn load_config() -> Result<TwilioConfig, std::io::Error> {
|
||||
let auth_sid_var = crate::envy::environment::get_env("TWILIO_AUTH_SID");
|
||||
let service_sid_var = crate::envy::environment::get_env("TWILIO_SERVICE_SID");
|
||||
let auth_token_var = crate::envy::environment::get_env("TWILIO_AUTH_TOKEN");
|
||||
let phone_number_var = crate::envy::environment::get_env("TWILIO_PHONE_NUMBER");
|
||||
|
||||
if auth_sid_var.value.is_empty()
|
||||
|| service_sid_var.value.is_empty()
|
||||
|
||||
+14
-16
@@ -1,6 +1,4 @@
|
||||
// TODO: Functions does not need to be async
|
||||
|
||||
pub async fn get_db_url() -> crate::envy::EnvVar {
|
||||
pub fn get_db_url() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::DB_URL;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -8,7 +6,7 @@ pub async fn get_db_url() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_secret_main_key() -> crate::envy::EnvVar {
|
||||
pub fn get_secret_main_key() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::SECRET_MAIN_KEY;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -16,7 +14,7 @@ pub async fn get_secret_main_key() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_service_passphrase() -> crate::envy::EnvVar {
|
||||
pub fn get_service_passphrase() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::SERVICE_PASSPHRASE;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -24,7 +22,7 @@ pub async fn get_service_passphrase() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_secret_key() -> crate::envy::EnvVar {
|
||||
pub fn get_secret_key() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::SECRET_KEY;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -32,7 +30,7 @@ pub async fn get_secret_key() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_root_directory() -> crate::envy::EnvVar {
|
||||
pub fn get_root_directory() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::ROOT_DIRECTORY;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -40,7 +38,7 @@ pub async fn get_root_directory() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_app_base_api_url() -> crate::envy::EnvVar {
|
||||
pub fn get_app_base_api_url() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::TEXTSENDER_BASE_API_URL;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -48,7 +46,7 @@ pub async fn get_app_base_api_url() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_app_auth_base_api_url() -> crate::envy::EnvVar {
|
||||
pub fn get_app_auth_base_api_url() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::TEXTSENDER_AUTH_BASE_API_URL;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -56,7 +54,7 @@ pub async fn get_app_auth_base_api_url() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_app_env() -> crate::envy::EnvVar {
|
||||
pub fn get_app_env() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::APP_ENV;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -64,14 +62,14 @@ pub async fn get_app_env() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_backend_port() -> crate::envy::EnvVar {
|
||||
pub fn get_backend_port() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::BACKEND_PORT;
|
||||
let value = std::env::var(key).expect(key);
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_frontend_url() -> crate::envy::EnvVar {
|
||||
pub fn get_frontend_url() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::FRONTEND_URL;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -79,7 +77,7 @@ pub async fn get_frontend_url() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_rust_log() -> crate::envy::EnvVar {
|
||||
pub fn get_rust_log() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::RUST_LOG;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -87,7 +85,7 @@ pub async fn get_rust_log() -> crate::envy::EnvVar {
|
||||
crate::envy::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub async fn get_allowed_origins() -> crate::envy::EnvVar {
|
||||
pub fn get_allowed_origins() -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::envy::keys::ALLOWED_ORIGINS;
|
||||
let value = std::env::var(key).expect(key);
|
||||
@@ -98,8 +96,8 @@ pub async fn get_allowed_origins() -> crate::envy::EnvVar {
|
||||
envvar
|
||||
}
|
||||
|
||||
/// Get environment not specified in the code
|
||||
pub async fn get_env(environment: &str) -> crate::envy::EnvVar {
|
||||
/// Get environment not specified in the library
|
||||
pub fn get_env(environment: &str) -> crate::envy::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let my_error = format!("{environment} {}", crate::envy::keys::error::GENERAL_ERROR);
|
||||
let value = std::env::var(environment).expect(&my_error);
|
||||
|
||||
+25
-7
@@ -20,16 +20,17 @@ pub fn init_envvar(key: &str, value: &str) -> EnvVar {
|
||||
}
|
||||
|
||||
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 amount_of_delimiters_found: i32 = {
|
||||
let mut count = 0;
|
||||
for v in envvar.value.chars() {
|
||||
if v == delimiter {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
count
|
||||
};
|
||||
let has_delimiter = amount_of_delimiters_found >= 1;
|
||||
|
||||
if has_delimiter {
|
||||
envvar.has_delimiter = has_delimiter;
|
||||
envvar.delimiter = delimiter;
|
||||
@@ -37,3 +38,20 @@ pub fn init_delimiter(envvar: &mut EnvVar, delimiter: char) {
|
||||
envvar.has_delimiter = has_delimiter;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_init_delimiter() {
|
||||
let delimiter: char = ',';
|
||||
let value = format!("red,green,white,black");
|
||||
let mut env_var = super::EnvVar {
|
||||
key: String::from("COLORS"),
|
||||
value: value.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
super::init_delimiter(&mut env_var, delimiter);
|
||||
assert_eq!(value, env_var.value, "Colors do not match");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user