From 13e5a6e18c6465e24a4f06ce96a3321d39f1952d Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Feb 2024 13:35:51 +0000 Subject: [PATCH] Create state structs --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7846794..f65bbb1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,11 +25,14 @@ mod db; mod secrets; mod server; -use std::path::Path; +use std::sync::Arc; +use auth::{ServerPadlockGenerator, UserAuthenticator, UserServerKeyGenerator}; use clap::Parser; use color_eyre::Result; use config::Config; +use db::SqliteDatabase; +use tokio::sync::Mutex; use tracing::{event, instrument, Level}; use tracing_error::ErrorLayer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; @@ -77,6 +80,17 @@ async fn main() -> Result<()> { let config = load_config(&args.config).await?; + let database = Arc::new(Mutex::new( + SqliteDatabase::open(&config.database.connection_string).await, + )); + + let user_authenticator = Arc::new(UserAuthenticator::new(database)); + let padlock_generator = Arc::new(ServerPadlockGenerator::new(config.padlock_secret)); + let user_server_key_generator = Arc::new(UserServerKeyGenerator::new( + Arc::clone(&user_authenticator), + Arc::clone(&padlock_generator), + )); + tokio::spawn(server::run(config.port)).await??; Ok(())