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