xref: /openbmc/bmcweb/redfish-core/lib/service_root.hpp (revision 3132dacead062fa63c070fc7f404f8cf93df43a0)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
4 #pragma once
5 
6 #include "bmcweb_config.h"
7 
8 #include "app.hpp"
9 #include "async_resp.hpp"
10 #include "http_request.hpp"
11 #include "persistent_data.hpp"
12 #include "query.hpp"
13 #include "registries/privilege_registry.hpp"
14 #include "utils/manager_utils.hpp"
15 
16 #include <boost/beast/http/field.hpp>
17 #include <boost/beast/http/verb.hpp>
18 #include <boost/url/format.hpp>
19 #include <nlohmann/json.hpp>
20 
21 #include <functional>
22 #include <memory>
23 #include <string>
24 
25 namespace redfish
26 {
27 
handleServiceRootHead(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)28 inline void handleServiceRootHead(
29     App& app, const crow::Request& req,
30     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
31 {
32     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
33     {
34         return;
35     }
36 
37     asyncResp->res.addHeader(
38         boost::beast::http::field::link,
39         "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
40 }
41 
handleServiceRootGetImpl(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)42 inline void handleServiceRootGetImpl(
43     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
44 {
45     asyncResp->res.addHeader(
46         boost::beast::http::field::link,
47         "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
48 
49     std::string uuid = persistent_data::getConfig().systemUuid;
50     asyncResp->res.jsonValue["@odata.type"] =
51         "#ServiceRoot.v1_15_0.ServiceRoot";
52     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
53     asyncResp->res.jsonValue["Id"] = "RootService";
54     asyncResp->res.jsonValue["Name"] = "Root Service";
55     asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0";
56     asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
57         "/redfish/v1/SessionService/Sessions";
58     asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
59         "/redfish/v1/AccountService";
60     if constexpr (BMCWEB_REDFISH_AGGREGATION)
61     {
62         asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
63             "/redfish/v1/AggregationService";
64     }
65     asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
66     asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
67         "/redfish/v1/JsonSchemas";
68     asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
69     asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
70         "/redfish/v1/SessionService";
71     asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
72     asyncResp->res.jsonValue["Fabrics"]["@odata.id"] = "/redfish/v1/Fabrics";
73     asyncResp->res.jsonValue["Registries"]["@odata.id"] =
74         "/redfish/v1/Registries";
75     asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
76         "/redfish/v1/UpdateService";
77     asyncResp->res.jsonValue["UUID"] = uuid;
78     asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
79         "/redfish/v1/CertificateService";
80     asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
81     asyncResp->res.jsonValue["EventService"]["@odata.id"] =
82         "/redfish/v1/EventService";
83     asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
84         "/redfish/v1/TelemetryService";
85     manager_utils::getServiceIdentification(asyncResp, true);
86     asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
87 
88     asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] =
89         boost::urls::format("/redfish/v1/Managers/{}",
90                             BMCWEB_REDFISH_MANAGER_URI_NAME);
91 
92     nlohmann::json& protocolFeatures =
93         asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
94     protocolFeatures["ExcerptQuery"] = false;
95 
96     protocolFeatures["ExpandQuery"]["ExpandAll"] =
97         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
98     // This is the maximum level defined in ServiceRoot.v1_13_0.json
99     if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY)
100     {
101         protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
102     }
103     protocolFeatures["ExpandQuery"]["Levels"] =
104         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
105     protocolFeatures["ExpandQuery"]["Links"] =
106         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
107     protocolFeatures["ExpandQuery"]["NoLinks"] =
108         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
109     protocolFeatures["FilterQuery"] = BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
110     protocolFeatures["OnlyMemberQuery"] = true;
111     protocolFeatures["SelectQuery"] = true;
112     protocolFeatures["DeepOperations"]["DeepPOST"] = false;
113     protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
114 }
handleServiceRootGet(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)115 inline void handleServiceRootGet(
116     App& app, const crow::Request& req,
117     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
118 {
119     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
120     {
121         return;
122     }
123 
124     handleServiceRootGetImpl(asyncResp);
125 }
126 
requestRoutesServiceRoot(App & app)127 inline void requestRoutesServiceRoot(App& app)
128 {
129     BMCWEB_ROUTE(app, "/redfish/v1/")
130         .privileges(redfish::privileges::headServiceRoot)
131         .methods(boost::beast::http::verb::head)(
132             std::bind_front(handleServiceRootHead, std::ref(app)));
133     BMCWEB_ROUTE(app, "/redfish/v1/")
134         .privileges(redfish::privileges::getServiceRoot)
135         .methods(boost::beast::http::verb::get)(
136             std::bind_front(handleServiceRootGet, std::ref(app)));
137 }
138 
139 } // namespace redfish
140