use std::collections::HashMap; use std::io::Read; use std::net::SocketAddr; use std::path::PathBuf; use anyhow::Result; use serde::Deserialize; #[derive(Deserialize, Debug, Clone)] pub struct Config { pub s3_endpoint: String, pub k2v_endpoint: String, pub aws_region: String, pub login_static: Option, pub login_ldap: Option, pub lmtp: Option, } #[derive(Deserialize, Debug, Clone)] pub struct LoginStaticConfig { pub default_bucket: Option, pub users: HashMap, } #[derive(Deserialize, Debug, Clone)] pub struct LoginStaticUser { #[serde(default)] pub email_addresses: Vec, pub password: String, pub aws_access_key_id: String, pub aws_secret_access_key: String, pub bucket: Option, pub user_secret: String, #[serde(default)] pub alternate_user_secrets: Vec, pub master_key: Option, pub secret_key: Option, } #[derive(Deserialize, Debug, Clone)] pub struct LoginLdapConfig { pub ldap_server: String, #[serde(default)] pub pre_bind_on_login: bool, pub bind_dn: Option, pub bind_password: Option, pub search_base: String, pub username_attr: String, #[serde(default = "default_mail_attr")] pub mail_attr: String, pub aws_access_key_id_attr: String, pub aws_secret_access_key_attr: String, pub user_secret_attr: String, pub alternate_user_secrets_attr: Option, pub bucket: Option, pub bucket_attr: Option, } #[derive(Deserialize, Debug, Clone)] pub struct LmtpConfig { pub bind_addr: SocketAddr, pub hostname: String, } pub fn read_config(config_file: PathBuf) -> Result { let mut file = std::fs::OpenOptions::new() .read(true) .open(config_file.as_path())?; let mut config = String::new(); file.read_to_string(&mut config)?; Ok(toml::from_str(&config)?) } fn default_mail_attr() -> String { "mail".into() }