reworked configuration file

This commit is contained in:
Quentin 2023-11-24 11:44:42 +01:00
parent 0722886efb
commit e2581c0dfb
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 33 additions and 1 deletions

View file

@ -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,
}

View file

@ -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(())