From 16b38f3197167c344bb522dcfa83292ddb3c1026 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 17 Nov 2023 16:42:25 +0100 Subject: integrate storage choice in config --- src/config.rs | 57 ++++++++++++++++++++++++++++++-------------- src/login/static_provider.rs | 1 + 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index 074c192..2a55036 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,10 +8,6 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, 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, @@ -19,21 +15,30 @@ pub struct Config { pub imap: Option, } +pub type LoginStaticConfig = HashMap; + #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct LoginStaticConfig { - pub default_bucket: Option, - pub users: HashMap, +pub enum StaticStorage { + Garage(StaticGarageConfig), + InMemory, } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct LoginStaticUser { - #[serde(default)] - pub email_addresses: Vec, - pub password: String, +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: Option, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct LoginStaticUser { + #[serde(default)] + pub email_addresses: Vec, + pub password: String, pub user_secret: String, #[serde(default)] @@ -43,27 +48,43 @@ pub struct LoginStaticUser { pub secret_key: Option, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub enum LdapStorage { + Garage(LdapGarageConfig), + InMemory, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct LdapGarageConfig { + pub s3_endpoint: String, + pub k2v_endpoint: String, + pub aws_region: String, + + pub aws_access_key_id_attr: String, + pub aws_secret_access_key_attr: String, + pub bucket_attr: Option, + pub default_bucket: Option, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct LoginLdapConfig { + // LDAP connection info pub ldap_server: String, - #[serde(default)] pub pre_bind_on_login: bool, pub bind_dn: Option, pub bind_password: Option, - pub search_base: String, + + // Schema-like info required for Aerogramme's logic 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, + // Storage related thing + pub storage: LdapStorage, } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/src/login/static_provider.rs b/src/login/static_provider.rs index b9be5a6..378a863 100644 --- a/src/login/static_provider.rs +++ b/src/login/static_provider.rs @@ -7,6 +7,7 @@ use async_trait::async_trait; use crate::config::*; use crate::cryptoblob::{Key, SecretKey}; use crate::login::*; +use crate::storage; pub struct StaticLoginProvider { default_bucket: Option, -- cgit v1.2.3