diff options
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 30 |
2 files changed, 33 insertions, 1 deletions
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<String, LoginStaticUser>; #[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<String>, pub secret_key: Option<String>, + #[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<String>, // 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(()) |