manta_server/server/handlers/
redfish_endpoints.rs

1//! Redfish-endpoints CRUD handlers.
2
3use axum::{
4  Json,
5  extract::{Path, Query},
6  http::StatusCode,
7  response::IntoResponse,
8};
9
10use super::{ErrorResponse, RequestCtx, SiteHeader, to_handler_error};
11use crate::service;
12use manta_shared::types::api::redfish_endpoints::{
13  GetRedfishEndpointsParams, UpdateRedfishEndpointParams,
14};
15
16// ---------------------------------------------------------------------------
17// GET /api/v1/redfish-endpoints
18// ---------------------------------------------------------------------------
19
20pub use manta_shared::types::api::queries::RedfishEndpointsQuery;
21
22/// GET /redfish-endpoints — list HSM Redfish endpoints with optional filters.
23#[utoipa::path(get, path = "/redfish-endpoints", tag = "redfish-endpoints",
24  params(RedfishEndpointsQuery, SiteHeader),
25  security(("bearerAuth" = [])),
26  responses(
27    // RedfishEndpointArray lives in manta-backend-dispatcher (third-party,
28    // no ToSchema) — kept as Value until upstream derives it.
29    (status = 200, description = "List of Redfish endpoints", 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_redfish_endpoints(
36  ctx: RequestCtx,
37  Query(q): Query<RedfishEndpointsQuery>,
38) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
39  let infra = ctx.infra();
40
41  let params = GetRedfishEndpointsParams {
42    id: q.id,
43    fqdn: q.fqdn,
44    uuid: q.uuid,
45    macaddr: q.macaddr,
46    ipaddress: q.ipaddress,
47  };
48
49  let endpoints =
50    service::redfish::get_redfish_endpoints(&infra, &ctx.token, &params)
51      .await
52      .map_err(to_handler_error)?;
53
54  Ok(Json(endpoints))
55}
56
57// ---------------------------------------------------------------------------
58// DELETE /api/v1/redfish-endpoints/{id}
59// ---------------------------------------------------------------------------
60
61/// DELETE /redfish-endpoints/{id} — remove a Redfish endpoint from HSM.
62#[utoipa::path(delete, path = "/redfish-endpoints/{id}", tag = "redfish-endpoints",
63  params(("id" = String, Path, description = "BMC xname"), SiteHeader),
64  security(("bearerAuth" = [])),
65  responses(
66    (status = 204, description = "Endpoint removed"),
67    (status = 401, description = "Unauthorized",   body = ErrorResponse),
68    (status = 404, description = "Not found",      body = ErrorResponse),
69    (status = 500, description = "Internal error", body = ErrorResponse),
70  )
71)]
72#[tracing::instrument(skip_all)]
73pub async fn delete_redfish_endpoint(
74  ctx: RequestCtx,
75  Path(id): Path<String>,
76) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
77  tracing::info!("delete_redfish_endpoint id={}", id);
78  let infra = ctx.infra();
79
80  service::redfish::delete_redfish_endpoint(&infra, &ctx.token, &id)
81    .await
82    .map_err(to_handler_error)?;
83
84  Ok(StatusCode::NO_CONTENT)
85}
86
87// ---------------------------------------------------------------------------
88// POST /api/v1/redfish-endpoints
89// ---------------------------------------------------------------------------
90
91/// POST /redfish-endpoints — register a new Redfish endpoint in HSM.
92#[utoipa::path(post, path = "/redfish-endpoints", tag = "redfish-endpoints",
93  params(SiteHeader),
94  request_body = UpdateRedfishEndpointParams,
95  security(("bearerAuth" = [])),
96  responses(
97    (status = 201, description = "Endpoint registered",  body = manta_shared::types::api::responses::CreatedResponse),
98    (status = 401, description = "Unauthorized",          body = ErrorResponse),
99    (status = 500, description = "Internal error",        body = ErrorResponse),
100  )
101)]
102#[tracing::instrument(skip_all)]
103pub async fn add_redfish_endpoint(
104  ctx: RequestCtx,
105  Json(params): Json<UpdateRedfishEndpointParams>,
106) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
107  tracing::info!("add_redfish_endpoint");
108  let infra = ctx.infra();
109
110  service::redfish::add_redfish_endpoint(&infra, &ctx.token, params)
111    .await
112    .map_err(to_handler_error)?;
113
114  Ok((
115    StatusCode::CREATED,
116    Json(serde_json::json!({ "created": true })),
117  ))
118}
119
120// ---------------------------------------------------------------------------
121// PUT /api/v1/redfish-endpoints
122// ---------------------------------------------------------------------------
123
124/// PUT /redfish-endpoints — update an existing Redfish endpoint's properties.
125#[utoipa::path(put, path = "/redfish-endpoints", tag = "redfish-endpoints",
126  params(SiteHeader),
127  request_body = UpdateRedfishEndpointParams,
128  security(("bearerAuth" = [])),
129  responses(
130    (status = 204, description = "Endpoint updated"),
131    (status = 401, description = "Unauthorized",   body = ErrorResponse),
132    (status = 500, description = "Internal error", body = ErrorResponse),
133  )
134)]
135#[tracing::instrument(skip_all)]
136pub async fn update_redfish_endpoint(
137  ctx: RequestCtx,
138  Json(params): Json<UpdateRedfishEndpointParams>,
139) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
140  tracing::info!("update_redfish_endpoint");
141  let infra = ctx.infra();
142
143  service::redfish::update_redfish_endpoint(&infra, &ctx.token, params)
144    .await
145    .map_err(to_handler_error)?;
146
147  Ok(StatusCode::NO_CONTENT)
148}