manta_server/server/handlers/
runtime_configuration.rs1use axum::{Json, http::StatusCode, response::IntoResponse};
9
10use super::{ErrorResponse, RequestCtx, SiteHeader, to_handler_error};
11use crate::service;
12
13pub use manta_shared::types::api::runtime_configuration::ApplyRuntimeConfigurationRequest;
14
15#[utoipa::path(put, path = "/runtime-configuration", tag = "runtime-configuration",
18 params(SiteHeader),
19 request_body = ApplyRuntimeConfigurationRequest,
20 security(("bearerAuth" = [])),
21 responses(
22 (status = 200, description = "Runtime configuration applied", body = serde_json::Value),
23 (status = 400, description = "Bad request", body = ErrorResponse),
24 (status = 401, description = "Unauthorized", body = ErrorResponse),
25 (status = 403, description = "Forbidden", body = ErrorResponse),
26 (status = 404, description = "Not found", body = ErrorResponse),
27 (status = 500, description = "Internal error", body = ErrorResponse),
28 )
29)]
30#[tracing::instrument(skip_all)]
31pub async fn apply_runtime_configuration(
32 ctx: RequestCtx,
33 Json(body): Json<ApplyRuntimeConfigurationRequest>,
34) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
35 tracing::info!(
36 "apply_runtime_configuration cfs_configuration_name={} hosts={} enabled={} dry_run={}",
37 body.cfs_configuration_name,
38 body.hosts_expression,
39 body.enabled,
40 body.dry_run
41 );
42 let infra = ctx.infra();
43
44 let xnames = service::runtime_configuration::apply_runtime_configuration(
45 &infra,
46 &ctx.token,
47 &body.cfs_configuration_name,
48 &body.hosts_expression,
49 body.enabled,
50 body.dry_run,
51 )
52 .await
53 .map_err(to_handler_error)?;
54
55 Ok((
56 StatusCode::OK,
57 Json(serde_json::json!({
58 "dry_run": body.dry_run,
59 "cfs_configuration_name": body.cfs_configuration_name,
60 "enabled": body.enabled,
61 "nodes": xnames,
62 })),
63 ))
64}