xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision 40e9b92ec19acffb46f83a6e55b18974da5d708e)
1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
4b6df6dc7SBorawski.Lukasz #pragma once
5b6df6dc7SBorawski.Lukasz 
63ccb3adbSEd Tanous #include "bmcweb_config.h"
7f4c99e70SEd Tanous 
83ccb3adbSEd Tanous #include "app.hpp"
93ccb3adbSEd Tanous #include "async_resp.hpp"
103ccb3adbSEd Tanous #include "http_request.hpp"
113ccb3adbSEd Tanous #include "persistent_data.hpp"
123ccb3adbSEd Tanous #include "query.hpp"
133ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
143ccb3adbSEd Tanous #include "utils/systemd_utils.hpp"
153ccb3adbSEd Tanous 
169629907dSNan Zhou #include <nlohmann/json.hpp>
17b6df6dc7SBorawski.Lukasz 
181abe55efSEd Tanous namespace redfish
191abe55efSEd Tanous {
201abe55efSEd Tanous 
218338891aSJohn Edward Broadbent inline void
225b224921SEd Tanous     handleServiceRootHead(App& app, const crow::Request& req,
235b224921SEd Tanous                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
245b224921SEd Tanous {
255b224921SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
265b224921SEd Tanous     {
275b224921SEd Tanous         return;
285b224921SEd Tanous     }
295b224921SEd Tanous 
305b224921SEd Tanous     asyncResp->res.addHeader(
315b224921SEd Tanous         boost::beast::http::field::link,
325b224921SEd Tanous         "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
335b224921SEd Tanous }
345b224921SEd Tanous 
355b224921SEd Tanous inline void handleServiceRootGetImpl(
365b224921SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
371abe55efSEd Tanous {
3801a89a1fSEd Tanous     asyncResp->res.addHeader(
3901a89a1fSEd Tanous         boost::beast::http::field::link,
4001a89a1fSEd Tanous         "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
4101a89a1fSEd Tanous 
427e860f15SJohn Edward Broadbent     std::string uuid = persistent_data::getConfig().systemUuid;
439c929beaSShantappa Teekappanavar     asyncResp->res.jsonValue["@odata.type"] =
44e68d1be0SEd Tanous         "#ServiceRoot.v1_15_0.ServiceRoot";
458d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
468d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "RootService";
478d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Root Service";
48c16e292cSEd Tanous     asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0";
491476687dSEd Tanous     asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
501476687dSEd Tanous         "/redfish/v1/SessionService/Sessions";
511476687dSEd Tanous     asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
521476687dSEd Tanous         "/redfish/v1/AccountService";
5325b54dbaSEd Tanous     if constexpr (BMCWEB_REDFISH_AGGREGATION)
5425b54dbaSEd Tanous     {
556c068982SEd Tanous         asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
566c068982SEd Tanous             "/redfish/v1/AggregationService";
5725b54dbaSEd Tanous     }
581476687dSEd Tanous     asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
591476687dSEd Tanous     asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
601476687dSEd Tanous         "/redfish/v1/JsonSchemas";
611476687dSEd Tanous     asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
621476687dSEd Tanous     asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
631476687dSEd Tanous         "/redfish/v1/SessionService";
641476687dSEd Tanous     asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
651476687dSEd Tanous     asyncResp->res.jsonValue["Registries"]["@odata.id"] =
661476687dSEd Tanous         "/redfish/v1/Registries";
671476687dSEd Tanous     asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
681476687dSEd Tanous         "/redfish/v1/UpdateService";
698d1b46d7Szhanghch05     asyncResp->res.jsonValue["UUID"] = uuid;
701476687dSEd Tanous     asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
711476687dSEd Tanous         "/redfish/v1/CertificateService";
721476687dSEd Tanous     asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
731476687dSEd Tanous     asyncResp->res.jsonValue["EventService"]["@odata.id"] =
741476687dSEd Tanous         "/redfish/v1/EventService";
751476687dSEd Tanous     asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
761476687dSEd Tanous         "/redfish/v1/TelemetryService";
771476687dSEd Tanous     asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
789629907dSNan Zhou 
79e68d1be0SEd Tanous     asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] =
80253f11b8SEd Tanous         boost::urls::format("/redfish/v1/Managers/{}",
81253f11b8SEd Tanous                             BMCWEB_REDFISH_MANAGER_URI_NAME);
82e68d1be0SEd Tanous 
839629907dSNan Zhou     nlohmann::json& protocolFeatures =
849629907dSNan Zhou         asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
859629907dSNan Zhou     protocolFeatures["ExcerptQuery"] = false;
867cf436c9SEd Tanous 
877cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["ExpandAll"] =
8825b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
897cf436c9SEd Tanous     // This is the maximum level defined in ServiceRoot.v1_13_0.json
9025b54dbaSEd Tanous     if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY)
917cf436c9SEd Tanous     {
927cf436c9SEd Tanous         protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
937cf436c9SEd Tanous     }
9425b54dbaSEd Tanous     protocolFeatures["ExpandQuery"]["Levels"] =
9525b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
9625b54dbaSEd Tanous     protocolFeatures["ExpandQuery"]["Links"] =
9725b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
987cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["NoLinks"] =
9925b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
10025991f7dSEd Tanous     protocolFeatures["FilterQuery"] = BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
1010553fb57SNan Zhou     protocolFeatures["OnlyMemberQuery"] = true;
10207ffa4e8SNan Zhou     protocolFeatures["SelectQuery"] = true;
1039629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPOST"] = false;
1049629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
1058338891aSJohn Edward Broadbent }
1065b224921SEd Tanous inline void
1075b224921SEd Tanous     handleServiceRootGet(App& app, const crow::Request& req,
1085b224921SEd Tanous                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1095b224921SEd Tanous {
11001a89a1fSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
11101a89a1fSEd Tanous     {
11201a89a1fSEd Tanous         return;
11301a89a1fSEd Tanous     }
11401a89a1fSEd Tanous 
1155b224921SEd Tanous     handleServiceRootGetImpl(asyncResp);
1165b224921SEd Tanous }
1178338891aSJohn Edward Broadbent 
1188338891aSJohn Edward Broadbent inline void requestRoutesServiceRoot(App& app)
1198338891aSJohn Edward Broadbent {
1208338891aSJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/")
1215b224921SEd Tanous         .privileges(redfish::privileges::headServiceRoot)
1225b224921SEd Tanous         .methods(boost::beast::http::verb::head)(
1235b224921SEd Tanous             std::bind_front(handleServiceRootHead, std::ref(app)));
1245b224921SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/")
1258338891aSJohn Edward Broadbent         .privileges(redfish::privileges::getServiceRoot)
1267cf436c9SEd Tanous         .methods(boost::beast::http::verb::get)(
1275b224921SEd Tanous             std::bind_front(handleServiceRootGet, std::ref(app)));
128b6df6dc7SBorawski.Lukasz }
1293602e232SEd Tanous 
130b6df6dc7SBorawski.Lukasz } // namespace redfish
131