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