xref: /openbmc/bmcweb/features/redfish/lib/service_root.hpp (revision 1476687deb1697d865b20458a0097c9ab5fd44e2)
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 
18f4c99e70SEd Tanous #include <bmcweb_config.h>
19f4c99e70SEd Tanous 
207e860f15SJohn Edward Broadbent #include <app.hpp>
219629907dSNan Zhou #include <async_resp.hpp>
229629907dSNan Zhou #include <http_request.hpp>
239629907dSNan Zhou #include <nlohmann/json.hpp>
248338891aSJohn Edward Broadbent #include <persistent_data.hpp>
257cf436c9SEd Tanous #include <query.hpp>
26ed398213SEd Tanous #include <registries/privilege_registry.hpp>
277bffdb7eSBernard Wong #include <utils/systemd_utils.hpp>
28b6df6dc7SBorawski.Lukasz 
291abe55efSEd Tanous namespace redfish
301abe55efSEd Tanous {
311abe55efSEd Tanous 
328338891aSJohn Edward Broadbent inline void
337cf436c9SEd Tanous     handleServiceRootGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
341abe55efSEd Tanous {
357e860f15SJohn Edward Broadbent     std::string uuid = persistent_data::getConfig().systemUuid;
369c929beaSShantappa Teekappanavar     asyncResp->res.jsonValue["@odata.type"] =
379c929beaSShantappa Teekappanavar         "#ServiceRoot.v1_11_0.ServiceRoot";
388d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
398d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "RootService";
408d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Root Service";
418d1b46d7Szhanghch05     asyncResp->res.jsonValue["RedfishVersion"] = "1.9.0";
42*1476687dSEd Tanous     asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
43*1476687dSEd Tanous         "/redfish/v1/SessionService/Sessions";
44*1476687dSEd Tanous     asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
45*1476687dSEd Tanous         "/redfish/v1/AccountService";
46*1476687dSEd Tanous     asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
47*1476687dSEd Tanous     asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
48*1476687dSEd Tanous         "/redfish/v1/JsonSchemas";
49*1476687dSEd Tanous     asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
50*1476687dSEd Tanous     asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
51*1476687dSEd Tanous         "/redfish/v1/SessionService";
52*1476687dSEd Tanous     asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
53*1476687dSEd Tanous     asyncResp->res.jsonValue["Registries"]["@odata.id"] =
54*1476687dSEd Tanous         "/redfish/v1/Registries";
55*1476687dSEd Tanous     asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
56*1476687dSEd Tanous         "/redfish/v1/UpdateService";
578d1b46d7Szhanghch05     asyncResp->res.jsonValue["UUID"] = uuid;
58*1476687dSEd Tanous     asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
59*1476687dSEd Tanous         "/redfish/v1/CertificateService";
60*1476687dSEd Tanous     asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
61*1476687dSEd Tanous     asyncResp->res.jsonValue["EventService"]["@odata.id"] =
62*1476687dSEd Tanous         "/redfish/v1/EventService";
63*1476687dSEd Tanous     asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
64*1476687dSEd Tanous         "/redfish/v1/TelemetryService";
65*1476687dSEd Tanous     asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
669629907dSNan Zhou 
679629907dSNan Zhou     nlohmann::json& protocolFeatures =
689629907dSNan Zhou         asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
699629907dSNan Zhou     protocolFeatures["ExcerptQuery"] = false;
707cf436c9SEd Tanous 
717cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["ExpandAll"] =
727cf436c9SEd Tanous         bmcwebInsecureEnableQueryParams;
737cf436c9SEd Tanous     // This is the maximum level defined in ServiceRoot.v1_13_0.json
747cf436c9SEd Tanous     if (bmcwebInsecureEnableQueryParams)
757cf436c9SEd Tanous     {
767cf436c9SEd Tanous         protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
777cf436c9SEd Tanous     }
787cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["Levels"] = bmcwebInsecureEnableQueryParams;
797cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["Links"] = bmcwebInsecureEnableQueryParams;
807cf436c9SEd Tanous     protocolFeatures["ExpandQuery"]["NoLinks"] =
817cf436c9SEd Tanous         bmcwebInsecureEnableQueryParams;
829629907dSNan Zhou     protocolFeatures["FilterQuery"] = false;
83f4c99e70SEd Tanous     protocolFeatures["OnlyMemberQuery"] = bmcwebInsecureEnableQueryParams;
849629907dSNan Zhou     protocolFeatures["SelectQuery"] = false;
859629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPOST"] = false;
869629907dSNan Zhou     protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
878338891aSJohn Edward Broadbent }
888338891aSJohn Edward Broadbent 
898338891aSJohn Edward Broadbent inline void requestRoutesServiceRoot(App& app)
908338891aSJohn Edward Broadbent {
918338891aSJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/")
928338891aSJohn Edward Broadbent         .privileges(redfish::privileges::getServiceRoot)
937cf436c9SEd Tanous         .methods(boost::beast::http::verb::get)(
947cf436c9SEd Tanous             [&app](const crow::Request& req,
957cf436c9SEd Tanous                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
967cf436c9SEd Tanous                 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
977cf436c9SEd Tanous                 {
987cf436c9SEd Tanous                     return;
997cf436c9SEd Tanous                 }
1007cf436c9SEd Tanous                 handleServiceRootGet(asyncResp);
1017cf436c9SEd Tanous             });
102b6df6dc7SBorawski.Lukasz }
1033602e232SEd Tanous 
104b6df6dc7SBorawski.Lukasz } // namespace redfish
105