1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 5 #include "app.hpp" 6 #include "query.hpp" 7 #include "registries/privilege_registry.hpp" 8 #include "utils/chassis_utils.hpp" 9 10 #include <boost/url/format.hpp> 11 12 #include <memory> 13 #include <optional> 14 #include <string> 15 16 namespace redfish 17 { 18 19 inline void handleEnvironmentMetricsHead( 20 App& app, const crow::Request& req, 21 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22 const std::string& chassisId) 23 { 24 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 25 { 26 return; 27 } 28 29 auto respHandler = [asyncResp, chassisId]( 30 const std::optional<std::string>& validChassisPath) { 31 if (!validChassisPath) 32 { 33 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 34 return; 35 } 36 37 asyncResp->res.addHeader( 38 boost::beast::http::field::link, 39 "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby"); 40 }; 41 42 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, 43 std::move(respHandler)); 44 } 45 46 inline void handleEnvironmentMetricsGet( 47 App& app, const crow::Request& req, 48 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 49 const std::string& chassisId) 50 { 51 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 52 { 53 return; 54 } 55 56 auto respHandler = [asyncResp, chassisId]( 57 const std::optional<std::string>& validChassisPath) { 58 if (!validChassisPath) 59 { 60 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 61 return; 62 } 63 64 asyncResp->res.addHeader( 65 boost::beast::http::field::link, 66 "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby"); 67 asyncResp->res.jsonValue["@odata.type"] = 68 "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics"; 69 asyncResp->res.jsonValue["Name"] = "Chassis Environment Metrics"; 70 asyncResp->res.jsonValue["Id"] = "EnvironmentMetrics"; 71 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 72 "/redfish/v1/Chassis/{}/EnvironmentMetrics", chassisId); 73 }; 74 75 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, 76 std::move(respHandler)); 77 } 78 79 inline void requestRoutesEnvironmentMetrics(App& app) 80 { 81 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/") 82 .privileges(redfish::privileges::headEnvironmentMetrics) 83 .methods(boost::beast::http::verb::head)( 84 std::bind_front(handleEnvironmentMetricsHead, std::ref(app))); 85 86 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/") 87 .privileges(redfish::privileges::getEnvironmentMetrics) 88 .methods(boost::beast::http::verb::get)( 89 std::bind_front(handleEnvironmentMetricsGet, std::ref(app))); 90 } 91 92 } // namespace redfish 93