blob: 387b6141cb4ebeb3e8106bc5fb850794cb17b61c [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 Tanousf4c99e72021-10-04 17:02:43 -070018#include <bmcweb_config.h>
19
John Edward Broadbent7e860f12021-04-08 15:57:16 -070020#include <app.hpp>
Nan Zhou96299072022-03-23 09:13:46 -070021#include <async_resp.hpp>
22#include <http_request.hpp>
23#include <nlohmann/json.hpp>
John Edward Broadbent83388912021-06-29 10:46:46 -070024#include <persistent_data.hpp>
Ed Tanous7cf436c2022-03-22 23:53:51 -070025#include <query.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070026#include <registries/privilege_registry.hpp>
Bernard Wong7bffdb72019-03-20 16:17:21 +080027#include <utils/systemd_utils.hpp>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010028
Ed Tanous1abe55e2018-09-05 08:30:59 -070029namespace redfish
30{
Ed Tanous3ebd75f2018-03-05 18:20:01 -080031
John Edward Broadbent83388912021-06-29 10:46:46 -070032inline void
Ed Tanous7cf436c2022-03-22 23:53:51 -070033 handleServiceRootGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent83388912021-06-29 10:46:46 -070034{
John Edward Broadbent83388912021-06-29 10:46:46 -070035 std::string uuid = persistent_data::getConfig().systemUuid;
Shantappa Teekappanavar9c929be2021-12-16 19:02:52 -060036 asyncResp->res.jsonValue["@odata.type"] =
37 "#ServiceRoot.v1_11_0.ServiceRoot";
John Edward Broadbent83388912021-06-29 10:46:46 -070038 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
39 asyncResp->res.jsonValue["Id"] = "RootService";
40 asyncResp->res.jsonValue["Name"] = "Root Service";
41 asyncResp->res.jsonValue["RedfishVersion"] = "1.9.0";
Ed Tanous14766872022-03-15 10:44:42 -070042 asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
43 "/redfish/v1/SessionService/Sessions";
44 asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
45 "/redfish/v1/AccountService";
46 asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
47 asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
48 "/redfish/v1/JsonSchemas";
49 asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
50 asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
51 "/redfish/v1/SessionService";
52 asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
53 asyncResp->res.jsonValue["Registries"]["@odata.id"] =
54 "/redfish/v1/Registries";
55 asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
56 "/redfish/v1/UpdateService";
John Edward Broadbent83388912021-06-29 10:46:46 -070057 asyncResp->res.jsonValue["UUID"] = uuid;
Ed Tanous14766872022-03-15 10:44:42 -070058 asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
59 "/redfish/v1/CertificateService";
60 asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
61 asyncResp->res.jsonValue["EventService"]["@odata.id"] =
62 "/redfish/v1/EventService";
63 asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
64 "/redfish/v1/TelemetryService";
65 asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
Nan Zhou96299072022-03-23 09:13:46 -070066
67 nlohmann::json& protocolFeatures =
68 asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
69 protocolFeatures["ExcerptQuery"] = false;
Ed Tanous7cf436c2022-03-22 23:53:51 -070070
71 protocolFeatures["ExpandQuery"]["ExpandAll"] =
72 bmcwebInsecureEnableQueryParams;
73 // This is the maximum level defined in ServiceRoot.v1_13_0.json
74 if (bmcwebInsecureEnableQueryParams)
75 {
76 protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
77 }
78 protocolFeatures["ExpandQuery"]["Levels"] = bmcwebInsecureEnableQueryParams;
79 protocolFeatures["ExpandQuery"]["Links"] = bmcwebInsecureEnableQueryParams;
80 protocolFeatures["ExpandQuery"]["NoLinks"] =
81 bmcwebInsecureEnableQueryParams;
Nan Zhou96299072022-03-23 09:13:46 -070082 protocolFeatures["FilterQuery"] = false;
Ed Tanousf4c99e72021-10-04 17:02:43 -070083 protocolFeatures["OnlyMemberQuery"] = bmcwebInsecureEnableQueryParams;
Nan Zhou96299072022-03-23 09:13:46 -070084 protocolFeatures["SelectQuery"] = false;
85 protocolFeatures["DeepOperations"]["DeepPOST"] = false;
86 protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
John Edward Broadbent83388912021-06-29 10:46:46 -070087}
88
John Edward Broadbent7e860f12021-04-08 15:57:16 -070089inline void requestRoutesServiceRoot(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070090{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070091 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanoused398212021-06-09 17:05:54 -070092 .privileges(redfish::privileges::getServiceRoot)
Ed Tanous7cf436c2022-03-22 23:53:51 -070093 .methods(boost::beast::http::verb::get)(
94 [&app](const crow::Request& req,
95 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +000096 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -070097 {
98 return;
99 }
100 handleServiceRootGet(asyncResp);
101 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700102}
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100103
Ed Tanous1abe55e2018-09-05 08:30:59 -0700104} // namespace redfish