Move .env configuration to config.toml
This commit is contained in:
parent
4ba04706b5
commit
f78f735b2c
5 changed files with 128 additions and 40 deletions
src
|
@ -140,3 +140,47 @@ impl Default for ZoneConfig {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub(crate) struct AppConfig {
|
||||
#[serde(alias="cf_api_token")]
|
||||
pub(crate) cloudflare_api_token: String,
|
||||
pub(crate) check_interval_seconds: Option<u16>,
|
||||
pub(crate) uptime_url: Option<String>,
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub(crate) fn load() -> Result<Self, Box<dyn Error>> {
|
||||
let cfg: Self = match confy::load(env!("CARGO_PKG_NAME"),"config") {
|
||||
Ok(data) => data,
|
||||
Err(e) => {
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {e}"),
|
||||
false => eprintln!("[ERROR] {e}")
|
||||
}
|
||||
return Err(Box::new(e));
|
||||
}
|
||||
};
|
||||
|
||||
if cfg.cloudflare_api_token.is_empty() {
|
||||
let err_msg = "Cloudflare api token not specified. The app cannot work without this";
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}")
|
||||
}
|
||||
panic!("{err_msg}");
|
||||
}
|
||||
|
||||
Ok(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cloudflare_api_token: "".to_owned(),
|
||||
check_interval_seconds: None,
|
||||
uptime_url: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue