2022-08-10 16:46:56 +02:00
|
|
|
use envconfig::Envconfig;
|
|
|
|
|
|
|
|
pub enum CuddleFetchPolicy {
|
|
|
|
Always,
|
|
|
|
Once,
|
2022-08-14 20:19:29 +02:00
|
|
|
Never,
|
2022-08-10 16:46:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Envconfig, Clone)]
|
|
|
|
pub struct CuddleConfig {
|
|
|
|
#[envconfig(from = "CUDDLE_FETCH_POLICY", default = "once")]
|
|
|
|
fetch_policy: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CuddleConfig {
|
|
|
|
pub fn from_env() -> anyhow::Result<Self> {
|
|
|
|
CuddleConfig::init_from_env().map_err(|e| anyhow::Error::from(e))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_fetch_policy(&self) -> anyhow::Result<CuddleFetchPolicy> {
|
|
|
|
match self.fetch_policy.clone().to_lowercase().as_str() {
|
|
|
|
"always" => Ok(CuddleFetchPolicy::Always),
|
|
|
|
"once" => Ok(CuddleFetchPolicy::Once),
|
2022-08-14 20:19:29 +02:00
|
|
|
"never" => Ok(CuddleFetchPolicy::Never),
|
2022-08-10 16:46:56 +02:00
|
|
|
_ => Err(anyhow::anyhow!("could not parse fetch policy")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|