blob: 5e3bbad0b4d8d8cd0b2ad513b71b7c52c1f5935f [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +01004#pragma once
5
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "bmcweb_config.h"
Ed Tanousf4c99e72021-10-04 17:02:43 -07007
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "app.hpp"
9#include "async_resp.hpp"
10#include "http_request.hpp"
11#include "persistent_data.hpp"
12#include "query.hpp"
13#include "registries/privilege_registry.hpp"
14#include "utils/systemd_utils.hpp"
15
Nan Zhou96299072022-03-23 09:13:46 -070016#include <nlohmann/json.hpp>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010017
Ed Tanous1abe55e2018-09-05 08:30:59 -070018namespace redfish
19{
Ed Tanous3ebd75f2018-03-05 18:20:01 -080020
John Edward Broadbent83388912021-06-29 10:46:46 -070021inline void
Ed Tanous5b224922022-06-22 19:00:59 -070022 handleServiceRootHead(App& app, const crow::Request& req,
23 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
24{
25 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
26 {
27 return;
28 }
29
30 asyncResp->res.addHeader(
31 boost::beast::http::field::link,
32 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
33}
34
35inline void handleServiceRootGetImpl(
36 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent83388912021-06-29 10:46:46 -070037{
Ed Tanous01a89a12022-08-05 09:18:54 -070038 asyncResp->res.addHeader(
39 boost::beast::http::field::link,
40 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
41
John Edward Broadbent83388912021-06-29 10:46:46 -070042 std::string uuid = persistent_data::getConfig().systemUuid;
Shantappa Teekappanavar9c929be2021-12-16 19:02:52 -060043 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanouse68d1be2023-01-27 10:42:32 -080044 "#ServiceRoot.v1_15_0.ServiceRoot";
John Edward Broadbent83388912021-06-29 10:46:46 -070045 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
46 asyncResp->res.jsonValue["Id"] = "RootService";
47 asyncResp->res.jsonValue["Name"] = "Root Service";
Ed Tanousc16e2922022-07-15 12:46:02 -070048 asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0";
Ed Tanous14766872022-03-15 10:44:42 -070049 asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
50 "/redfish/v1/SessionService/Sessions";
51 asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
52 "/redfish/v1/AccountService";
Ed Tanous25b54db2024-04-17 15:40:31 -070053 if constexpr (BMCWEB_REDFISH_AGGREGATION)
54 {
55 asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
56 "/redfish/v1/AggregationService";
57 }
Ed Tanous14766872022-03-15 10:44:42 -070058 asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
59 asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
60 "/redfish/v1/JsonSchemas";
61 asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
62 asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
63 "/redfish/v1/SessionService";
64 asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
65 asyncResp->res.jsonValue["Registries"]["@odata.id"] =
66 "/redfish/v1/Registries";
67 asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
68 "/redfish/v1/UpdateService";
John Edward Broadbent83388912021-06-29 10:46:46 -070069 asyncResp->res.jsonValue["UUID"] = uuid;
Ed Tanous14766872022-03-15 10:44:42 -070070 asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
71 "/redfish/v1/CertificateService";
72 asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
73 asyncResp->res.jsonValue["EventService"]["@odata.id"] =
74 "/redfish/v1/EventService";
75 asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
76 "/redfish/v1/TelemetryService";
77 asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
Nan Zhou96299072022-03-23 09:13:46 -070078
Ed Tanouse68d1be2023-01-27 10:42:32 -080079 asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -070080 boost::urls::format("/redfish/v1/Managers/{}",
81 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanouse68d1be2023-01-27 10:42:32 -080082
Nan Zhou96299072022-03-23 09:13:46 -070083 nlohmann::json& protocolFeatures =
84 asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
85 protocolFeatures["ExcerptQuery"] = false;
Ed Tanous7cf436c2022-03-22 23:53:51 -070086
87 protocolFeatures["ExpandQuery"]["ExpandAll"] =
Ed Tanous25b54db2024-04-17 15:40:31 -070088 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -070089 // This is the maximum level defined in ServiceRoot.v1_13_0.json
Ed Tanous25b54db2024-04-17 15:40:31 -070090 if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY)
Ed Tanous7cf436c2022-03-22 23:53:51 -070091 {
92 protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
93 }
Ed Tanous25b54db2024-04-17 15:40:31 -070094 protocolFeatures["ExpandQuery"]["Levels"] =
95 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
96 protocolFeatures["ExpandQuery"]["Links"] =
97 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -070098 protocolFeatures["ExpandQuery"]["NoLinks"] =
Ed Tanous25b54db2024-04-17 15:40:31 -070099 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous25991f72024-06-13 18:10:25 -0700100 protocolFeatures["FilterQuery"] = BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Nan Zhou0553fb52022-08-05 17:23:06 +0000101 protocolFeatures["OnlyMemberQuery"] = true;
Nan Zhou07ffa4e2022-08-09 22:46:25 +0000102 protocolFeatures["SelectQuery"] = true;
Nan Zhou96299072022-03-23 09:13:46 -0700103 protocolFeatures["DeepOperations"]["DeepPOST"] = false;
104 protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
John Edward Broadbent83388912021-06-29 10:46:46 -0700105}
Ed Tanous5b224922022-06-22 19:00:59 -0700106inline void
107 handleServiceRootGet(App& app, const crow::Request& req,
108 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
109{
Ed Tanous01a89a12022-08-05 09:18:54 -0700110 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
111 {
112 return;
113 }
114
Ed Tanous5b224922022-06-22 19:00:59 -0700115 handleServiceRootGetImpl(asyncResp);
116}
John Edward Broadbent83388912021-06-29 10:46:46 -0700117
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700118inline void requestRoutesServiceRoot(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700119{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700120 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanous5b224922022-06-22 19:00:59 -0700121 .privileges(redfish::privileges::headServiceRoot)
122 .methods(boost::beast::http::verb::head)(
123 std::bind_front(handleServiceRootHead, std::ref(app)));
124 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanoused398212021-06-09 17:05:54 -0700125 .privileges(redfish::privileges::getServiceRoot)
Ed Tanous7cf436c2022-03-22 23:53:51 -0700126 .methods(boost::beast::http::verb::get)(
Ed Tanous5b224922022-06-22 19:00:59 -0700127 std::bind_front(handleServiceRootGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700128}
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100129
Ed Tanous1abe55e2018-09-05 08:30:59 -0700130} // namespace redfish