integrate storage choice in config

This commit is contained in:
Quentin 2023-11-17 16:42:25 +01:00
parent 89cb8d9572
commit 16b38f3197
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 41 additions and 19 deletions

View file

@ -8,10 +8,6 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Config { pub struct Config {
pub s3_endpoint: String,
pub k2v_endpoint: String,
pub aws_region: String,
pub login_static: Option<LoginStaticConfig>, pub login_static: Option<LoginStaticConfig>,
pub login_ldap: Option<LoginLdapConfig>, pub login_ldap: Option<LoginLdapConfig>,
@ -19,10 +15,23 @@ pub struct Config {
pub imap: Option<ImapConfig>, pub imap: Option<ImapConfig>,
} }
pub type LoginStaticConfig = HashMap<String, LoginStaticUser>;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LoginStaticConfig { pub enum StaticStorage {
pub default_bucket: Option<String>, Garage(StaticGarageConfig),
pub users: HashMap<String, LoginStaticUser>, InMemory,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
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<String>,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
@ -31,10 +40,6 @@ pub struct LoginStaticUser {
pub email_addresses: Vec<String>, pub email_addresses: Vec<String>,
pub password: String, pub password: String,
pub aws_access_key_id: String,
pub aws_secret_access_key: String,
pub bucket: Option<String>,
pub user_secret: String, pub user_secret: String,
#[serde(default)] #[serde(default)]
pub alternate_user_secrets: Vec<String>, pub alternate_user_secrets: Vec<String>,
@ -44,26 +49,42 @@ pub struct LoginStaticUser {
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LoginLdapConfig { pub enum LdapStorage {
pub ldap_server: String, 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<String>,
pub default_bucket: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LoginLdapConfig {
// LDAP connection info
pub ldap_server: String,
#[serde(default)] #[serde(default)]
pub pre_bind_on_login: bool, pub pre_bind_on_login: bool,
pub bind_dn: Option<String>, pub bind_dn: Option<String>,
pub bind_password: Option<String>, pub bind_password: Option<String>,
pub search_base: String, pub search_base: String,
// Schema-like info required for Aerogramme's logic
pub username_attr: String, pub username_attr: String,
#[serde(default = "default_mail_attr")] #[serde(default = "default_mail_attr")]
pub mail_attr: String, pub mail_attr: String,
pub aws_access_key_id_attr: String,
pub aws_secret_access_key_attr: String,
pub user_secret_attr: String, pub user_secret_attr: String,
pub alternate_user_secrets_attr: Option<String>, pub alternate_user_secrets_attr: Option<String>,
pub bucket: Option<String>, // Storage related thing
pub bucket_attr: Option<String>, pub storage: LdapStorage,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]

View file

@ -7,6 +7,7 @@ use async_trait::async_trait;
use crate::config::*; use crate::config::*;
use crate::cryptoblob::{Key, SecretKey}; use crate::cryptoblob::{Key, SecretKey};
use crate::login::*; use crate::login::*;
use crate::storage;
pub struct StaticLoginProvider { pub struct StaticLoginProvider {
default_bucket: Option<String>, default_bucket: Option<String>,