Files
catapult/src/app.rs
T
phoenix 8dbfd88aae
catapult PR / Check (pull_request) Successful in 59s
catapult PR / Rustfmt (pull_request) Successful in 1m25s
catapult PR / Clippy (pull_request) Successful in 1m18s
Refactoring (#15)
Reviewed-on: #15
2026-07-07 15:51:06 -04:00

61 lines
1.9 KiB
Rust

/// Seconds to sleep after finising a task
pub const SECONDS_TO_SLEEP: u64 = 5;
pub const APP_NAME: &str = "catapult";
#[derive(Clone, Debug)]
pub struct App {
pub api_url: String,
pub auth_url: String,
pub service_username: String,
pub service_passphrase: String,
pub twilio_config: textsender_models::config::auxiliary::TwilioConfig,
}
pub fn load_app() -> Result<App, std::io::Error> {
use textsender_models::envy;
let auth_url_env = envy::environment::get_env("AUTH_URL");
let api_url_env = envy::environment::get_env("API_URL");
let service_username_env = envy::environment::get_env("SERVICE_USERNAME");
let service_passphrase_env = envy::environment::get_env("SERVICE_PASSPHRASE");
let envs = vec![
&api_url_env,
&auth_url_env,
&service_username_env,
&service_passphrase_env,
];
let check_envs = |vs: &Vec<&envy::EnvVar>| -> (bool, Option<String>) {
for env in vs {
if env.value.is_empty() {
return (false, Some(format!("Key {} is not provided", env.key)));
}
}
(true, None)
};
let (envs_valid, reason) = check_envs(&envs);
if envs_valid {
let auth_url: String = auth_url_env.value;
let api_url: String = api_url_env.value;
let service_username: String = service_username_env.value;
let service_passphrase: String = service_passphrase_env.value;
match textsender_models::config::auxiliary::load_config() {
Ok(twilio_config) => Ok(App {
api_url,
auth_url,
service_username,
service_passphrase,
twilio_config,
}),
Err(err) => Err(err),
}
} else {
match reason {
Some(reason) => Err(std::io::Error::other(reason)),
None => Err(std::io::Error::other("No reason found")),
}
}
}