Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 1 | /* |
| 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 Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "bmcweb_config.h" |
Ed Tanous | f4c99e7 | 2021-10-04 17:02:43 -0700 | [diff] [blame] | 19 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "app.hpp" |
| 21 | #include "async_resp.hpp" |
| 22 | #include "http_request.hpp" |
| 23 | #include "persistent_data.hpp" |
| 24 | #include "query.hpp" |
| 25 | #include "registries/privilege_registry.hpp" |
| 26 | #include "utils/systemd_utils.hpp" |
| 27 | |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 28 | #include <nlohmann/json.hpp> |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 29 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 30 | namespace redfish |
| 31 | { |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 32 | |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 33 | inline void |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 34 | handleServiceRootHead(App& app, const crow::Request& req, |
| 35 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 36 | { |
| 37 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 38 | { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | asyncResp->res.addHeader( |
| 43 | boost::beast::http::field::link, |
| 44 | "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby"); |
| 45 | } |
| 46 | |
| 47 | inline void handleServiceRootGetImpl( |
| 48 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 49 | { |
Ed Tanous | 01a89a1 | 2022-08-05 09:18:54 -0700 | [diff] [blame] | 50 | asyncResp->res.addHeader( |
| 51 | boost::beast::http::field::link, |
| 52 | "</redfish/v1/JsonSchemas/ServiceRoot/ServiceRoot.json>; rel=describedby"); |
| 53 | |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 54 | std::string uuid = persistent_data::getConfig().systemUuid; |
Shantappa Teekappanavar | 9c929be | 2021-12-16 19:02:52 -0600 | [diff] [blame] | 55 | asyncResp->res.jsonValue["@odata.type"] = |
Ed Tanous | e68d1be | 2023-01-27 10:42:32 -0800 | [diff] [blame] | 56 | "#ServiceRoot.v1_15_0.ServiceRoot"; |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 57 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1"; |
| 58 | asyncResp->res.jsonValue["Id"] = "RootService"; |
| 59 | asyncResp->res.jsonValue["Name"] = "Root Service"; |
Ed Tanous | c16e292 | 2022-07-15 12:46:02 -0700 | [diff] [blame] | 60 | asyncResp->res.jsonValue["RedfishVersion"] = "1.17.0"; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 61 | asyncResp->res.jsonValue["Links"]["Sessions"]["@odata.id"] = |
| 62 | "/redfish/v1/SessionService/Sessions"; |
| 63 | asyncResp->res.jsonValue["AccountService"]["@odata.id"] = |
| 64 | "/redfish/v1/AccountService"; |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 65 | if constexpr (BMCWEB_REDFISH_AGGREGATION) |
| 66 | { |
| 67 | asyncResp->res.jsonValue["AggregationService"]["@odata.id"] = |
| 68 | "/redfish/v1/AggregationService"; |
| 69 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 70 | asyncResp->res.jsonValue["Chassis"]["@odata.id"] = "/redfish/v1/Chassis"; |
| 71 | asyncResp->res.jsonValue["JsonSchemas"]["@odata.id"] = |
| 72 | "/redfish/v1/JsonSchemas"; |
| 73 | asyncResp->res.jsonValue["Managers"]["@odata.id"] = "/redfish/v1/Managers"; |
| 74 | asyncResp->res.jsonValue["SessionService"]["@odata.id"] = |
| 75 | "/redfish/v1/SessionService"; |
| 76 | asyncResp->res.jsonValue["Systems"]["@odata.id"] = "/redfish/v1/Systems"; |
| 77 | asyncResp->res.jsonValue["Registries"]["@odata.id"] = |
| 78 | "/redfish/v1/Registries"; |
| 79 | asyncResp->res.jsonValue["UpdateService"]["@odata.id"] = |
| 80 | "/redfish/v1/UpdateService"; |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 81 | asyncResp->res.jsonValue["UUID"] = uuid; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 82 | asyncResp->res.jsonValue["CertificateService"]["@odata.id"] = |
| 83 | "/redfish/v1/CertificateService"; |
| 84 | asyncResp->res.jsonValue["Tasks"]["@odata.id"] = "/redfish/v1/TaskService"; |
| 85 | asyncResp->res.jsonValue["EventService"]["@odata.id"] = |
| 86 | "/redfish/v1/EventService"; |
| 87 | asyncResp->res.jsonValue["TelemetryService"]["@odata.id"] = |
| 88 | "/redfish/v1/TelemetryService"; |
| 89 | asyncResp->res.jsonValue["Cables"]["@odata.id"] = "/redfish/v1/Cables"; |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 90 | |
Ed Tanous | e68d1be | 2023-01-27 10:42:32 -0800 | [diff] [blame] | 91 | asyncResp->res.jsonValue["Links"]["ManagerProvidingService"]["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame^] | 92 | boost::urls::format("/redfish/v1/Managers/{}", |
| 93 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | e68d1be | 2023-01-27 10:42:32 -0800 | [diff] [blame] | 94 | |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 95 | nlohmann::json& protocolFeatures = |
| 96 | asyncResp->res.jsonValue["ProtocolFeaturesSupported"]; |
| 97 | protocolFeatures["ExcerptQuery"] = false; |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 98 | |
| 99 | protocolFeatures["ExpandQuery"]["ExpandAll"] = |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 100 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 101 | // This is the maximum level defined in ServiceRoot.v1_13_0.json |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 102 | if constexpr (BMCWEB_INSECURE_ENABLE_REDFISH_QUERY) |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 103 | { |
| 104 | protocolFeatures["ExpandQuery"]["MaxLevels"] = 6; |
| 105 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 106 | protocolFeatures["ExpandQuery"]["Levels"] = |
| 107 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
| 108 | protocolFeatures["ExpandQuery"]["Links"] = |
| 109 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 110 | protocolFeatures["ExpandQuery"]["NoLinks"] = |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 111 | BMCWEB_INSECURE_ENABLE_REDFISH_QUERY; |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 112 | protocolFeatures["FilterQuery"] = false; |
Nan Zhou | 0553fb5 | 2022-08-05 17:23:06 +0000 | [diff] [blame] | 113 | protocolFeatures["OnlyMemberQuery"] = true; |
Nan Zhou | 07ffa4e | 2022-08-09 22:46:25 +0000 | [diff] [blame] | 114 | protocolFeatures["SelectQuery"] = true; |
Nan Zhou | 9629907 | 2022-03-23 09:13:46 -0700 | [diff] [blame] | 115 | protocolFeatures["DeepOperations"]["DeepPOST"] = false; |
| 116 | protocolFeatures["DeepOperations"]["DeepPATCH"] = false; |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 117 | } |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 118 | inline void |
| 119 | handleServiceRootGet(App& app, const crow::Request& req, |
| 120 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 121 | { |
Ed Tanous | 01a89a1 | 2022-08-05 09:18:54 -0700 | [diff] [blame] | 122 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 123 | { |
| 124 | return; |
| 125 | } |
| 126 | |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 127 | handleServiceRootGetImpl(asyncResp); |
| 128 | } |
John Edward Broadbent | 8338891 | 2021-06-29 10:46:46 -0700 | [diff] [blame] | 129 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 130 | inline void requestRoutesServiceRoot(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 131 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 132 | BMCWEB_ROUTE(app, "/redfish/v1/") |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 133 | .privileges(redfish::privileges::headServiceRoot) |
| 134 | .methods(boost::beast::http::verb::head)( |
| 135 | std::bind_front(handleServiceRootHead, std::ref(app))); |
| 136 | BMCWEB_ROUTE(app, "/redfish/v1/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 137 | .privileges(redfish::privileges::getServiceRoot) |
Ed Tanous | 7cf436c | 2022-03-22 23:53:51 -0700 | [diff] [blame] | 138 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 5b22492 | 2022-06-22 19:00:59 -0700 | [diff] [blame] | 139 | std::bind_front(handleServiceRootGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 140 | } |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 141 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 142 | } // namespace redfish |