1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::path::{Path, PathBuf};
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct Icinga2Instance {
pub url: String,
pub ca_certificate: Option<PathBuf>,
pub username: String,
pub password: String,
}
impl Icinga2Instance {
pub fn from_config_file(path: &Path) -> Result<Self, crate::error::Error> {
let content =
std::fs::read_to_string(path).map_err(crate::error::Error::CouldNotReadConfigFile)?;
let config: crate::config::Icinga2Instance =
toml::from_str(&content).map_err(crate::error::Error::CouldNotParseConfig)?;
Ok(config)
}
}