Files
sender/src/config/mod.rs
T
phoenix c62fddf44e
sender pr / Check (pull_request) Failing after 13s
sender pr / Rustfmt (pull_request) Successful in 1m10s
sender pr / Clippy (pull_request) Successful in 3m42s
sender Build / Check (push) Successful in 1m39s
sender Build / Rustfmt (push) Successful in 1m19s
sender Build / Test Suite (push) Successful in 2m3s
sender Build / Clippy (push) Successful in 2m10s
sender Build / build (push) Successful in 2m53s
Update rust (#8)
Reviewed-on: #8
2026-07-06 23:15:25 -04:00

69 lines
2.2 KiB
Rust

pub const APP_NAME: &str = "sender";
/// Returns numbers and message paths
pub fn get_paths(args: Vec<String>) -> Result<(String, String), std::io::Error> {
if args.len() < 2 {
Err(std::io::Error::other("Not enough arguments"))
} else {
let numbers_path = args[1].clone();
let message_path = args[2].clone();
if !path_exists(&numbers_path) && !path_exists(&message_path) {
Err(std::io::Error::other("Paths do not exists"))
} else {
Ok((numbers_path, message_path))
}
}
}
fn path_exists(path: &str) -> bool {
let file = std::path::Path::new(path);
file.exists()
}
pub fn parse_config() -> (textsender_models::config::auxiliary::TwilioConfig, bool) {
let mut config = textsender_models::config::auxiliary::TwilioConfig {
..Default::default()
};
let auth_sid_var = textsender_models::envy::environment::get_env("AUTH_SID");
let auth_token_var = textsender_models::envy::environment::get_env("AUTH_TOKEN");
let phone_number_var = textsender_models::envy::environment::get_env("PHONE_NUMBER");
let service_sid_var = textsender_models::envy::environment::get_env("SERVICE_SID");
config.account_sid = auth_sid_var.value;
config.auth_token = auth_token_var.value;
config.phone_number = phone_number_var.value;
config.service_sid = service_sid_var.value;
let success = {
!config.account_sid.is_empty()
&& !config.auth_token.is_empty()
&& !config.phone_number.is_empty()
&& !config.service_sid.is_empty()
};
(config, success)
}
#[cfg(test)]
mod tests {
#[test]
fn test_parse_config() {
let (config, success) = super::parse_config();
assert!(success, "Config was not parsed");
assert_eq!(
false,
config.account_sid.is_empty(),
"Account SID is missing"
);
assert_eq!(false, config.auth_token.is_empty(), "AUTH TOKEN is missing");
assert_eq!(
false,
config.phone_number.is_empty(),
"Phone Number is missing"
);
assert_eq!(
false,
config.service_sid.is_empty(),
"Service SID is missing"
);
}
}