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 |
Ed Tanous | d5c0172 | 2024-06-16 12:10:33 -0700 | [diff] [blame] | 3 | #pragma once |
| 4 | |
| 5 | #include "app.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 6 | #include "async_resp.hpp" |
Ed Tanous | d5c0172 | 2024-06-16 12:10:33 -0700 | [diff] [blame] | 7 | #include "http_request.hpp" |
| 8 | #include "http_response.hpp" |
Ed Tanous | d5c0172 | 2024-06-16 12:10:33 -0700 | [diff] [blame] | 9 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 10 | #include <boost/beast/http/verb.hpp> |
Ed Tanous | d5c0172 | 2024-06-16 12:10:33 -0700 | [diff] [blame] | 11 | #include <boost/url/format.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include <boost/url/url.hpp> |
Ed Tanous | d5c0172 | 2024-06-16 12:10:33 -0700 | [diff] [blame] | 13 | #include <nlohmann/json.hpp> |
| 14 | |
| 15 | #include <memory> |
| 16 | #include <ranges> |
| 17 | #include <string> |
| 18 | #include <string_view> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 19 | #include <utility> |
Ed Tanous | d5c0172 | 2024-06-16 12:10:33 -0700 | [diff] [blame] | 20 | |
| 21 | namespace redfish |
| 22 | { |
| 23 | |
| 24 | inline void redfishOdataGet(const crow::Request& /*req*/, |
| 25 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 26 | { |
| 27 | nlohmann::json::object_t obj; |
| 28 | obj["@odata.context"] = "/redfish/v1/$metadata"; |
| 29 | nlohmann::json::array_t value; |
| 30 | for (std::string_view service : |
| 31 | {"$metadata", "odata", "JsonSchemas", "Service", "ServiceRoot", |
| 32 | "Systems", "Chassis", "Managers", "SessionService", "AccountService", |
| 33 | "UpdateService"}) |
| 34 | { |
| 35 | nlohmann::json::object_t serviceObj; |
| 36 | serviceObj["kind"] = "Singleton"; |
| 37 | serviceObj["name"] = "$metadata"; |
| 38 | boost::urls::url url = boost::urls::format("/redfish/v1/{}", service); |
| 39 | if (service == "Service") |
| 40 | { |
| 41 | url = boost::urls::url("/redfish/v1"); |
| 42 | } |
| 43 | serviceObj["url"] = url; |
| 44 | value.emplace_back(std::move(serviceObj)); |
| 45 | } |
| 46 | |
| 47 | obj["value"] = std::move(value); |
| 48 | |
| 49 | asyncResp->res.jsonValue = std::move(obj); |
| 50 | } |
| 51 | |
| 52 | inline void requestRoutesOdata(App& app) |
| 53 | { |
| 54 | BMCWEB_ROUTE(app, "/redfish/v1/odata/") |
| 55 | .methods(boost::beast::http::verb::get)(redfishOdataGet); |
| 56 | } |
| 57 | |
| 58 | } // namespace redfish |