Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
Directories, Directory, UnavailableDirectory,
|
||||
backend::{ldap::LdapDirectory, oidc::OpenIdDirectory, sql::SqlDirectory},
|
||||
};
|
||||
use registry::schema::{
|
||||
prelude::ObjectType,
|
||||
structs::{self, Authentication},
|
||||
};
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use store::registry::bootstrap::Bootstrap;
|
||||
|
||||
impl Directories {
|
||||
pub async fn build(bp: &mut Bootstrap) -> Self {
|
||||
let mut directories = HashMap::default();
|
||||
|
||||
for directory in bp.list_infallible::<structs::Directory>().await {
|
||||
let id = directory.id;
|
||||
let directory_type = directory.object.object_type();
|
||||
let result = match directory.object {
|
||||
structs::Directory::Ldap(directory) => LdapDirectory::open(directory).await,
|
||||
structs::Directory::Sql(directory) => {
|
||||
SqlDirectory::open(directory, &bp.data_store).await
|
||||
}
|
||||
structs::Directory::Oidc(directory) => OpenIdDirectory::open(directory).await,
|
||||
};
|
||||
|
||||
let directory = match result {
|
||||
Ok(directory) => directory,
|
||||
Err(err) => {
|
||||
bp.build_error(id, err.clone());
|
||||
Directory::Unavailable(UnavailableDirectory::new(directory_type, err))
|
||||
}
|
||||
};
|
||||
directories.insert(id.id().id() as u32, Arc::new(directory));
|
||||
}
|
||||
|
||||
let auth = bp.setting_infallible::<Authentication>().await;
|
||||
let default_directory = if let Some(directory_id) = auth.directory_id {
|
||||
match directories.get(&(directory_id.id() as u32)) {
|
||||
Some(default_directory) => default_directory.clone().into(),
|
||||
None => {
|
||||
bp.build_error(
|
||||
ObjectType::Authentication.singleton(),
|
||||
format!("Default directory with ID {} not found", directory_id),
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Directories {
|
||||
default_directory,
|
||||
directories,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user