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