Add complex configuration

This commit is contained in:
Thomas Wickham 2021-03-02 20:30:43 +01:00
parent 845073c29d
commit acc80d21e5
3 changed files with 34 additions and 13 deletions

View File

@ -1,21 +1,16 @@
[package]
name = "lldap"
authors = ["Valentin Tolmer <valentin@tolmer.fr>", "Steve Barrau <steve.barrau@gmail.com>", "Thomas Wickham <mackwic@gmail.com>"]
edition = "2018"
name = "lldap"
version = "0.1.0"
authors = [
"Valentin Tolmer <valentin@tolmer.fr>",
"Steve Barrau <steve.barrau@gmail.com>",
"Thomas Wickham <mackwic@gmail.com>"
]
[dependencies]
clap = "3.0.0-beta.2"
actix-web = "3"
anyhow = "*"
thiserror="*"
clap = "3.0.0-beta.2"
http = "*"
passablewords = "*"
serde = "*"
thiserror = "*"
tracing = "*"
tracing-actix-web = "*"
tracing-log = "*"

2
lldap_config.toml Normal file
View File

@ -0,0 +1,2 @@
# LLDAP configuration
some_text = "ok boomer"

View File

@ -1,6 +1,30 @@
#[derive(Debug, Default)]
pub struct Configuration;
use anyhow::Result;
use figment::{
providers::{Env, Format, Serialized, Toml},
Figment,
};
use serde::{Deserialize, Serialize};
pub fn init() -> Configuration {
Configuration::default()
#[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)
}