WIP config rework
This commit is contained in:
parent
e2581c0dfb
commit
2779837a37
2 changed files with 57 additions and 40 deletions
|
@ -7,49 +7,43 @@ use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Config {
|
pub struct CompanionConfig {
|
||||||
pub login_static: Option<LoginStaticConfig>,
|
pub pid: Option<String>,
|
||||||
pub login_ldap: Option<LoginLdapConfig>,
|
pub imap: ImapConfig,
|
||||||
|
|
||||||
pub lmtp: Option<LmtpConfig>,
|
#[serde(flatten)]
|
||||||
pub imap: Option<ImapConfig>,
|
pub users: LoginStaticUser,
|
||||||
}
|
|
||||||
|
|
||||||
pub type LoginStaticConfig = HashMap<String, LoginStaticUser>;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
#[serde(tag = "storage_driver")]
|
|
||||||
pub enum StaticStorage {
|
|
||||||
Garage(StaticGarageConfig),
|
|
||||||
InMemory,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct StaticGarageConfig {
|
pub struct ProviderConfig {
|
||||||
pub s3_endpoint: String,
|
pub pid: Option<String>,
|
||||||
pub k2v_endpoint: String,
|
pub imap: ImapConfig,
|
||||||
pub aws_region: String,
|
pub lmtp: LmtpConfig,
|
||||||
|
pub users: UserManagement,
|
||||||
|
}
|
||||||
|
|
||||||
pub aws_access_key_id: String,
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub aws_secret_access_key: String,
|
#[serde(tag = "user_driver")]
|
||||||
pub bucket: String,
|
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)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct LoginStaticUser {
|
pub struct LoginStaticUser {
|
||||||
#[serde(default)]
|
pub user_list: String,
|
||||||
pub email_addresses: Vec<String>,
|
|
||||||
pub password: String,
|
|
||||||
|
|
||||||
pub user_secret: String,
|
|
||||||
#[serde(default)]
|
|
||||||
pub alternate_user_secrets: Vec<String>,
|
|
||||||
|
|
||||||
pub master_key: Option<String>,
|
|
||||||
pub secret_key: Option<String>,
|
|
||||||
|
|
||||||
#[serde(flatten)]
|
|
||||||
pub storage: StaticStorage,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
@ -93,17 +87,40 @@ pub struct LoginLdapConfig {
|
||||||
pub storage: LdapStorage,
|
pub storage: LdapStorage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct LmtpConfig {
|
#[serde(tag = "storage_driver")]
|
||||||
pub bind_addr: SocketAddr,
|
pub enum StaticStorage {
|
||||||
pub hostname: String,
|
Garage(StaticGarageConfig),
|
||||||
|
InMemory,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct ImapConfig {
|
pub struct StaticGarageConfig {
|
||||||
pub bind_addr: SocketAddr,
|
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<String>,
|
||||||
|
pub password: String,
|
||||||
|
|
||||||
|
pub master_key: Option<String>,
|
||||||
|
pub secret_key: Option<String>,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub storage: StaticStorage,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---
|
||||||
pub fn read_config(config_file: PathBuf) -> Result<Config> {
|
pub fn read_config(config_file: PathBuf) -> Result<Config> {
|
||||||
let mut file = std::fs::OpenOptions::new()
|
let mut file = std::fs::OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
|
|
|
@ -74,7 +74,7 @@ async fn main() -> Result<()> {
|
||||||
Command::Test => {
|
Command::Test => {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
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,
|
lmtp: None,
|
||||||
imap: Some(ImapConfig { bind_addr: SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8080) }),
|
imap: Some(ImapConfig { bind_addr: SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8080) }),
|
||||||
login_ldap: None,
|
login_ldap: None,
|
||||||
|
|
Loading…
Reference in a new issue