mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
server: Improve startup error messages and fail fast
This commit is contained in:
parent
f026e7cd38
commit
eef3afd2e2
@ -4,6 +4,7 @@ use figment::{
|
|||||||
Figment,
|
Figment,
|
||||||
};
|
};
|
||||||
use lldap_auth::opaque::{server::ServerSetup, KeyPair};
|
use lldap_auth::opaque::{server::ServerSetup, KeyPair};
|
||||||
|
use log::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::infra::cli::RunOpts;
|
use crate::infra::cli::RunOpts;
|
||||||
@ -110,6 +111,8 @@ fn get_server_setup(file_path: &str) -> Result<ServerSetup> {
|
|||||||
pub fn init(cli_opts: RunOpts) -> Result<Configuration> {
|
pub fn init(cli_opts: RunOpts) -> Result<Configuration> {
|
||||||
let config_file = cli_opts.config_file.clone();
|
let config_file = cli_opts.config_file.clone();
|
||||||
|
|
||||||
|
info!("Loading configuration from {}", cli_opts.config_file);
|
||||||
|
|
||||||
let config: Configuration = Figment::from(Serialized::defaults(Configuration::default()))
|
let config: Configuration = Figment::from(Serialized::defaults(Configuration::default()))
|
||||||
.merge(Toml::file(config_file))
|
.merge(Toml::file(config_file))
|
||||||
.merge(Env::prefixed("LLDAP_"))
|
.merge(Env::prefixed("LLDAP_"))
|
||||||
|
@ -11,7 +11,7 @@ use crate::{
|
|||||||
infra::{cli::*, configuration::Configuration, db_cleaner::Scheduler},
|
infra::{cli::*, configuration::Configuration, db_cleaner::Scheduler},
|
||||||
};
|
};
|
||||||
use actix::Actor;
|
use actix::Actor;
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use futures_util::TryFutureExt;
|
use futures_util::TryFutureExt;
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|
||||||
@ -19,9 +19,11 @@ mod domain;
|
|||||||
mod infra;
|
mod infra;
|
||||||
|
|
||||||
async fn create_admin_user(handler: &SqlBackendHandler, config: &Configuration) -> Result<()> {
|
async fn create_admin_user(handler: &SqlBackendHandler, config: &Configuration) -> Result<()> {
|
||||||
if config.ldap_user_pass.len() < 8 {
|
assert!(
|
||||||
bail!("Minimum password length is 8 characters");
|
config.ldap_user_pass.len() >= 8,
|
||||||
}
|
"Minimum password length is 8 characters, got {} characters",
|
||||||
|
config.ldap_user_pass.len()
|
||||||
|
);
|
||||||
handler
|
handler
|
||||||
.create_user(CreateUserRequest {
|
.create_user(CreateUserRequest {
|
||||||
user_id: config.ldap_user_dn.clone(),
|
user_id: config.ldap_user_dn.clone(),
|
||||||
@ -48,9 +50,12 @@ async fn run_server(config: Configuration) -> Result<()> {
|
|||||||
.await?;
|
.await?;
|
||||||
domain::sql_tables::init_table(&sql_pool).await?;
|
domain::sql_tables::init_table(&sql_pool).await?;
|
||||||
let backend_handler = SqlBackendHandler::new(config.clone(), sql_pool.clone());
|
let backend_handler = SqlBackendHandler::new(config.clone(), sql_pool.clone());
|
||||||
|
if let Err(e) = backend_handler.get_user_details(&config.ldap_user_dn).await {
|
||||||
|
warn!("Could not get admin user, trying to create it: {:#}", e);
|
||||||
create_admin_user(&backend_handler, &config)
|
create_admin_user(&backend_handler, &config)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| warn!("Error setting up admin login/account: {}", e));
|
.map_err(|e| anyhow!("Error setting up admin login/account: {:#}", e))?;
|
||||||
|
}
|
||||||
let server_builder = infra::ldap_server::build_ldap_server(
|
let server_builder = infra::ldap_server::build_ldap_server(
|
||||||
&config,
|
&config,
|
||||||
backend_handler.clone(),
|
backend_handler.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user