1 #pragma once
2 
3 #include "app.hpp"
4 #include "error_messages.hpp"
5 #include "http_request.hpp"
6 #include "http_response.hpp"
7 #include "query.hpp"
8 #include "registries/privilege_registry.hpp"
9 
10 #include <nlohmann/json.hpp>
11 
12 #include <functional>
13 #include <memory>
14 
15 namespace redfish
16 {
17 
18 inline void handleAggregationServiceHead(
19     App& app, const crow::Request& req,
20     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
21 {
22     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
23     {
24         return;
25     }
26     asyncResp->res.addHeader(
27         boost::beast::http::field::link,
28         "</redfish/v1/JsonSchemas/AggregationService/AggregationService.json>; rel=describedby");
29 }
30 
31 inline void handleAggregationServiceGet(
32     App& app, const crow::Request& req,
33     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
34 {
35     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
36     {
37         return;
38     }
39     asyncResp->res.addHeader(
40         boost::beast::http::field::link,
41         "</redfish/v1/JsonSchemas/AggregationService/AggregationService.json>; rel=describedby");
42     nlohmann::json& json = asyncResp->res.jsonValue;
43     json["@odata.id"] = "/redfish/v1/AggregationService";
44     json["@odata.type"] = "#AggregationService.v1_0_1.AggregationService";
45     json["Id"] = "AggregationService";
46     json["Name"] = "Aggregation Service";
47     json["Description"] = "Aggregation Service";
48     json["ServiceEnabled"] = true;
49     json["AggregationSources"]["@odata.id"] =
50         "/redfish/v1/AggregationService/AggregationSources";
51 }
52 
53 inline void requestAggregationServiceRoutes(App& app)
54 {
55     BMCWEB_ROUTE(app, "/redfish/v1/AggregationService/")
56         .privileges(redfish::privileges::headAggregationService)
57         .methods(boost::beast::http::verb::head)(
58             std::bind_front(handleAggregationServiceHead, std::ref(app)));
59     BMCWEB_ROUTE(app, "/redfish/v1/AggregationService/")
60         .privileges(redfish::privileges::getAggregationService)
61         .methods(boost::beast::http::verb::get)(
62             std::bind_front(handleAggregationServiceGet, std::ref(app)));
63 }
64 
65 inline void handleAggregationSourcesGet(
66     App& app, const crow::Request& req,
67     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
68 {
69     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
70     {
71         return;
72     }
73     asyncResp->res.addHeader(
74         boost::beast::http::field::link,
75         "</redfish/v1/JsonSchemas/AggregationSourceCollection/AggregationSourceCollection.json>; rel=describedby");
76     nlohmann::json& json = asyncResp->res.jsonValue;
77     json["@odata.id"] = "/redfish/v1/AggregationService/AggregationSources";
78     json["@odata.type"] =
79         "#AggregationSourceCollection.AggregationSourceCollection";
80     json["Name"] = "Aggregation Source Collection";
81     json["Members"] = nlohmann::json::array();
82     json["Members@odata.count"] = 0;
83 
84     // TODO: Query D-Bus for satellite configs and add them to the Members array
85 }
86 
87 inline void requestAggregationSourcesRoutes(App& app)
88 {
89     BMCWEB_ROUTE(app, "/redfish/v1/AggregationService/AggregationSources/")
90         .privileges(redfish::privileges::getAggregationService)
91         .methods(boost::beast::http::verb::get)(
92             std::bind_front(handleAggregationSourcesGet, std::ref(app)));
93 }
94 
95 } // namespace redfish
96