manta_server/service/
redfish.rs1use manta_backend_dispatcher::error::Error;
15use manta_backend_dispatcher::interfaces::hsm::redfish_endpoint::RedfishEndpointTrait;
16use manta_backend_dispatcher::types::hsm::inventory::{
17 RedfishEndpoint, RedfishEndpointArray,
18};
19
20use crate::{
21 server::common::app_context::InfraContext,
22 service::authorization::{is_admin, validate_user_group_members_access},
23};
24pub use manta_shared::types::api::redfish_endpoints::{
25 GetRedfishEndpointsParams, UpdateRedfishEndpointParams,
26};
27
28pub(crate) fn params_to_redfish_endpoint(
32 params: UpdateRedfishEndpointParams,
33) -> RedfishEndpoint {
34 RedfishEndpoint {
35 id: params.id,
36 name: params.name,
37 hostname: params.hostname,
38 domain: params.domain,
39 fqdn: params.fqdn,
40 enabled: Some(params.enabled),
41 user: params.user,
42 password: params.password,
43 use_ssdp: Some(params.use_ssdp),
44 mac_required: Some(params.mac_required),
45 mac_addr: params.mac_addr,
46 ip_address: params.ip_address,
47 rediscover_on_update: Some(params.rediscover_on_update),
48 template_id: params.template_id,
49 r#type: None,
50 uuid: None,
51 discovery_info: None,
52 }
53}
54
55pub async fn get_redfish_endpoints(
73 infra: &InfraContext<'_>,
74 token: &str,
75 params: &GetRedfishEndpointsParams,
76) -> Result<RedfishEndpointArray, Error> {
77 tracing::info!("Get Redfish endpoints");
78
79 if !is_admin(token) {
80 let Some(xname) = params.id.as_deref() else {
81 return Err(Error::BadRequest(
82 "Non-admin callers must scope a Redfish-endpoints query by `id`."
83 .to_string(),
84 ));
85 };
86 validate_user_group_members_access(infra, token, &[xname.to_string()])
87 .await?;
88 }
89
90 infra
91 .backend
92 .get_redfish_endpoints(
93 token,
94 params.id.as_deref(),
95 params.fqdn.as_deref(),
96 None,
97 params.uuid.as_deref(),
98 params.macaddr.as_deref(),
99 params.ipaddress.as_deref(),
100 None,
101 )
102 .await
103}
104
105pub async fn add_redfish_endpoint(
118 infra: &InfraContext<'_>,
119 token: &str,
120 params: UpdateRedfishEndpointParams,
121) -> Result<(), Error> {
122 tracing::info!("Add Redfish endpoint id={}", params.id);
123
124 validate_user_group_members_access(
125 infra,
126 token,
127 std::slice::from_ref(¶ms.id),
128 )
129 .await?;
130
131 let endpoint = params_to_redfish_endpoint(params);
132 let array = RedfishEndpointArray {
133 redfish_endpoints: Some(vec![endpoint]),
134 };
135 infra.backend.add_redfish_endpoint(token, &array).await
136}
137
138pub async fn update_redfish_endpoint(
149 infra: &InfraContext<'_>,
150 token: &str,
151 params: UpdateRedfishEndpointParams,
152) -> Result<(), Error> {
153 tracing::info!("Update Redfish endpoint id={}", params.id);
154
155 validate_user_group_members_access(
156 infra,
157 token,
158 std::slice::from_ref(¶ms.id),
159 )
160 .await?;
161
162 let endpoint = params_to_redfish_endpoint(params);
163 infra
164 .backend
165 .update_redfish_endpoint(token, &endpoint)
166 .await
167}
168
169pub async fn delete_redfish_endpoint(
180 infra: &InfraContext<'_>,
181 token: &str,
182 id: &str,
183) -> Result<(), Error> {
184 tracing::info!("Delete Redfish endpoint id={}", id);
185
186 validate_user_group_members_access(infra, token, &[id.to_string()]).await?;
187
188 infra
189 .backend
190 .delete_redfish_endpoint(token, id)
191 .await
192 .map(|_| ())
193}