Skip to main content

hypercall_admin/monitoring/
env.rs

1//! Backend runtime configuration admin endpoint.
2
3use axum::{
4    extract::State,
5    http::StatusCode,
6    response::{IntoResponse, Response},
7};
8use serde::Serialize;
9
10use crate::state::AdminState;
11use hypercall_runtime_api::sonic_json::SonicJson;
12
13/// Response for /monitoring/env endpoint
14#[derive(Debug, Serialize, utoipa::ToSchema)]
15pub struct EnvConfigResponse {
16    /// Server boot ID (UUID generated at startup)
17    pub boot_id: String,
18    /// Database host (safe portion only)
19    pub db_host: String,
20    /// Database name
21    pub db_name: String,
22    /// Server start time (ISO 8601)
23    pub server_started_at: String,
24    /// Current time (ISO 8601)
25    pub current_time: String,
26}
27
28/// GET /monitoring/env - Show backend runtime configuration for debugging
29///
30/// Returns parsed configuration values so misconfigurations are obvious.
31/// Does not expose secrets (passwords, API keys).
32#[utoipa::path(
33    get,
34    path = "/monitoring/env",
35    tag = "monitoring",
36    responses(
37        (status = 200, description = "Environment configuration", body = EnvConfigResponse)
38    ),
39    security(
40        ("admin_key" = [])
41    )
42)]
43pub async fn get_monitoring_env(State(state): State<AdminState>) -> Response {
44    let response = EnvConfigResponse {
45        boot_id: state.boot_id.clone(),
46        db_host: state.runtime_config.db_host.clone(),
47        db_name: state.runtime_config.db_name.clone(),
48        server_started_at: state.server_started_at.to_rfc3339(),
49        current_time: chrono::Utc::now().to_rfc3339(),
50    };
51
52    (StatusCode::OK, SonicJson(response)).into_response()
53}