Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
Ed Tanous | f4c99e7 | 2021-10-04 17:02:43 -0700 | [diff] [blame] | 7 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 8 | #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 Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 14 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 15 | #include <boost/beast/http/field.hpp> |
| 16 | #include <boost/beast/http/verb.hpp> |
| 17 | #include <boost/url/format.hpp> |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 18 | #include <nlohmann/json.hpp> |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 19 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 20 | #include <functional> |
| 21 | #include <memory> |
| 22 | #include <string> |
| 23 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 24 | namespace redfish |
| 25 | { |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 26 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 27 | inline void handleServiceRootHead( |
| 28 | App& app, const crow::Request& req, |
| 29 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 30 | { |
| 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 | |
| 41 | inline void handleServiceRootGetImpl( |
| 42 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 43 | { |
Ed Tanous | 01a89a1 | 2022-08-05 09:18:54 -0700 | [diff] [blame] | 44 | asyncResp->res.addHeader( |
| 45 | boost::beast::http::field::link, |
| 46 | "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby"); |
| 47 | |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 48 | std::string uuid = persistent_data::getConfig().systemUuid; |
Shantappa Teekappanavar | 9c929be | 2021-12-16 19:02:52 -0600 | [diff] [blame] | 49 | asyncResp->res.jsonValue["@odata.type"] = |
Ed Tanous | e68d1be | 2023-01-27 10:42:32 -0800 | [diff] [blame] | 50 | "#ServiceRoot.v1_15_0.ServiceRoot"; |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 51 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1"; |
| 52 | asyncResp->res.jsonValue["Id"] = "RootService"; |
| 53 | asyncResp->res.jsonValue["Name"] = "Root Service"; |
Ed Tanous | c16e292 | 2022-07-15 12:46:02 -0700 | [diff] [blame] | 54 | asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0"; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 55 | asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] = |
| 56 | "/redfish/v1/SessionService/Sessions"; |
| 57 | asyncResp->res.jsonValue["AccountService"]["@odata.id"] = |
| 58 | "/redfish/v1/AccountService"; |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 59 | if constexpr (BMCWEB_REDFISH_AGGREGATION) |
| 60 | { |
| 61 | asyncResp->res.jsonValue["AggregationService"]["@odata.id"] = |
| 62 | "/redfish/v1/AggregationService"; |
| 63 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 64 | 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 Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 75 | asyncResp->res.jsonValue["UUID"] = uuid; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 76 | 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 Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 84 | |
Ed Tanous | e68d1be | 2023-01-27 10:42:32 -0800 | [diff] [blame] | 85 | asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 86 | boost::urls::format("/redfish/v1/Managers/{}", |
| 87 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | e68d1be | 2023-01-27 10:42:32 -0800 | [diff] [blame] | 88 | |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 89 | nlohmann::json& protocolFeatures = |
| 90 | asyncResp->res.jsonValue["ProtocolFeaturesSupported"]; |
| 91 | protocolFeatures["ExcerptQuery"] = false; |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 92 | |
| 93 | protocolFeatures["ExpandQuery"]["ExpandAll"] = |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 94 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 95 | // This is the maximum level defined in ServiceRoot.v1_13_0.json |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 96 | if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY) |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 97 | { |
| 98 | protocolFeatures["ExpandQuery"]["MaxLevels"] = 6; |
| 99 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 100 | protocolFeatures["ExpandQuery"]["Levels"] = |
| 101 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
| 102 | protocolFeatures["ExpandQuery"]["Links"] = |
| 103 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 104 | protocolFeatures["ExpandQuery"]["NoLinks"] = |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 105 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
Ed Tanous | 25991f7 | 2024-06-13 18:10:25 -0700 | [diff] [blame] | 106 | protocolFeatures["FilterQuery"] = BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
Nan Zhou | 0553fb5 | 2022-08-05 17:23:06 +0000 | [diff] [blame] | 107 | protocolFeatures["OnlyMemberQuery"] = true; |
Nan Zhou | 07ffa4e | 2022-08-09 22:46:25 +0000 | [diff] [blame] | 108 | protocolFeatures["SelectQuery"] = true; |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 109 | protocolFeatures["DeepOperations"]["DeepPOST"] = false; |
| 110 | protocolFeatures["DeepOperations"]["DeepPATCH"] = false; |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 111 | } |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 112 | inline void handleServiceRootGet( |
| 113 | App& app, const crow::Request& req, |
| 114 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 115 | { |
Ed Tanous | 01a89a1 | 2022-08-05 09:18:54 -0700 | [diff] [blame] | 116 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 117 | { |
| 118 | return; |
| 119 | } |
| 120 | |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 121 | handleServiceRootGetImpl(asyncResp); |
| 122 | } |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 123 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 124 | inline void requestRoutesServiceRoot(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 125 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 126 | BMCWEB_ROUTE(app, "/redfish/v1/") |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 127 | .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 Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 131 | .privileges(redfish::privileges::getServiceRoot) |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 132 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 133 | std::bind_front(handleServiceRootGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 134 | } |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 135 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 136 | } // namespace redfish |