From 163f805454f906c16bef0aebc9bdb5be7a7760aa Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 03:58:59 +0100 Subject: move /admin/config handler to own module --- src/api/config.rs | 25 +++++++++++++++++++++++++ src/api/mod.rs | 21 +++------------------ 2 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 src/api/config.rs (limited to 'src/api') diff --git a/src/api/config.rs b/src/api/config.rs new file mode 100644 index 0000000..10a9f80 --- /dev/null +++ b/src/api/config.rs @@ -0,0 +1,25 @@ +//! `GET /admin/config`: the effective configuration, as `--print-config` prints it. + +use axum::{ + Json, + extract::{Query, State}, +}; +use serde_json::Value as JsonValue; + +use crate::state::AppState; + +#[derive(Debug, Default, serde::Deserialize)] +pub(crate) struct ConfigQuery { + /// Text with placeholders as it ends up, or as written. + #[serde(default)] + values: crate::config::Values, +} + +/// `GET /admin/config`: the effective configuration with each value's source; +/// imported values and secrets are left out. +pub(crate) async fn get_config( + State(state): State, + Query(query): Query, +) -> Json { + Json(state.config.get(query.values).clone()) +} diff --git a/src/api/mod.rs b/src/api/mod.rs index a777724..093ca6a 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -2,6 +2,7 @@ //! own are in `store`). pub(crate) mod auth; +mod config; #[cfg(feature = "dashboard")] mod dashboard; mod debug; @@ -15,7 +16,7 @@ mod store; use axum::{ Json, Router, body::Body, - extract::{Request, State}, + extract::Request, http::{ HeaderValue, StatusCode, header::{CONTENT_LENGTH, CONTENT_TYPE}, @@ -54,7 +55,7 @@ pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) -> ) .route("/admin/stats", get(stats::get_stats)) .route("/admin/document", get(document::get_document)) - .route("/admin/config", get(get_config)) + .route("/admin/config", get(config::get_config)) .merge(crate::remake::router::()); #[cfg(feature = "dashboard")] @@ -166,22 +167,6 @@ async fn openapi_spec() -> impl IntoResponse { ) } -#[derive(Debug, Default, serde::Deserialize)] -struct ConfigQuery { - /// Text with placeholders as it ends up, or as written. - #[serde(default)] - values: crate::config::Values, -} - -/// `GET /admin/config`: the effective configuration with each value's source; -/// imported values and secrets are left out. -async fn get_config( - State(state): State, - axum::extract::Query(query): axum::extract::Query, -) -> Json { - Json(state.config.get(query.values).clone()) -} - // --- shared helpers ---------------------------------------------------------- pub(crate) fn store_status(error: StoreError, context: &str) -> StatusCode { -- cgit v1.3.1