From acc80d21e5f51170de130af149ae27525091b125 Mon Sep 17 00:00:00 2001 From: Thomas Wickham Date: Tue, 2 Mar 2021 20:30:43 +0100 Subject: [PATCH] Add complex configuration --- Cargo.toml | 13 ++++--------- lldap_config.toml | 2 ++ src/infra/configuration.rs | 32 ++++++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 lldap_config.toml diff --git a/Cargo.toml b/Cargo.toml index 62dccd1..70936e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,16 @@ [package] -name = "lldap" +authors = ["Valentin Tolmer ", "Steve Barrau ", "Thomas Wickham "] edition = "2018" +name = "lldap" version = "0.1.0" -authors = [ - "Valentin Tolmer ", - "Steve Barrau ", - "Thomas Wickham " -] - [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 = "*" diff --git a/lldap_config.toml b/lldap_config.toml new file mode 100644 index 0000000..8720539 --- /dev/null +++ b/lldap_config.toml @@ -0,0 +1,2 @@ +# LLDAP configuration +some_text = "ok boomer" \ No newline at end of file diff --git a/src/infra/configuration.rs b/src/infra/configuration.rs index 4880f38..6e2ce0a 100644 --- a/src/infra/configuration.rs +++ b/src/infra/configuration.rs @@ -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 { + let config: Configuration = Figment::from(Serialized::defaults(Configuration::default())) + .merge(Toml::file("lldap_config.toml")) + .merge(Env::prefixed("LLDAP_")) + .extract()?; + + Ok(config) }