feat: Start dummy in-memory database
This commit is contained in:
parent
1ef02c58dd
commit
bdb5008914
9 changed files with 181 additions and 3 deletions
21
src/main.rs
21
src/main.rs
|
|
@ -1,16 +1,31 @@
|
|||
// #![deny(warnings)]
|
||||
|
||||
mod cli;
|
||||
mod db;
|
||||
mod error;
|
||||
mod ldap;
|
||||
mod listener;
|
||||
mod stream;
|
||||
|
||||
use cli::CliArgs;
|
||||
use db::{Database, DatabaseInterface, MemoryDatabase, User};
|
||||
use error::GlobalError;
|
||||
use ldap::ldap_handler;
|
||||
use listener::ListenerPath;
|
||||
|
||||
async fn create_dummy_users<D: DatabaseInterface>(db: &mut Database<D>) {
|
||||
for domain in &["a", "b", "c"] {
|
||||
db.create_user(User {
|
||||
username: domain.to_string(),
|
||||
domain: format!("{domain}.localhost"),
|
||||
password: "adminadmin".to_string(),
|
||||
mail: format!("{domain}@{domain}.localhost"),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> Result<(), GlobalError> {
|
||||
let cli: CliArgs = argh::from_env();
|
||||
|
|
@ -25,10 +40,14 @@ async fn main() -> Result<(), GlobalError> {
|
|||
|
||||
let listener = ListenerPath::new(&cli.listen)?.listener().await?;
|
||||
|
||||
let mut db = MemoryDatabase::new();
|
||||
create_dummy_users(&mut db).await;
|
||||
|
||||
// If the connection is None, it's because the client aborted early
|
||||
// so there's nothing to do about it.
|
||||
while let Some(stream) = listener.accept_ldap().await? {
|
||||
tokio::spawn(ldap_handler(stream));
|
||||
let db = db.clone();
|
||||
tokio::spawn(ldap_handler(stream, db));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue