blob: 34f0e318fa7d4cf9a2aa3eb0293a4834a481eadc [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"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080014
Ed Tanousd7857202025-01-28 15:32:26 -080015#include <boost/beast/http/field.hpp>
16#include <boost/beast/http/verb.hpp>
17#include <boost/url/format.hpp>
Nan Zhou96299072022-03-23 09:13:46 -070018#include <nlohmann/json.hpp>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010019
Ed Tanousd7857202025-01-28 15:32:26 -080020#include <functional>
21#include <memory>
22#include <string>
23
Ed Tanous1abe55e2018-09-05 08:30:59 -070024namespace redfish
25{
Ed Tanous3ebd75f2018-03-05 18:20:01 -080026
Patrick Williams504af5a2025-02-03 14:29:03 -050027inline void handleServiceRootHead(
28 App& app, const crow::Request& req,
29 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous5b224922022-06-22 19:00:59 -070030{
31 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
32 {
33 return;
34 }
35
36 asyncResp->res.addHeader(
37 boost::beast::http::field::link,
38 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
39}
40
41inline void handleServiceRootGetImpl(
42 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbent83388912021-06-29 10:46:46 -070043{
Ed Tanous01a89a12022-08-05 09:18:54 -070044 asyncResp->res.addHeader(
45 boost::beast::http::field::link,
46 "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby");
47
John Edward Broadbent83388912021-06-29 10:46:46 -070048 std::string uuid = persistent_data::getConfig().systemUuid;
Shantappa Teekappanavar9c929be2021-12-16 19:02:52 -060049 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanouse68d1be2023-01-27 10:42:32 -080050 "#ServiceRoot.v1_15_0.ServiceRoot";
John Edward Broadbent83388912021-06-29 10:46:46 -070051 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
52 asyncResp->res.jsonValue["Id"] = "RootService";
53 asyncResp->res.jsonValue["Name"] = "Root Service";
Ed Tanousc16e2922022-07-15 12:46:02 -070054 asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0";
Ed Tanous14766872022-03-15 10:44:42 -070055 asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] =
56 "/redfish/v1/SessionService/Sessions";
57 asyncResp->res.jsonValue["AccountService"]["@odata.id"] =
58 "/redfish/v1/AccountService";
Ed Tanous25b54db2024-04-17 15:40:31 -070059 if constexpr (BMCWEB_REDFISH_AGGREGATION)
60 {
61 asyncResp->res.jsonValue["AggregationService"]["@odata.id"] =
62 "/redfish/v1/AggregationService";
63 }
Ed Tanous14766872022-03-15 10:44:42 -070064 asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis";
65 asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] =
66 "/redfish/v1/JsonSchemas";
67 asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers";
68 asyncResp->res.jsonValue["SessionService"]["@odata.id"] =
69 "/redfish/v1/SessionService";
70 asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems";
71 asyncResp->res.jsonValue["Registries"]["@odata.id"] =
72 "/redfish/v1/Registries";
73 asyncResp->res.jsonValue["UpdateService"]["@odata.id"] =
74 "/redfish/v1/UpdateService";
John Edward Broadbent83388912021-06-29 10:46:46 -070075 asyncResp->res.jsonValue["UUID"] = uuid;
Ed Tanous14766872022-03-15 10:44:42 -070076 asyncResp->res.jsonValue["CertificateService"]["@odata.id"] =
77 "/redfish/v1/CertificateService";
78 asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService";
79 asyncResp->res.jsonValue["EventService"]["@odata.id"] =
80 "/redfish/v1/EventService";
81 asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] =
82 "/redfish/v1/TelemetryService";
83 asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables";
Nan Zhou96299072022-03-23 09:13:46 -070084
Ed Tanouse68d1be2023-01-27 10:42:32 -080085 asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] =
Ed Tanous253f11b2024-05-16 09:38:31 -070086 boost::urls::format("/redfish/v1/Managers/{}",
87 BMCWEB_REDFISH_MANAGER_URI_NAME);
Ed Tanouse68d1be2023-01-27 10:42:32 -080088
Nan Zhou96299072022-03-23 09:13:46 -070089 nlohmann::json& protocolFeatures =
90 asyncResp->res.jsonValue["ProtocolFeaturesSupported"];
91 protocolFeatures["ExcerptQuery"] = false;
Ed Tanous7cf436c2022-03-22 23:53:51 -070092
93 protocolFeatures["ExpandQuery"]["ExpandAll"] =
Ed Tanous25b54db2024-04-17 15:40:31 -070094 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -070095 // This is the maximum level defined in ServiceRoot.v1_13_0.json
Ed Tanous25b54db2024-04-17 15:40:31 -070096 if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY)
Ed Tanous7cf436c2022-03-22 23:53:51 -070097 {
98 protocolFeatures["ExpandQuery"]["MaxLevels"] = 6;
99 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700100 protocolFeatures["ExpandQuery"]["Levels"] =
101 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
102 protocolFeatures["ExpandQuery"]["Links"] =
103 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous7cf436c2022-03-22 23:53:51 -0700104 protocolFeatures["ExpandQuery"]["NoLinks"] =
Ed Tanous25b54db2024-04-17 15:40:31 -0700105 BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Ed Tanous25991f72024-06-13 18:10:25 -0700106 protocolFeatures["FilterQuery"] = BMCWEB_INSECURE_ENABLE_REDFISH_QUERY;
Nan Zhou0553fb52022-08-05 17:23:06 +0000107 protocolFeatures["OnlyMemberQuery"] = true;
Nan Zhou07ffa4e2022-08-09 22:46:25 +0000108 protocolFeatures["SelectQuery"] = true;
Nan Zhou96299072022-03-23 09:13:46 -0700109 protocolFeatures["DeepOperations"]["DeepPOST"] = false;
110 protocolFeatures["DeepOperations"]["DeepPATCH"] = false;
John Edward Broadbent83388912021-06-29 10:46:46 -0700111}
Patrick Williams504af5a2025-02-03 14:29:03 -0500112inline void handleServiceRootGet(
113 App& app, const crow::Request& req,
114 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous5b224922022-06-22 19:00:59 -0700115{
Ed Tanous01a89a12022-08-05 09:18:54 -0700116 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
117 {
118 return;
119 }
120
Ed Tanous5b224922022-06-22 19:00:59 -0700121 handleServiceRootGetImpl(asyncResp);
122}
John Edward Broadbent83388912021-06-29 10:46:46 -0700123
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700124inline void requestRoutesServiceRoot(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700125{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700126 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanous5b224922022-06-22 19:00:59 -0700127 .privileges(redfish::privileges::headServiceRoot)
128 .methods(boost::beast::http::verb::head)(
129 std::bind_front(handleServiceRootHead, std::ref(app)));
130 BMCWEB_ROUTE(app, "/redfish/v1/")
Ed Tanoused398212021-06-09 17:05:54 -0700131 .privileges(redfish::privileges::getServiceRoot)
Ed Tanous7cf436c2022-03-22 23:53:51 -0700132 .methods(boost::beast::http::verb::get)(
Ed Tanous5b224922022-06-22 19:00:59 -0700133 std::bind_front(handleServiceRootGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700134}
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +0100135
Ed Tanous1abe55e2018-09-05 08:30:59 -0700136} // namespace redfish