manta_server/server/handlers/
cluster.rs

1//! GET /api/v1/groups/nodes (canonical) and /clusters (deprecated alias).
2
3use axum::{Json, extract::Query, http::StatusCode, response::IntoResponse};
4use serde::Deserialize;
5use utoipa::IntoParams;
6
7use super::{ErrorResponse, RequestCtx, SiteHeader, to_handler_error};
8use crate::service;
9
10// ---------------------------------------------------------------------------
11// GET /api/v1/groups/nodes
12// ---------------------------------------------------------------------------
13
14/// Query parameters for `GET /groups/nodes`.
15#[derive(Deserialize, IntoParams)]
16pub struct ClusterQuery {
17  /// HSM group name to list nodes for. When omitted the response covers
18  /// every group the bearer token can access.
19  pub hsm_group: Option<String>,
20  /// Optional power-status filter (e.g. `ON`, `OFF`, `READY`).
21  pub status: Option<String>,
22}
23
24/// GET /groups/nodes — list nodes in a group with optional status filter.
25#[utoipa::path(get, path = "/groups/nodes", tag = "groups",
26  params(ClusterQuery, SiteHeader),
27  security(("bearerAuth" = [])),
28  responses(
29    (status = 200, description = "List of group nodes", body = serde_json::Value),
30    (status = 401, description = "Unauthorized",         body = ErrorResponse),
31    (status = 500, description = "Internal error",       body = ErrorResponse),
32  )
33)]
34#[tracing::instrument(skip_all)]
35pub async fn get_groups_nodes(
36  ctx: RequestCtx,
37  Query(q): Query<ClusterQuery>,
38) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
39  let infra = ctx.infra();
40
41  let params = service::cluster::GetClusterParams {
42    hsm_group_name: q.hsm_group,
43    settings_hsm_group_name: None,
44    status_filter: q.status,
45  };
46
47  let nodes = service::cluster::get_cluster_nodes(&infra, &ctx.token, &params)
48    .await
49    .map_err(to_handler_error)?;
50
51  Ok(Json(nodes))
52}
53
54/// DEPRECATED alias for `GET /clusters`. Logs a server-side warning,
55/// then delegates to the canonical handler. Old path kept for one
56/// release.
57#[utoipa::path(get, path = "/clusters", tag = "clusters",
58  params(ClusterQuery, SiteHeader),
59  security(("bearerAuth" = [])),
60  responses(
61    (status = 200, description = "[DEPRECATED] use /groups/nodes — list of group nodes", body = serde_json::Value),
62    (status = 401, description = "Unauthorized",                                          body = ErrorResponse),
63    (status = 500, description = "Internal error",                                        body = ErrorResponse),
64  )
65)]
66#[tracing::instrument(skip_all)]
67pub async fn get_clusters_deprecated(
68  ctx: RequestCtx,
69  q: Query<ClusterQuery>,
70) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
71  tracing::warn!(
72    "deprecated endpoint: GET /clusters — use /groups/nodes instead"
73  );
74  get_groups_nodes(ctx, q).await
75}