lldap/src/infra/configuration.rs

31 lines
724 B
Rust
Raw Normal View History

2021-03-02 19:30:43 +00:00
use anyhow::Result;
use figment::{
providers::{Env, Format, Serialized, Toml},
Figment,
};
use serde::{Deserialize, Serialize};
2021-03-02 19:13:58 +00:00
2021-03-02 19:30:43 +00:00
#[derive(Debug, Deserialize, Serialize)]
pub struct Configuration {
secret_pepper: String,
some_text: String,
}
impl Default for Configuration {
fn default() -> Self {
Configuration {
secret_pepper: String::from("secretsecretpepper"),
some_text: String::new(),
}
}
}
pub fn init() -> Result<Configuration> {
let config: Configuration = Figment::from(Serialized::defaults(Configuration::default()))
.merge(Toml::file("lldap_config.toml"))
.merge(Env::prefixed("LLDAP_"))
.extract()?;
Ok(config)
2021-03-02 19:13:58 +00:00
}