Create state structs

This commit is contained in:
Xiretza 2024-02-10 13:35:51 +00:00
parent 5772c26537
commit 13e5a6e18c

View file

@ -25,11 +25,14 @@ mod db;
mod secrets; mod secrets;
mod server; mod server;
use std::path::Path; use std::sync::Arc;
use auth::{ServerPadlockGenerator, UserAuthenticator, UserServerKeyGenerator};
use clap::Parser; use clap::Parser;
use color_eyre::Result; use color_eyre::Result;
use config::Config; use config::Config;
use db::SqliteDatabase;
use tokio::sync::Mutex;
use tracing::{event, instrument, Level}; use tracing::{event, instrument, Level};
use tracing_error::ErrorLayer; use tracing_error::ErrorLayer;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
@ -77,6 +80,17 @@ async fn main() -> Result<()> {
let config = load_config(&args.config).await?; 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??; tokio::spawn(server::run(config.port)).await??;
Ok(()) Ok(())