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] [package]
name = "lldap" authors = ["Valentin Tolmer <valentin@tolmer.fr>", "Steve Barrau <steve.barrau@gmail.com>", "Thomas Wickham <mackwic@gmail.com>"]
edition = "2018" edition = "2018"
name = "lldap"
version = "0.1.0" version = "0.1.0"
authors = [
"Valentin Tolmer <valentin@tolmer.fr>",
"Steve Barrau <steve.barrau@gmail.com>",
"Thomas Wickham <mackwic@gmail.com>"
]
[dependencies] [dependencies]
clap = "3.0.0-beta.2"
actix-web = "3" actix-web = "3"
anyhow = "*" anyhow = "*"
thiserror="*" clap = "3.0.0-beta.2"
http = "*" http = "*"
passablewords = "*" passablewords = "*"
serde = "*" serde = "*"
thiserror = "*"
tracing = "*" tracing = "*"
tracing-actix-web = "*" tracing-actix-web = "*"
tracing-log = "*" 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)] use anyhow::Result;
pub struct Configuration; use figment::{
providers::{Env, Format, Serialized, Toml},
Figment,
};
use serde::{Deserialize, Serialize};
pub fn init() -> Configuration { #[derive(Debug, Deserialize, Serialize)]
Configuration::default() 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)
} }