Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 1 | /* |
| 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. |
| 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" |
| 21 | #include "registries/base_message_registry.hpp" |
Jason M. Bills | fbe8378 | 2019-03-27 14:14:53 -0700 | [diff] [blame] | 22 | #include "registries/openbmc_message_registry.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 23 | #include "registries/privilege_registry.hpp" |
Sunitha Harish | 74eec26 | 2020-06-25 10:00:01 -0500 | [diff] [blame] | 24 | #include "registries/resource_event_message_registry.hpp" |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 25 | #include "registries/task_event_message_registry.hpp" |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 26 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 27 | #include <boost/url/format.hpp> |
| 28 | |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 29 | #include <array> |
| 30 | |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 31 | namespace redfish |
| 32 | { |
| 33 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 34 | inline void handleMessageRegistryFileCollectionGet( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 35 | crow::App& app, const crow::Request& req, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 36 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 37 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 38 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 39 | { |
| 40 | return; |
| 41 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 42 | // Collections don't include the static data added by SubRoute |
| 43 | // because it has a duplicate entry for members |
| 44 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 45 | asyncResp->res.jsonValue["@odata.type"] = |
| 46 | "#MessageRegistryFileCollection.MessageRegistryFileCollection"; |
| 47 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries"; |
| 48 | asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection"; |
| 49 | asyncResp->res.jsonValue["Description"] = |
| 50 | "Collection of MessageRegistryFiles"; |
| 51 | asyncResp->res.jsonValue["Members@odata.count"] = 4; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 52 | |
| 53 | nlohmann::json& members = asyncResp->res.jsonValue["Members"]; |
| 54 | for (const char* memberName : |
| 55 | std::to_array({"Base", "TaskEvent", "ResourceEvent", "OpenBMC"})) |
| 56 | { |
| 57 | nlohmann::json::object_t member; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 58 | member["@odata.id"] = boost::urls::format("/redfish/v1/Registries/{}", |
| 59 | memberName); |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 60 | members.emplace_back(std::move(member)); |
| 61 | } |
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 | } |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 84 | const registries::Header* header = nullptr; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 85 | std::string dmtf = "DMTF "; |
| 86 | const char* url = nullptr; |
| 87 | |
| 88 | if (registry == "Base") |
| 89 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 90 | header = ®istries::base::header; |
| 91 | url = registries::base::url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 92 | } |
| 93 | else if (registry == "TaskEvent") |
| 94 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 95 | header = ®istries::task_event::header; |
| 96 | url = registries::task_event::url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 97 | } |
| 98 | else if (registry == "OpenBMC") |
| 99 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 100 | header = ®istries::openbmc::header; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 101 | dmtf.clear(); |
| 102 | } |
| 103 | else if (registry == "ResourceEvent") |
| 104 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 105 | header = ®istries::resource_event::header; |
| 106 | url = registries::resource_event::url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 107 | } |
| 108 | else |
| 109 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 110 | messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", |
| 111 | registry); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 112 | return; |
| 113 | } |
| 114 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 115 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 116 | boost::urls::format("/redfish/v1/Registries/{}", registry); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 117 | asyncResp->res.jsonValue["@odata.type"] = |
| 118 | "#MessageRegistryFile.v1_1_0.MessageRegistryFile"; |
| 119 | asyncResp->res.jsonValue["Name"] = registry + " Message Registry File"; |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 120 | asyncResp->res.jsonValue["Description"] = dmtf + registry + |
| 121 | " Message Registry File Location"; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 122 | asyncResp->res.jsonValue["Id"] = header->registryPrefix; |
| 123 | asyncResp->res.jsonValue["Registry"] = header->id; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 124 | nlohmann::json::array_t languages; |
Alexander Paramonov | 3ad903a | 2024-04-23 16:35:40 +0300 | [diff] [blame] | 125 | languages.emplace_back(header->language); |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 126 | asyncResp->res.jsonValue["Languages@odata.count"] = languages.size(); |
| 127 | asyncResp->res.jsonValue["Languages"] = std::move(languages); |
| 128 | nlohmann::json::array_t locationMembers; |
| 129 | nlohmann::json::object_t location; |
Alexander Paramonov | 3ad903a | 2024-04-23 16:35:40 +0300 | [diff] [blame] | 130 | location["Language"] = header->language; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 131 | location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 132 | |
| 133 | if (url != nullptr) |
| 134 | { |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 135 | location["PublicationUri"] = url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 136 | } |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 137 | locationMembers.emplace_back(std::move(location)); |
| 138 | asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size(); |
| 139 | asyncResp->res.jsonValue["Location"] = std::move(locationMembers); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 140 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 141 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 142 | inline void requestRoutesMessageRegistryFile(App& app) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 143 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 144 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 145 | .privileges(redfish::privileges::getMessageRegistryFile) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 146 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 147 | handleMessageRoutesMessageRegistryFileGet, std::ref(app))); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 148 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 149 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 150 | inline void handleMessageRegistryGet( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 151 | crow::App& app, const crow::Request& req, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 152 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 153 | const std::string& registry, const std::string& registryMatch) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 154 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 155 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 156 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 157 | { |
| 158 | return; |
| 159 | } |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 160 | const registries::Header* header = nullptr; |
| 161 | std::vector<const registries::MessageEntry*> registryEntries; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 162 | if (registry == "Base") |
| 163 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 164 | header = ®istries::base::header; |
| 165 | for (const registries::MessageEntry& entry : registries::base::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 166 | { |
| 167 | registryEntries.emplace_back(&entry); |
| 168 | } |
| 169 | } |
| 170 | else if (registry == "TaskEvent") |
| 171 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 172 | header = ®istries::task_event::header; |
| 173 | for (const registries::MessageEntry& entry : |
| 174 | registries::task_event::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 175 | { |
| 176 | registryEntries.emplace_back(&entry); |
| 177 | } |
| 178 | } |
| 179 | else if (registry == "OpenBMC") |
| 180 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 181 | header = ®istries::openbmc::header; |
| 182 | for (const registries::MessageEntry& entry : |
| 183 | registries::openbmc::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 184 | { |
| 185 | registryEntries.emplace_back(&entry); |
| 186 | } |
| 187 | } |
| 188 | else if (registry == "ResourceEvent") |
| 189 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 190 | header = ®istries::resource_event::header; |
| 191 | for (const registries::MessageEntry& entry : |
| 192 | registries::resource_event::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 193 | { |
| 194 | registryEntries.emplace_back(&entry); |
| 195 | } |
| 196 | } |
| 197 | else |
| 198 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 199 | messages::resourceNotFound(asyncResp->res, "MessageRegistryFile", |
| 200 | registry); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 201 | return; |
| 202 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 203 | |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 204 | if (registry != registryMatch) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 205 | { |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 206 | messages::resourceNotFound(asyncResp->res, header->type, registryMatch); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 207 | return; |
| 208 | } |
| 209 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 210 | asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright; |
| 211 | asyncResp->res.jsonValue["@odata.type"] = header->type; |
| 212 | asyncResp->res.jsonValue["Id"] = header->id; |
| 213 | asyncResp->res.jsonValue["Name"] = header->name; |
| 214 | asyncResp->res.jsonValue["Language"] = header->language; |
| 215 | asyncResp->res.jsonValue["Description"] = header->description; |
| 216 | asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix; |
| 217 | asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion; |
| 218 | asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 219 | |
| 220 | nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; |
| 221 | |
| 222 | // Go through the Message Registry and populate each Message |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 223 | for (const registries::MessageEntry* message : registryEntries) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 224 | { |
| 225 | nlohmann::json& obj = messageObj[message->first]; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 226 | obj["Description"] = message->second.description; |
| 227 | obj["Message"] = message->second.message; |
| 228 | obj["Severity"] = message->second.messageSeverity; |
| 229 | obj["MessageSeverity"] = message->second.messageSeverity; |
| 230 | obj["NumberOfArgs"] = message->second.numberOfArgs; |
| 231 | obj["Resolution"] = message->second.resolution; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 232 | if (message->second.numberOfArgs > 0) |
| 233 | { |
| 234 | nlohmann::json& messageParamArray = obj["ParamTypes"]; |
| 235 | messageParamArray = nlohmann::json::array(); |
| 236 | for (const char* str : message->second.paramTypes) |
| 237 | { |
| 238 | if (str == nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 239 | { |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 240 | break; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 241 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 242 | messageParamArray.push_back(str); |
| 243 | } |
| 244 | } |
| 245 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | inline void requestRoutesMessageRegistry(App& app) |
| 249 | { |
| 250 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 251 | .privileges(redfish::privileges::getMessageRegistryFile) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 252 | .methods(boost::beast::http::verb::get)( |
| 253 | std::bind_front(handleMessageRegistryGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 254 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 255 | } // namespace redfish |