use actix_web::{HttpRequest, HttpResponse, get, web};
use serde_json::json;
use athena_control_plane::DaemonRegistryService;
use crate::AppState;
use crate::api::auth::authorize_static_admin_key;
use crate::api::client_context::logging_pool;
use crate::api::response::{api_success, internal_error};
use crate::runtime::runtime_binary_catalog;
#[get("/admin/daemons")]
pub async fn admin_list_daemons(req: HttpRequest, state: web::Data<AppState>) -> HttpResponse {
if let Err(resp) = authorize_static_admin_key(&req) {
return resp;
}
let pool = match logging_pool(state.get_ref()) {
Ok(pool) => pool,
Err(resp) => return resp,
};
let service = DaemonRegistryService::new(pool);
let daemons = match service.list_inventory().await {
Ok(rows) => rows,
Err(err) => return internal_error("Failed to load daemon inventory", err.to_string()),
};
api_success("Listed daemon inventory", json!({ "daemons": daemons }))
}
#[get("/admin/daemons/catalog")]
pub async fn admin_list_daemon_runtime_catalog(req: HttpRequest) -> HttpResponse {
if let Err(resp) = authorize_static_admin_key(&req) {
return resp;
}
api_success(
"Listed daemon runtime catalog",
json!({ "runtimes": runtime_binary_catalog() }),
)
}
pub fn services(cfg: &mut web::ServiceConfig) {
cfg.service(admin_list_daemon_runtime_catalog)
.service(admin_list_daemons);
}