2021-03-07 11:36:12 +00:00
|
|
|
use crate::infra::configuration::Configuration;
|
2021-03-02 19:51:33 +00:00
|
|
|
use anyhow::Result;
|
2021-03-07 11:36:12 +00:00
|
|
|
use futures_util::TryFutureExt;
|
2021-03-02 19:51:33 +00:00
|
|
|
use log::*;
|
2021-04-11 20:07:28 +00:00
|
|
|
use crate::domain::sql_tables::PoolOptions;
|
2021-03-02 19:51:33 +00:00
|
|
|
|
2021-03-11 09:14:15 +00:00
|
|
|
mod domain;
|
2021-03-02 19:13:58 +00:00
|
|
|
mod infra;
|
|
|
|
|
2021-03-07 11:36:12 +00:00
|
|
|
async fn run_server(config: Configuration) -> Result<()> {
|
2021-04-11 20:07:28 +00:00
|
|
|
let sql_pool = PoolOptions::new()
|
2021-03-07 15:13:50 +00:00
|
|
|
.max_connections(5)
|
2021-03-12 08:33:43 +00:00
|
|
|
.connect(&config.database_url)
|
2021-03-07 15:13:50 +00:00
|
|
|
.await?;
|
2021-03-12 16:01:04 +00:00
|
|
|
domain::sql_tables::init_table(&sql_pool).await?;
|
2021-03-11 09:14:15 +00:00
|
|
|
let backend_handler = domain::handler::SqlBackendHandler::new(config.clone(), sql_pool.clone());
|
2021-03-07 15:13:50 +00:00
|
|
|
let server_builder = infra::ldap_server::build_ldap_server(
|
|
|
|
&config,
|
2021-03-11 09:14:15 +00:00
|
|
|
backend_handler.clone(),
|
2021-03-07 15:13:50 +00:00
|
|
|
actix_server::Server::build(),
|
|
|
|
)?;
|
2021-03-11 09:14:15 +00:00
|
|
|
let server_builder =
|
|
|
|
infra::tcp_server::build_tcp_server(&config, backend_handler, server_builder)?;
|
2021-03-07 11:36:12 +00:00
|
|
|
server_builder.workers(1).run().await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-03-02 19:51:33 +00:00
|
|
|
fn main() -> Result<()> {
|
2021-03-02 19:13:58 +00:00
|
|
|
let cli_opts = infra::cli::init();
|
2021-03-02 19:51:33 +00:00
|
|
|
let config = infra::configuration::init(cli_opts.clone())?;
|
|
|
|
infra::logging::init(config.clone())?;
|
|
|
|
|
2021-03-02 21:03:58 +00:00
|
|
|
info!("Starting LLDAP....");
|
|
|
|
|
|
|
|
debug!("CLI: {:#?}", cli_opts);
|
|
|
|
debug!("Configuration: {:#?}", config);
|
2021-03-02 22:07:01 +00:00
|
|
|
|
2021-03-07 11:36:12 +00:00
|
|
|
actix::run(
|
|
|
|
run_server(config).unwrap_or_else(|e| error!("Could not bring up the servers: {:?}", e)),
|
|
|
|
)?;
|
2021-03-02 22:07:01 +00:00
|
|
|
|
2021-03-02 19:51:33 +00:00
|
|
|
info!("End.");
|
|
|
|
Ok(())
|
2021-03-02 11:45:30 +00:00
|
|
|
}
|