xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision 6c068982d54d20476fd04ae7ef893b153015762e)
1b6df6dc7SBorawski.Lukasz /*
2b6df6dc7SBorawski.Lukasz // Copyright (c) 2018 Intel Corporation
3b6df6dc7SBorawski.Lukasz //
4b6df6dc7SBorawski.Lukasz // Licensed under the Apache License, Version 2.0 (the "License");
5b6df6dc7SBorawski.Lukasz // you may not use this file except in compliance with the License.
6b6df6dc7SBorawski.Lukasz // You may obtain a copy of the License at
7b6df6dc7SBorawski.Lukasz //
8b6df6dc7SBorawski.Lukasz //      http://www.apache.org/licenses/LICENSE-2.0
9b6df6dc7SBorawski.Lukasz //
10b6df6dc7SBorawski.Lukasz // Unless required by applicable law or agreed to in writing, software
11b6df6dc7SBorawski.Lukasz // distributed under the License is distributed on an "AS IS" BASIS,
12b6df6dc7SBorawski.Lukasz // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b6df6dc7SBorawski.Lukasz // See the License for the specific language governing permissions and
14b6df6dc7SBorawski.Lukasz // limitations under the License.
15b6df6dc7SBorawski.Lukasz */
16b6df6dc7SBorawski.Lukasz #pragma once
17b6df6dc7SBorawski.Lukasz 
183ccb3adbSEd Tanous #include "bmcweb_config.h"
19f4c99e70SEd Tanous 
203ccb3adbSEd Tanous #include "app.hpp"
213ccb3adbSEd Tanous #include "async_resp.hpp"
223ccb3adbSEd Tanous #include "http_request.hpp"
233ccb3adbSEd Tanous #include "persistent_data.hpp"
243ccb3adbSEd Tanous #include "query.hpp"
253ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
263ccb3adbSEd Tanous #include "utils/systemd_utils.hpp"
273ccb3adbSEd Tanous 
289629907dSNan Zhou #include <nlohmann/json.hpp>
29b6df6dc7SBorawski.Lukasz 
301abe55efSEd Tanous namespace redfish
311abe55efSEd Tanous {
321abe55efSEd Tanous 
338338891aSJohn Edward Broadbent inline void
345b224921SEd Tanous     handleServiceRootHead(App& app, const crow::Request& req,
355b224921SEd Tanous                           const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
365b224921SEd Tanous {
375b224921SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
385b224921SEd Tanous     {
395b224921SEd Tanous         return;
405b224921SEd Tanous     }
415b224921SEd Tanous 
425b224921SEd Tanous     asyncResp->res.addHeader(
435b224921SEd Tanous         boost::beast::http::field::link,
445b224921SEd Tanous         "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
455b224921SEd Tanous }
465b224921SEd Tanous 
475b224921SEd Tanous inline void handleServiceRootGetImpl(
485b224921SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
491abe55efSEd Tanous {
507e860f15SJohn Edward Broadbent     std::string uuid = persistent_data::getConfig().systemUuid;
519c929beaSShantappa Teekappanavar     asyncResp->res.jsonValue["@odata.type"] =
529c929beaSShantappa Teekappanavar         "#ServiceRoot.v1_11_0.ServiceRoot";
538d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
548d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "RootService";
558d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Root Service";
568d1b46d7Szhanghch05     asyncResp->res.jsonValue["RedfishVersion"] = "1.9.0";
571476687dSEd Tanous     asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
581476687dSEd Tanous         "/redfish/v1/SessionService/Sessions";
591476687dSEd Tanous     asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
601476687dSEd Tanous         "/redfish/v1/AccountService";
61*6c068982SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION
62*6c068982SEd Tanous     asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
63*6c068982SEd Tanous         "/redfish/v1/AggregationService";
64*6c068982SEd Tanous #endif
651476687dSEd Tanous     asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
661476687dSEd Tanous     asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
671476687dSEd Tanous         "/redfish/v1/JsonSchemas";
681476687dSEd Tanous     asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
691476687dSEd Tanous     asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
701476687dSEd Tanous         "/redfish/v1/SessionService";
711476687dSEd Tanous     asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
721476687dSEd Tanous     asyncResp->res.jsonValue["Registries"]["@odata.id"] =
731476687dSEd Tanous         "/redfish/v1/Registries";
741476687dSEd Tanous     asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
751476687dSEd Tanous         "/redfish/v1/UpdateService";
768d1b46d7Szhanghch05     asyncResp->res.jsonValue["UUID"] = uuid;
771476687dSEd Tanous     asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
781476687dSEd Tanous         "/redfish/v1/CertificateService";
791476687dSEd Tanous     asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
801476687dSEd Tanous     asyncResp->res.jsonValue["EventService"]["@odata.id"] =
811476687dSEd Tanous         "/redfish/v1/EventService";
821476687dSEd Tanous     asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
831476687dSEd Tanous         "/redfish/v1/TelemetryService";
841476687dSEd Tanous     asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
859629907dSNan Zhou 
869629907dSNan Zhou     nlohmann::json& protocolFeatures =
879629907dSNan Zhou         asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
889629907dSNan Zhou     protocolFeatures["ExcerptQuery"] = false;
897cf436c9SEd Tanous 
907cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["ExpandAll"] =
917cf436c9SEd Tanous         bmcwebInsecureEnableQueryParams;
927cf436c9SEd Tanous     // This is the maximum level defined in ServiceRoot.v1_13_0.json
937cf436c9SEd Tanous     if (bmcwebInsecureEnableQueryParams)
947cf436c9SEd Tanous     {
957cf436c9SEd Tanous         protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
967cf436c9SEd Tanous     }
977cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["Levels"] = bmcwebInsecureEnableQueryParams;
987cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["Links"] = bmcwebInsecureEnableQueryParams;
997cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["NoLinks"] =
1007cf436c9SEd Tanous         bmcwebInsecureEnableQueryParams;
1019629907dSNan Zhou     protocolFeatures["FilterQuery"] = false;
1020553fb57SNan Zhou     protocolFeatures["OnlyMemberQuery"] = true;
10307ffa4e8SNan Zhou     protocolFeatures["SelectQuery"] = true;
1049629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPOST"] = false;
1059629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
1068338891aSJohn Edward Broadbent }
1075b224921SEd Tanous inline void
1085b224921SEd Tanous     handleServiceRootGet(App& app, const crow::Request& req,
1095b224921SEd Tanous                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1105b224921SEd Tanous {
1115b224921SEd Tanous     handleServiceRootHead(app, req, asyncResp);
1125b224921SEd Tanous     handleServiceRootGetImpl(asyncResp);
1135b224921SEd Tanous }
1148338891aSJohn Edward Broadbent 
1158338891aSJohn Edward Broadbent inline void requestRoutesServiceRoot(App& app)
1168338891aSJohn Edward Broadbent {
1178338891aSJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/")
1185b224921SEd Tanous         .privileges(redfish::privileges::headServiceRoot)
1195b224921SEd Tanous         .methods(boost::beast::http::verb::head)(
1205b224921SEd Tanous             std::bind_front(handleServiceRootHead, std::ref(app)));
1215b224921SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/")
1228338891aSJohn Edward Broadbent         .privileges(redfish::privileges::getServiceRoot)
1237cf436c9SEd Tanous         .methods(boost::beast::http::verb::get)(
1245b224921SEd Tanous             std::bind_front(handleServiceRootGet, std::ref(app)));
125b6df6dc7SBorawski.Lukasz }
1263602e232SEd Tanous 
127b6df6dc7SBorawski.Lukasz } // namespace redfish
128