use dotenvy;
use crate::utilities::env::format_env;
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Env {
pub name: String,
pub value: Option<String>,
}
impl From<String> for Env {
fn from(value: String) -> Self {
Self {
name: value.to_uppercase(),
value: dotenvy::var(value.to_uppercase()).ok(),
}
}
}
impl From<&str> for Env {
fn from(value: &str) -> Self {
Self {
name: value.to_uppercase(),
value: dotenvy::var(value.to_uppercase()).ok(),
}
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Credentials {
pub username: Env,
pub password: Env,
}
impl From<&str> for Credentials {
fn from(name: &str) -> Self {
Self {
username: format_env(name, "username").into(),
password: format_env(name, "password").into(),
}
}
}
impl Credentials {
pub fn is_ok(&self) -> bool {
self.username.value.is_some() && self.password.value.is_some()
}
}
#[derive(Debug)]
pub struct SubscanModuleEnvs {
pub host: Env,
pub apikey: Env,
pub credentials: Credentials,
}
impl From<&str> for SubscanModuleEnvs {
fn from(name: &str) -> Self {
Self {
host: format_env(name, "host").into(),
apikey: format_env(name, "apikey").into(),
credentials: name.into(),
}
}
}