From e2581c0dfb95a3fca86bb4801f425ed519257ff9 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 24 Nov 2023 11:44:42 +0100 Subject: [PATCH] reworked configuration file --- src/config.rs | 4 ++++ src/main.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 34940f2..cacc5c8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,6 +18,7 @@ pub struct Config { pub type LoginStaticConfig = HashMap; #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "storage_driver")] pub enum StaticStorage { Garage(StaticGarageConfig), InMemory, @@ -47,10 +48,12 @@ pub struct LoginStaticUser { pub master_key: Option, pub secret_key: Option, + #[serde(flatten)] pub storage: StaticStorage, } #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "storage_driver")] pub enum LdapStorage { Garage(LdapGarageConfig), InMemory, @@ -86,6 +89,7 @@ pub struct LoginLdapConfig { pub alternate_user_secrets_attr: Option, // Storage related thing + #[serde(flatten)] pub storage: LdapStorage, } diff --git a/src/main.rs b/src/main.rs index 9efd9a5..1055650 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,8 @@ enum Command { Server { #[clap(short, long, env = "CONFIG_FILE", default_value = "aerogramme.toml")] config_file: PathBuf, - } + }, + Test, } #[derive(Parser, Debug)] @@ -70,6 +71,33 @@ async fn main() -> Result<()> { let server = Server::new(config).await?; server.run().await?; } + Command::Test => { + use std::collections::HashMap; + use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; + println!("--- toml ---\n{}\n--- end ---\n", toml::to_string(&Config { + lmtp: None, + imap: Some(ImapConfig { bind_addr: SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8080) }), + login_ldap: None, + login_static: Some(HashMap::from([ + ("alice".into(), LoginStaticUser { + password: "hash".into(), + user_secret: "hello".into(), + alternate_user_secrets: vec![], + email_addresses: vec![], + master_key: None, + secret_key: None, + storage: StaticStorage::Garage(StaticGarageConfig { + s3_endpoint: "http://".into(), + k2v_endpoint: "http://".into(), + aws_region: "garage".into(), + aws_access_key_id: "GK...".into(), + aws_secret_access_key: "xxx".into(), + bucket: "aerogramme".into(), + }), + }) + ])), + }).unwrap()); + } } Ok(())