xref: /openbmc/bmcweb/redfish-core/lib/service_root.hpp (revision 504af5a0568171b72caf13234cc81380b261fa21)
140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
340e9b92eSEd 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 
15d7857201SEd Tanous #include <boost/beast/http/field.hpp>
16d7857201SEd Tanous #include <boost/beast/http/verb.hpp>
17d7857201SEd Tanous #include <boost/url/format.hpp>
189629907dSNan Zhou #include <nlohmann/json.hpp>
19b6df6dc7SBorawski.Lukasz 
20d7857201SEd Tanous #include <functional>
21d7857201SEd Tanous #include <memory>
22d7857201SEd Tanous #include <string>
23d7857201SEd Tanous 
241abe55efSEd Tanous namespace redfish
251abe55efSEd Tanous {
261abe55efSEd Tanous 
handleServiceRootHead(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)27*504af5a0SPatrick Williams inline void handleServiceRootHead(
28*504af5a0SPatrick Williams     App& app, const crow::Request& req,
295b224921SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
305b224921SEd Tanous {
315b224921SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
325b224921SEd Tanous     {
335b224921SEd Tanous         return;
345b224921SEd Tanous     }
355b224921SEd Tanous 
365b224921SEd Tanous     asyncResp->res.addHeader(
375b224921SEd Tanous         boost::beast::http::field::link,
385b224921SEd Tanous         "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
395b224921SEd Tanous }
405b224921SEd Tanous 
handleServiceRootGetImpl(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)415b224921SEd Tanous inline void handleServiceRootGetImpl(
425b224921SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
431abe55efSEd Tanous {
4401a89a1fSEd Tanous     asyncResp->res.addHeader(
4501a89a1fSEd Tanous         boost::beast::http::field::link,
4601a89a1fSEd Tanous         "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
4701a89a1fSEd Tanous 
487e860f15SJohn Edward Broadbent     std::string uuid = persistent_data::getConfig().systemUuid;
499c929beaSShantappa Teekappanavar     asyncResp->res.jsonValue["@odata.type"] =
50e68d1be0SEd Tanous         "#ServiceRoot.v1_15_0.ServiceRoot";
518d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
528d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "RootService";
538d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Root Service";
54c16e292cSEd Tanous     asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0";
551476687dSEd Tanous     asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
561476687dSEd Tanous         "/redfish/v1/SessionService/Sessions";
571476687dSEd Tanous     asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
581476687dSEd Tanous         "/redfish/v1/AccountService";
5925b54dbaSEd Tanous     if constexpr (BMCWEB_REDFISH_AGGREGATION)
6025b54dbaSEd Tanous     {
616c068982SEd Tanous         asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
626c068982SEd Tanous             "/redfish/v1/AggregationService";
6325b54dbaSEd Tanous     }
641476687dSEd Tanous     asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
651476687dSEd Tanous     asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
661476687dSEd Tanous         "/redfish/v1/JsonSchemas";
671476687dSEd Tanous     asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
681476687dSEd Tanous     asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
691476687dSEd Tanous         "/redfish/v1/SessionService";
701476687dSEd Tanous     asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
711476687dSEd Tanous     asyncResp->res.jsonValue["Registries"]["@odata.id"] =
721476687dSEd Tanous         "/redfish/v1/Registries";
731476687dSEd Tanous     asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
741476687dSEd Tanous         "/redfish/v1/UpdateService";
758d1b46d7Szhanghch05     asyncResp->res.jsonValue["UUID"] = uuid;
761476687dSEd Tanous     asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
771476687dSEd Tanous         "/redfish/v1/CertificateService";
781476687dSEd Tanous     asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
791476687dSEd Tanous     asyncResp->res.jsonValue["EventService"]["@odata.id"] =
801476687dSEd Tanous         "/redfish/v1/EventService";
811476687dSEd Tanous     asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
821476687dSEd Tanous         "/redfish/v1/TelemetryService";
831476687dSEd Tanous     asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
849629907dSNan Zhou 
85e68d1be0SEd Tanous     asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] =
86253f11b8SEd Tanous         boost::urls::format("/redfish/v1/Managers/{}",
87253f11b8SEd Tanous                             BMCWEB_REDFISH_MANAGER_URI_NAME);
88e68d1be0SEd Tanous 
899629907dSNan Zhou     nlohmann::json& protocolFeatures =
909629907dSNan Zhou         asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
919629907dSNan Zhou     protocolFeatures["ExcerptQuery"] = false;
927cf436c9SEd Tanous 
937cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["ExpandAll"] =
9425b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
957cf436c9SEd Tanous     // This is the maximum level defined in ServiceRoot.v1_13_0.json
9625b54dbaSEd Tanous     if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY)
977cf436c9SEd Tanous     {
987cf436c9SEd Tanous         protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
997cf436c9SEd Tanous     }
10025b54dbaSEd Tanous     protocolFeatures["ExpandQuery"]["Levels"] =
10125b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
10225b54dbaSEd Tanous     protocolFeatures["ExpandQuery"]["Links"] =
10325b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
1047cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["NoLinks"] =
10525b54dbaSEd Tanous         BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
10625991f7dSEd Tanous     protocolFeatures["FilterQuery"] = BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
1070553fb57SNan Zhou     protocolFeatures["OnlyMemberQuery"] = true;
10807ffa4e8SNan Zhou     protocolFeatures["SelectQuery"] = true;
1099629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPOST"] = false;
1109629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
1118338891aSJohn Edward Broadbent }
handleServiceRootGet(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)112*504af5a0SPatrick Williams inline void handleServiceRootGet(
113*504af5a0SPatrick Williams     App& app, const crow::Request& req,
1145b224921SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1155b224921SEd Tanous {
11601a89a1fSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
11701a89a1fSEd Tanous     {
11801a89a1fSEd Tanous         return;
11901a89a1fSEd Tanous     }
12001a89a1fSEd Tanous 
1215b224921SEd Tanous     handleServiceRootGetImpl(asyncResp);
1225b224921SEd Tanous }
1238338891aSJohn Edward Broadbent 
requestRoutesServiceRoot(App & app)1248338891aSJohn Edward Broadbent inline void requestRoutesServiceRoot(App& app)
1258338891aSJohn Edward Broadbent {
1268338891aSJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/")
1275b224921SEd Tanous         .privileges(redfish::privileges::headServiceRoot)
1285b224921SEd Tanous         .methods(boost::beast::http::verb::head)(
1295b224921SEd Tanous             std::bind_front(handleServiceRootHead, std::ref(app)));
1305b224921SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/")
1318338891aSJohn Edward Broadbent         .privileges(redfish::privileges::getServiceRoot)
1327cf436c9SEd Tanous         .methods(boost::beast::http::verb::get)(
1335b224921SEd Tanous             std::bind_front(handleServiceRootGet, std::ref(app)));
134b6df6dc7SBorawski.Lukasz }
1353602e232SEd Tanous 
136b6df6dc7SBorawski.Lukasz } // namespace redfish
137