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