blob: 2fc35150dd5cd19c93401b339a242bed2d1b6fd4 [file] [log] [blame]
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +01001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "bmcweb_config.h"
Ed Tanousf4c99e72021-10-04 17:02:43 -070019
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "app.hpp"
21#include "async_resp.hpp"
22#include "http_request.hpp"
23#include "persistent_data.hpp"
24#include "query.hpp"
25#include "registries/privilege_registry.hpp"
26#include "utils/systemd_utils.hpp"
27
Nan Zhou96299072022-03-23 09:13:46 -070028#include <nlohmann/json.hpp>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010029
Ed Tanous1abe55e2018-09-05 08:30:59 -070030namespace redfish
31{
Ed Tanous3ebd75f2018-03-05 18:20:01 -080032
John Edward Broadbent83388912021-06-29 10:46:46 -070033inline void
Ed Tanous5b224922022-06-22 19:00:59 -070034 handleServiceRootHead(App& app, const crow::Request& req,
35 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
36{
37 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
38 {
39 return;
40 }
41
42 asyncResp->res.addHeader(
43 boost::beast::http::field::link,
44 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
45}
46
47inline void handleServiceRootGetImpl(
48 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent83388912021-06-29 10:46:46 -070049{
Ed Tanous01a89a12022-08-05 09:18:54 -070050 asyncResp->res.addHeader(
51 boost::beast::http::field::link,
52 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
53
John Edward Broadbent83388912021-06-29 10:46:46 -070054 std::string uuid = persistent_data::getConfig().systemUuid;
Shantappa Teekappanavar9c929be2021-12-16 19:02:52 -060055 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanouse68d1be2023-01-27 10:42:32 -080056 "#ServiceRoot.v1_15_0.ServiceRoot";
John Edward Broadbent83388912021-06-29 10:46:46 -070057 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
58 asyncResp->res.jsonValue["Id"] = "RootService";
59 asyncResp->res.jsonValue["Name"] = "Root Service";
Ed Tanousc16e2922022-07-15 12:46:02 -070060 asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0";
Ed Tanous14766872022-03-15 10:44:42 -070061 asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
62 "/redfish/v1/SessionService/Sessions";
63 asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
64 "/redfish/v1/AccountService";
Ed Tanous25b54db2024-04-17 15:40:31 -070065 if constexpr (BMCWEB_REDFISH_AGGREGATION)
66 {
67 asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
68 "/redfish/v1/AggregationService";
69 }
Ed Tanous14766872022-03-15 10:44:42 -070070 asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
71 asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
72 "/redfish/v1/JsonSchemas";
73 asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
74 asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
75 "/redfish/v1/SessionService";
76 asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
77 asyncResp->res.jsonValue["Registries"]["@odata.id"] =
78 "/redfish/v1/Registries";
79 asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
80 "/redfish/v1/UpdateService";
John Edward Broadbent83388912021-06-29 10:46:46 -070081 asyncResp->res.jsonValue["UUID"] = uuid;
Ed Tanous14766872022-03-15 10:44:42 -070082 asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
83 "/redfish/v1/CertificateService";
84 asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
85 asyncResp->res.jsonValue["EventService"]["@odata.id"] =
86 "/redfish/v1/EventService";
87 asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
88 "/redfish/v1/TelemetryService";
89 asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
Nan Zhou96299072022-03-23 09:13:46 -070090
Ed Tanouse68d1be2023-01-27 10:42:32 -080091 asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] =
92 "/redfish/v1/Managers/bmc";
93
Nan Zhou96299072022-03-23 09:13:46 -070094 nlohmann::json& protocolFeatures =
95 asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
96 protocolFeatures["ExcerptQuery"] = false;
Ed Tanous7cf436c2022-03-22 23:53:51 -070097
98 protocolFeatures["ExpandQuery"]["ExpandAll"] =
Ed Tanous25b54db2024-04-17 15:40:31 -070099 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -0700100 // This is the maximum level defined in ServiceRoot.v1_13_0.json
Ed Tanous25b54db2024-04-17 15:40:31 -0700101 if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY)
Ed Tanous7cf436c2022-03-22 23:53:51 -0700102 {
103 protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
104 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700105 protocolFeatures["ExpandQuery"]["Levels"] =
106 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
107 protocolFeatures["ExpandQuery"]["Links"] =
108 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -0700109 protocolFeatures["ExpandQuery"]["NoLinks"] =
Ed Tanous25b54db2024-04-17 15:40:31 -0700110 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Nan Zhou96299072022-03-23 09:13:46 -0700111 protocolFeatures["FilterQuery"] = false;
Nan Zhou0553fb52022-08-05 17:23:06 +0000112 protocolFeatures["OnlyMemberQuery"] = true;
Nan Zhou07ffa4e2022-08-09 22:46:25 +0000113 protocolFeatures["SelectQuery"] = true;
Nan Zhou96299072022-03-23 09:13:46 -0700114 protocolFeatures["DeepOperations"]["DeepPOST"] = false;
115 protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
John Edward Broadbent83388912021-06-29 10:46:46 -0700116}
Ed Tanous5b224922022-06-22 19:00:59 -0700117inline void
118 handleServiceRootGet(App& app, const crow::Request& req,
119 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
120{
Ed Tanous01a89a12022-08-05 09:18:54 -0700121 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
122 {
123 return;
124 }
125
Ed Tanous5b224922022-06-22 19:00:59 -0700126 handleServiceRootGetImpl(asyncResp);
127}
John Edward Broadbent83388912021-06-29 10:46:46 -0700128
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700129inline void requestRoutesServiceRoot(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700130{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700131 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanous5b224922022-06-22 19:00:59 -0700132 .privileges(redfish::privileges::headServiceRoot)
133 .methods(boost::beast::http::verb::head)(
134 std::bind_front(handleServiceRootHead, std::ref(app)));
135 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanoused398212021-06-09 17:05:54 -0700136 .privileges(redfish::privileges::getServiceRoot)
Ed Tanous7cf436c2022-03-22 23:53:51 -0700137 .methods(boost::beast::http::verb::get)(
Ed Tanous5b224922022-06-22 19:00:59 -0700138 std::bind_front(handleServiceRootGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700139}
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100140
Ed Tanous1abe55e2018-09-05 08:30:59 -0700141} // namespace redfish