From 2779837a3750c3b2964c3a4d5d43de25218bc605 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 4 Dec 2023 16:51:27 +0100 Subject: [PATCH] WIP config rework --- src/config.rs | 95 ++++++++++++++++++++++++++++++--------------------- src/main.rs | 2 +- 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/config.rs b/src/config.rs index cacc5c8..286ef65 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,49 +7,43 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct Config { - pub login_static: Option, - pub login_ldap: Option, +pub struct CompanionConfig { + pub pid: Option, + pub imap: ImapConfig, - pub lmtp: Option, - pub imap: Option, -} - -pub type LoginStaticConfig = HashMap; - -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(tag = "storage_driver")] -pub enum StaticStorage { - Garage(StaticGarageConfig), - InMemory, + #[serde(flatten)] + pub users: LoginStaticUser, } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct StaticGarageConfig { - pub s3_endpoint: String, - pub k2v_endpoint: String, - pub aws_region: String, +pub struct ProviderConfig { + pub pid: Option, + pub imap: ImapConfig, + pub lmtp: LmtpConfig, + pub users: UserManagement, +} - pub aws_access_key_id: String, - pub aws_secret_access_key: String, - pub bucket: String, +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(tag = "user_driver")] +pub enum UserManagement { + Static(LoginStaticUser), + Ldap(LoginLdapConfig), +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct LmtpConfig { + pub bind_addr: SocketAddr, + pub hostname: String, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct ImapConfig { + pub bind_addr: SocketAddr, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct LoginStaticUser { - #[serde(default)] - pub email_addresses: Vec, - pub password: String, - - pub user_secret: String, - #[serde(default)] - pub alternate_user_secrets: Vec, - - pub master_key: Option, - pub secret_key: Option, - - #[serde(flatten)] - pub storage: StaticStorage, + pub user_list: String, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -93,17 +87,40 @@ pub struct LoginLdapConfig { pub storage: LdapStorage, } +// ---- + #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct LmtpConfig { - pub bind_addr: SocketAddr, - pub hostname: String, +#[serde(tag = "storage_driver")] +pub enum StaticStorage { + Garage(StaticGarageConfig), + InMemory, } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct ImapConfig { - pub bind_addr: SocketAddr, +pub struct StaticGarageConfig { + pub s3_endpoint: String, + pub k2v_endpoint: String, + pub aws_region: String, + + pub aws_access_key_id: String, + pub aws_secret_access_key: String, + pub bucket: String, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct UserEntry { + #[serde(default)] + pub email_addresses: Vec, + pub password: String, + + pub master_key: Option, + pub secret_key: Option, + + #[serde(flatten)] + pub storage: StaticStorage, +} + +// --- pub fn read_config(config_file: PathBuf) -> Result { let mut file = std::fs::OpenOptions::new() .read(true) diff --git a/src/main.rs b/src/main.rs index 1055650..a566ec6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,7 @@ async fn main() -> Result<()> { Command::Test => { use std::collections::HashMap; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; - println!("--- toml ---\n{}\n--- end ---\n", toml::to_string(&Config { + println!("--- message pack ---\n{:?}\n--- end ---\n", rmp_serde::to_vec(&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,