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