WIP provider config

This commit is contained in:
Quentin 2023-11-17 18:46:22 +01:00
parent 16b38f3197
commit 36f4050a40
Signed by: quentin
GPG key ID: E9602264D639FF68
4 changed files with 17 additions and 25 deletions

View file

@ -46,6 +46,8 @@ pub struct LoginStaticUser {
pub master_key: Option<String>, pub master_key: Option<String>,
pub secret_key: Option<String>, pub secret_key: Option<String>,
pub storage: StaticStorage,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]

View file

@ -10,18 +10,13 @@ use crate::login::*;
use crate::storage; use crate::storage;
pub struct StaticLoginProvider { pub struct StaticLoginProvider {
default_bucket: Option<String>,
users: HashMap<String, Arc<LoginStaticUser>>, users: HashMap<String, Arc<LoginStaticUser>>,
users_by_email: HashMap<String, Arc<LoginStaticUser>>, users_by_email: HashMap<String, Arc<LoginStaticUser>>,
k2v_region: Region,
s3_region: Region,
} }
impl StaticLoginProvider { impl StaticLoginProvider {
pub fn new(config: LoginStaticConfig, k2v_region: Region, s3_region: Region) -> Result<Self> { pub fn new(config: LoginStaticConfig) -> Result<Self> {
let users = config let users = config
.users
.into_iter() .into_iter()
.map(|(k, v)| (k, Arc::new(v))) .map(|(k, v)| (k, Arc::new(v)))
.collect::<HashMap<_, _>>(); .collect::<HashMap<_, _>>();
@ -36,11 +31,8 @@ impl StaticLoginProvider {
} }
Ok(Self { Ok(Self {
default_bucket: config.default_bucket,
users, users,
users_by_email, users_by_email,
k2v_region,
s3_region,
}) })
} }
} }
@ -59,23 +51,30 @@ impl LoginProvider for StaticLoginProvider {
bail!("Wrong password"); bail!("Wrong password");
} }
/*
tracing::debug!(user=%username, "fetch bucket"); tracing::debug!(user=%username, "fetch bucket");
let bucket = user let bucket = user
.bucket .bucket
.clone() .clone()
.or_else(|| self.default_bucket.clone()) .or_else(|| self.default_bucket.clone())
.ok_or(anyhow!( .ok_or(anyhow!(
"No bucket configured and no default bucket specieid" "No bucket configured and no default bucket specified"
))?; ))?;*/
tracing::debug!(user=%username, "fetch keys"); tracing::debug!(user=%username, "fetch keys");
let storage = StorageCredentials { let storage: storage::Builders = match user.storage {
StaticStorage::InMemory => Box::new(storage::in_memory::FullMem {}),
StaticStorage::Garage(c) => Box::new(storage::garage::GrgCreds {}),
};
/*
StorageCredentials {
k2v_region: self.k2v_region.clone(), k2v_region: self.k2v_region.clone(),
s3_region: self.s3_region.clone(), s3_region: self.s3_region.clone(),
aws_access_key_id: user.aws_access_key_id.clone(), aws_access_key_id: user.aws_access_key_id.clone(),
aws_secret_access_key: user.aws_secret_access_key.clone(), aws_secret_access_key: user.aws_secret_access_key.clone(),
bucket, bucket,
}; };*/
let keys = match (&user.master_key, &user.secret_key) { let keys = match (&user.master_key, &user.secret_key) {
(Some(m), Some(s)) => { (Some(m), Some(s)) => {

View file

@ -61,18 +61,9 @@ impl Server {
} }
fn build(config: Config) -> Result<(ArcLoginProvider, Option<LmtpConfig>, Option<ImapConfig>)> { fn build(config: Config) -> Result<(ArcLoginProvider, Option<LmtpConfig>, Option<ImapConfig>)> {
let s3_region = Region {
name: config.aws_region.clone(),
endpoint: config.s3_endpoint,
};
let k2v_region = Region {
name: config.aws_region,
endpoint: config.k2v_endpoint,
};
let lp: ArcLoginProvider = match (config.login_static, config.login_ldap) { let lp: ArcLoginProvider = match (config.login_static, config.login_ldap) {
(Some(st), None) => Arc::new(StaticLoginProvider::new(st, k2v_region, s3_region)?), (Some(st), None) => Arc::new(StaticLoginProvider::new(st)?),
(None, Some(ld)) => Arc::new(LdapLoginProvider::new(ld, k2v_region, s3_region)?), (None, Some(ld)) => Arc::new(LdapLoginProvider::new(ld)?),
(Some(_), Some(_)) => { (Some(_), Some(_)) => {
bail!("A single login provider must be set up in config file") bail!("A single login provider must be set up in config file")
} }

View file

@ -30,7 +30,7 @@ impl IRowStore for MemStore {
} }
fn select(&self, selector: Selector) -> AsyncResult<Vec<RowValue>> { fn select(&self, selector: Selector) -> AsyncResult<Vec<RowValue>> {
unimplemented!(); unimplemented!()
} }
fn rm(&self, selector: Selector) -> AsyncResult<()> { fn rm(&self, selector: Selector) -> AsyncResult<()> {