use std::collections::HashMap; use std::net::SocketAddr; use std::sync::{Arc}; use tokio::sync::Mutex; use axum::Router; use axum::routing::{get, post}; use openidconnect::core::CoreClient; pub mod model; mod config; mod error; mod handlers; mod util; use crate::util::powerdns::PowerDnsApi; #[derive(Clone)] pub struct AppState { oidc_client: CoreClient, pdns_client: PowerDnsApi, state: Arc>>, } #[tokio::main] async fn main() { let config = config::PowerDnsTsigKeyManagerConfig::load("config.yaml") .expect("Unable to load and parse config.yaml"); let oidc_client = util::openid::create_client( config.oidc.issuer, config.oidc.client_id, config.oidc.client_secret, config.oidc.callback, ).await; let pdns_client = util::powerdns::PowerDnsApi::new( config.powerdns.server_url, config.powerdns.server_api_key, config.powerdns.server_id, ).await; let state: HashMap = HashMap::new(); let app_state = AppState { oidc_client, pdns_client, state: Arc::new(Mutex::new(state)), }; let app = Router::new() .route("/user/home", get(handlers::user::home)) .route("/openid/login", get(handlers::openid::login)) .route("/openid/callback", get(handlers::openid::callback)) .route("/api/tsigkey/list", get(handlers::api::list)) .route("/api/tsigkey/:tsig_key_name", get(handlers::api::get).delete(handlers::api::delete)) .route("/api/tsigkey/", post(handlers::api::add).put(handlers::api::add)) .route("/", get(handlers::app::home)) .with_state(app_state); let socket_addr: SocketAddr = (config.server.bind_address, config.server.port).into(); let listener = tokio::net::TcpListener::bind(socket_addr).await.unwrap(); axum::serve::serve(listener, app).await.unwrap(); }