blob: a67a75de19df4e8e6b1165e7e9d119b0ecc6dee0 [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"
Corey Ethingtone30d3342025-06-24 11:25:11 -040014#include "utils/manager_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080015
Ed Tanousd7857202025-01-28 15:32:26 -080016#include <boost/beast/http/field.hpp>
17#include <boost/beast/http/verb.hpp>
18#include <boost/url/format.hpp>
Nan Zhou96299072022-03-23 09:13:46 -070019#include <nlohmann/json.hpp>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010020
Ed Tanousd7857202025-01-28 15:32:26 -080021#include <functional>
22#include <memory>
23#include <string>
24
Ed Tanous1abe55e2018-09-05 08:30:59 -070025namespace redfish
26{
Ed Tanous3ebd75f2018-03-05 18:20:01 -080027
Patrick Williams504af5a2025-02-03 14:29:03 -050028inline void handleServiceRootHead(
29 App& app, const crow::Request& req,
30 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous5b224922022-06-22 19:00:59 -070031{
32 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
33 {
34 return;
35 }
36
37 asyncResp->res.addHeader(
38 boost::beast::http::field::link,
39 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
40}
41
42inline void handleServiceRootGetImpl(
43 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent83388912021-06-29 10:46:46 -070044{
Ed Tanous01a89a12022-08-05 09:18:54 -070045 asyncResp->res.addHeader(
46 boost::beast::http::field::link,
47 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
48
John Edward Broadbent83388912021-06-29 10:46:46 -070049 std::string uuid = persistent_data::getConfig().systemUuid;
Shantappa Teekappanavar9c929be2021-12-16 19:02:52 -060050 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanouse68d1be2023-01-27 10:42:32 -080051 "#ServiceRoot.v1_15_0.ServiceRoot";
John Edward Broadbent83388912021-06-29 10:46:46 -070052 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
53 asyncResp->res.jsonValue["Id"] = "RootService";
54 asyncResp->res.jsonValue["Name"] = "Root Service";
Ed Tanousc16e2922022-07-15 12:46:02 -070055 asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0";
Ed Tanous14766872022-03-15 10:44:42 -070056 asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
57 "/redfish/v1/SessionService/Sessions";
58 asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
59 "/redfish/v1/AccountService";
Ed Tanous25b54db2024-04-17 15:40:31 -070060 if constexpr (BMCWEB_REDFISH_AGGREGATION)
61 {
62 asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
63 "/redfish/v1/AggregationService";
64 }
Ed Tanous14766872022-03-15 10:44:42 -070065 asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
66 asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
67 "/redfish/v1/JsonSchemas";
68 asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
69 asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
70 "/redfish/v1/SessionService";
71 asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
72 asyncResp->res.jsonValue["Registries"]["@odata.id"] =
73 "/redfish/v1/Registries";
74 asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
75 "/redfish/v1/UpdateService";
John Edward Broadbent83388912021-06-29 10:46:46 -070076 asyncResp->res.jsonValue["UUID"] = uuid;
Ed Tanous14766872022-03-15 10:44:42 -070077 asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
78 "/redfish/v1/CertificateService";
79 asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
80 asyncResp->res.jsonValue["EventService"]["@odata.id"] =
81 "/redfish/v1/EventService";
82 asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
83 "/redfish/v1/TelemetryService";
Corey Ethingtone30d3342025-06-24 11:25:11 -040084 manager_utils::getServiceIdentification(asyncResp, true);
Ed Tanous14766872022-03-15 10:44:42 -070085 asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
Nan Zhou96299072022-03-23 09:13:46 -070086
Ed Tanouse68d1be2023-01-27 10:42:32 -080087 asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -070088 boost::urls::format("/redfish/v1/Managers/{}",
89 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanouse68d1be2023-01-27 10:42:32 -080090
Nan Zhou96299072022-03-23 09:13:46 -070091 nlohmann::json& protocolFeatures =
92 asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
93 protocolFeatures["ExcerptQuery"] = false;
Ed Tanous7cf436c2022-03-22 23:53:51 -070094
95 protocolFeatures["ExpandQuery"]["ExpandAll"] =
Ed Tanous25b54db2024-04-17 15:40:31 -070096 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -070097 // This is the maximum level defined in ServiceRoot.v1_13_0.json
Ed Tanous25b54db2024-04-17 15:40:31 -070098 if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY)
Ed Tanous7cf436c2022-03-22 23:53:51 -070099 {
100 protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
101 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700102 protocolFeatures["ExpandQuery"]["Levels"] =
103 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
104 protocolFeatures["ExpandQuery"]["Links"] =
105 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -0700106 protocolFeatures["ExpandQuery"]["NoLinks"] =
Ed Tanous25b54db2024-04-17 15:40:31 -0700107 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous25991f72024-06-13 18:10:25 -0700108 protocolFeatures["FilterQuery"] = BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Nan Zhou0553fb52022-08-05 17:23:06 +0000109 protocolFeatures["OnlyMemberQuery"] = true;
Nan Zhou07ffa4e2022-08-09 22:46:25 +0000110 protocolFeatures["SelectQuery"] = true;
Nan Zhou96299072022-03-23 09:13:46 -0700111 protocolFeatures["DeepOperations"]["DeepPOST"] = false;
112 protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
John Edward Broadbent83388912021-06-29 10:46:46 -0700113}
Patrick Williams504af5a2025-02-03 14:29:03 -0500114inline void handleServiceRootGet(
115 App& app, const crow::Request& req,
116 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous5b224922022-06-22 19:00:59 -0700117{
Ed Tanous01a89a12022-08-05 09:18:54 -0700118 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
119 {
120 return;
121 }
122
Ed Tanous5b224922022-06-22 19:00:59 -0700123 handleServiceRootGetImpl(asyncResp);
124}
John Edward Broadbent83388912021-06-29 10:46:46 -0700125
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700126inline void requestRoutesServiceRoot(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700127{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700128 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanous5b224922022-06-22 19:00:59 -0700129 .privileges(redfish::privileges::headServiceRoot)
130 .methods(boost::beast::http::verb::head)(
131 std::bind_front(handleServiceRootHead, std::ref(app)));
132 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanoused398212021-06-09 17:05:54 -0700133 .privileges(redfish::privileges::getServiceRoot)
Ed Tanous7cf436c2022-03-22 23:53:51 -0700134 .methods(boost::beast::http::verb::get)(
Ed Tanous5b224922022-06-22 19:00:59 -0700135 std::bind_front(handleServiceRootGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700136}
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100137
Ed Tanous1abe55e2018-09-05 08:30:59 -0700138} // namespace redfish