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