controller/
config.rs

1use std::env;
2
3#[derive(Clone, Debug)]
4pub struct Config {
5    pub enable_backup: bool,
6    pub enable_volume_snapshot: bool,
7    pub volume_snapshot_retention_period_days: u64,
8    pub reconcile_ttl: u64,
9}
10
11impl Default for Config {
12    fn default() -> Self {
13        Self {
14            enable_backup: from_env_default("ENABLE_BACKUP", "true").parse().unwrap(),
15            enable_volume_snapshot: from_env_default("ENABLE_VOLUME_SNAPSHOT", "false")
16                .parse()
17                .unwrap(),
18            volume_snapshot_retention_period_days: from_env_default(
19                "VOLUME_SNAPSHOT_RETENTION_PERIOD_DAYS",
20                "40",
21            )
22            .parse()
23            .unwrap(),
24            // The time to live for reconciling the entire instance
25            reconcile_ttl: from_env_default("RECONCILE_TTL", "90").parse().unwrap(),
26        }
27    }
28}
29
30// Source the variable from the env - use default if not set
31fn from_env_default(var: &str, default: &str) -> String {
32    env::var(var).unwrap_or_else(|_| default.to_owned())
33}