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