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 2019 Intel Corporation |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 6 | #include "app.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 7 | #include "async_resp.hpp" |
| 8 | #include "error_messages.hpp" |
| 9 | #include "http_request.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 10 | #include "query.hpp" |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 11 | #include "registries.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include "registries/privilege_registry.hpp" |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 13 | #include "registries_selector.hpp" |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 14 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 15 | #include <boost/beast/http/verb.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 16 | #include <boost/url/format.hpp> |
| 17 | |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 18 | #include <array> |
Ed Tanous | 56b8199 | 2024-12-02 10:36:37 -0800 | [diff] [blame] | 19 | #include <format> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 20 | #include <functional> |
| 21 | #include <memory> |
| 22 | #include <optional> |
| 23 | #include <span> |
| 24 | #include <utility> |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 25 | |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 26 | namespace redfish |
| 27 | { |
| 28 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 29 | inline void handleMessageRegistryFileCollectionGet( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 30 | crow::App& app, const crow::Request& req, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 31 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 32 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 33 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 34 | { |
| 35 | return; |
| 36 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 37 | // Collections don't include the static data added by SubRoute |
| 38 | // because it has a duplicate entry for members |
| 39 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 40 | asyncResp->res.jsonValue["@odata.type"] = |
| 41 | "#MessageRegistryFileCollection.MessageRegistryFileCollection"; |
| 42 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries"; |
| 43 | asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection"; |
| 44 | asyncResp->res.jsonValue["Description"] = |
| 45 | "Collection of MessageRegistryFiles"; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 46 | |
| 47 | nlohmann::json& members = asyncResp->res.jsonValue["Members"]; |
Myung Bae | fb54610 | 2024-10-29 10:21:26 -0500 | [diff] [blame] | 48 | |
| 49 | static constexpr const auto registryFiles = std::to_array( |
| 50 | {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry", |
| 51 | "HeartbeatEvent"}); |
| 52 | |
| 53 | for (const char* memberName : registryFiles) |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 54 | { |
| 55 | nlohmann::json::object_t member; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 56 | member["@odata.id"] = |
| 57 | boost::urls::format("/redfish/v1/Registries/{}", memberName); |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 58 | members.emplace_back(std::move(member)); |
| 59 | } |
Myung Bae | fb54610 | 2024-10-29 10:21:26 -0500 | [diff] [blame] | 60 | asyncResp->res.jsonValue["Members@odata.count"] = members.size(); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 61 | } |
| 62 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 63 | inline void requestRoutesMessageRegistryFileCollection(App& app) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 64 | { |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Functions triggers appropriate requests on DBus |
| 67 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 68 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 69 | .privileges(redfish::privileges::getMessageRegistryFileCollection) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 70 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 71 | handleMessageRegistryFileCollectionGet, std::ref(app))); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 72 | } |
Ed Tanous | 14c8aee | 2019-06-13 13:39:16 -0700 | [diff] [blame] | 73 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 74 | inline void handleMessageRoutesMessageRegistryFileGet( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 75 | crow::App& app, const crow::Request& req, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 76 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 77 | const std::string& registry) |
| 78 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 79 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 80 | { |
| 81 | return; |
| 82 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 83 | std::string dmtf = "DMTF "; |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 84 | std::optional<registries::HeaderAndUrl> headerAndUrl = |
| 85 | registries::getRegistryHeaderAndUrlFromPrefix(registry); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 86 | |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 87 | if (!headerAndUrl) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 88 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 89 | messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", |
| 90 | registry); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 91 | return; |
| 92 | } |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 93 | if (registry == "OpenBMC") |
| 94 | { |
| 95 | dmtf.clear(); |
| 96 | } |
| 97 | const registries::Header& header = headerAndUrl->header; |
| 98 | const char* url = headerAndUrl->url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 99 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 100 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 101 | boost::urls::format("/redfish/v1/Registries/{}", registry); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 102 | asyncResp->res.jsonValue["@odata.type"] = |
| 103 | "#MessageRegistryFile.v1_1_0.MessageRegistryFile"; |
| 104 | asyncResp->res.jsonValue["Name"] = registry + " Message Registry File"; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 105 | asyncResp->res.jsonValue["Description"] = |
| 106 | dmtf + registry + " Message Registry File Location"; |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 107 | asyncResp->res.jsonValue["Id"] = header.registryPrefix; |
Ed Tanous | 56b8199 | 2024-12-02 10:36:37 -0800 | [diff] [blame] | 108 | asyncResp->res.jsonValue["Registry"] = |
| 109 | std::format("{}.{}.{}", header.registryPrefix, header.versionMajor, |
| 110 | header.versionMinor); |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 111 | nlohmann::json::array_t languages; |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 112 | languages.emplace_back(header.language); |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 113 | asyncResp->res.jsonValue["Languages@odata.count"] = languages.size(); |
| 114 | asyncResp->res.jsonValue["Languages"] = std::move(languages); |
| 115 | nlohmann::json::array_t locationMembers; |
| 116 | nlohmann::json::object_t location; |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 117 | location["Language"] = header.language; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 118 | location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 119 | |
| 120 | if (url != nullptr) |
| 121 | { |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 122 | location["PublicationUri"] = url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 123 | } |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 124 | locationMembers.emplace_back(std::move(location)); |
| 125 | asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size(); |
| 126 | asyncResp->res.jsonValue["Location"] = std::move(locationMembers); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 127 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 128 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 129 | inline void requestRoutesMessageRegistryFile(App& app) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 130 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 131 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 132 | .privileges(redfish::privileges::getMessageRegistryFile) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 133 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 134 | handleMessageRoutesMessageRegistryFileGet, std::ref(app))); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 135 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 136 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 137 | inline void handleMessageRegistryGet( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 138 | crow::App& app, const crow::Request& req, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 139 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 140 | const std::string& registry, const std::string& registryMatch) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 141 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 142 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 143 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 144 | { |
| 145 | return; |
| 146 | } |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 147 | |
| 148 | std::optional<registries::HeaderAndUrl> headerAndUrl = |
| 149 | registries::getRegistryHeaderAndUrlFromPrefix(registry); |
| 150 | if (!headerAndUrl) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 151 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 152 | messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", |
| 153 | registry); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 154 | return; |
| 155 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 156 | |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 157 | const registries::Header& header = headerAndUrl->header; |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 158 | if (registry != registryMatch) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 159 | { |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 160 | messages::resourceNotFound(asyncResp->res, header.type, registryMatch); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 164 | asyncResp->res.jsonValue["@Redfish.Copyright"] = header.copyright; |
| 165 | asyncResp->res.jsonValue["@odata.type"] = header.type; |
Ed Tanous | 56b8199 | 2024-12-02 10:36:37 -0800 | [diff] [blame] | 166 | asyncResp->res.jsonValue["Id"] = |
| 167 | std::format("{}.{}.{}.{}", header.registryPrefix, header.versionMajor, |
| 168 | header.versionMinor, header.versionPatch); |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 169 | asyncResp->res.jsonValue["Name"] = header.name; |
| 170 | asyncResp->res.jsonValue["Language"] = header.language; |
| 171 | asyncResp->res.jsonValue["Description"] = header.description; |
| 172 | asyncResp->res.jsonValue["RegistryPrefix"] = header.registryPrefix; |
Ed Tanous | 56b8199 | 2024-12-02 10:36:37 -0800 | [diff] [blame] | 173 | asyncResp->res.jsonValue["RegistryVersion"] = |
| 174 | std::format("{}.{}.{}", header.versionMajor, header.versionMinor, |
| 175 | header.versionPatch); |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 176 | asyncResp->res.jsonValue["OwningEntity"] = header.owningEntity; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 177 | |
| 178 | nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; |
| 179 | |
| 180 | // Go through the Message Registry and populate each Message |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 181 | const std::span<const registries::MessageEntry> registryEntries = |
| 182 | registries::getRegistryFromPrefix(registry); |
| 183 | |
| 184 | for (const registries::MessageEntry& message : registryEntries) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 185 | { |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 186 | nlohmann::json& obj = messageObj[message.first]; |
| 187 | obj["Description"] = message.second.description; |
| 188 | obj["Message"] = message.second.message; |
| 189 | obj["Severity"] = message.second.messageSeverity; |
| 190 | obj["MessageSeverity"] = message.second.messageSeverity; |
| 191 | obj["NumberOfArgs"] = message.second.numberOfArgs; |
| 192 | obj["Resolution"] = message.second.resolution; |
| 193 | if (message.second.numberOfArgs > 0) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 194 | { |
| 195 | nlohmann::json& messageParamArray = obj["ParamTypes"]; |
| 196 | messageParamArray = nlohmann::json::array(); |
Myung Bae | f7a2607 | 2024-12-04 10:08:59 -0600 | [diff] [blame] | 197 | for (const char* str : message.second.paramTypes) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 198 | { |
| 199 | if (str == nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 200 | { |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 201 | break; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 202 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 203 | messageParamArray.push_back(str); |
| 204 | } |
| 205 | } |
| 206 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | inline void requestRoutesMessageRegistry(App& app) |
| 210 | { |
| 211 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 212 | .privileges(redfish::privileges::getMessageRegistryFile) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 213 | .methods(boost::beast::http::verb::get)( |
| 214 | std::bind_front(handleMessageRegistryGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 215 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 216 | } // namespace redfish |