Migrate (#4)
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
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 async 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").await;
|
||||
let auth_token_var = textsender_models::envy::environment::get_env("AUTH_TOKEN").await;
|
||||
let phone_number_var = textsender_models::envy::environment::get_env("PHONE_NUMBER").await;
|
||||
let service_sid_var = textsender_models::envy::environment::get_env("SERVICE_SID").await;
|
||||
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) = async_std::task::block_on(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"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user