use actix_web::{App, HttpServer, web, get}; use clap::Parser; use basic_oidc::constants::{DEFAULT_ADMIN_PASSWORD, DEFAULT_ADMIN_USERNAME}; use basic_oidc::controllers::assets_controller::assets_route; use basic_oidc::data::app_config::AppConfig; use basic_oidc::data::entity_manager::EntityManager; use basic_oidc::data::user::{hash_password, User}; #[get("/health")] async fn health() -> &'static str { "Running" } #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); let config: AppConfig = AppConfig::parse(); if !config.storage_path().exists() { log::error!( "Specified storage path {:?} does not exists!", config.storage_path() ); panic!() } let mut users = EntityManager::::open_or_create(config.users_file()) .expect("Failed to load users list!"); // Create initial user if required if users.is_empty() { log::info!("Create default {} user", DEFAULT_ADMIN_USERNAME); let default_admin = User { username: DEFAULT_ADMIN_USERNAME.to_string(), password: hash_password(DEFAULT_ADMIN_PASSWORD).unwrap(), need_reset_password: true, authorized_services: None, admin: true, ..Default::default() }; users .insert(default_admin) .expect("Failed to create initial user!"); } log::info!("Server will listen on {}", config.listen_address); HttpServer::new(|| { App::new() .service(health) .route("/assets/{path:.*}", web::get().to(assets_route)) }) .bind(config.listen_address)? .run() .await }