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 | |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 18 | #include "registries.hpp" |
| 19 | #include "registries/base_message_registry.hpp" |
Jason M. Bills | fbe8378 | 2019-03-27 14:14:53 -0700 | [diff] [blame] | 20 | #include "registries/openbmc_message_registry.hpp" |
Sunitha Harish | 74eec26 | 2020-06-25 10:00:01 -0500 | [diff] [blame] | 21 | #include "registries/resource_event_message_registry.hpp" |
James Feist | e51c710 | 2020-03-17 10:38:18 -0700 | [diff] [blame] | 22 | #include "registries/task_event_message_registry.hpp" |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 23 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 24 | #include <app.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 25 | #include <query.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 26 | #include <registries/privilege_registry.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -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"; |
| 48 | asyncResp->res.jsonValue["Members@odata.count"] = 4; |
| 49 | asyncResp->res.jsonValue["Members"] = { |
| 50 | {{"@odata.id", "/redfish/v1/Registries/Base"}}, |
| 51 | {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}}, |
| 52 | {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}}, |
| 53 | {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 54 | } |
| 55 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 56 | inline void requestRoutesMessageRegistryFileCollection(App& app) |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 57 | { |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Functions triggers appropriate requests on DBus |
| 60 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 61 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 62 | .privileges(redfish::privileges::getMessageRegistryFileCollection) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 63 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 64 | handleMessageRegistryFileCollectionGet, std::ref(app))); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 65 | } |
Ed Tanous | 14c8aee | 2019-06-13 13:39:16 -0700 | [diff] [blame] | 66 | |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 67 | inline void handleMessageRoutesMessageRegistryFileGet( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 68 | crow::App& app, const crow::Request& req, |
Ed Tanous | 104f09c | 2022-01-25 09:56:04 -0800 | [diff] [blame] | 69 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 70 | const std::string& registry) |
| 71 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 72 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 73 | { |
| 74 | return; |
| 75 | } |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 76 | const registries::Header* header = nullptr; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 77 | std::string dmtf = "DMTF "; |
| 78 | const char* url = nullptr; |
| 79 | |
| 80 | if (registry == "Base") |
| 81 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 82 | header = ®istries::base::header; |
| 83 | url = registries::base::url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 84 | } |
| 85 | else if (registry == "TaskEvent") |
| 86 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 87 | header = ®istries::task_event::header; |
| 88 | url = registries::task_event::url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 89 | } |
| 90 | else if (registry == "OpenBMC") |
| 91 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 92 | header = ®istries::openbmc::header; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 93 | dmtf.clear(); |
| 94 | } |
| 95 | else if (registry == "ResourceEvent") |
| 96 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 97 | header = ®istries::resource_event::header; |
| 98 | url = registries::resource_event::url; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 99 | } |
| 100 | else |
| 101 | { |
| 102 | messages::resourceNotFound( |
| 103 | asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile", |
| 104 | registry); |
| 105 | return; |
| 106 | } |
| 107 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 108 | asyncResp->res.jsonValue["@odata.id"] = |
| 109 | "/redfish/v1/Registries/" + registry; |
| 110 | asyncResp->res.jsonValue["@odata.type"] = |
| 111 | "#MessageRegistryFile.v1_1_0.MessageRegistryFile"; |
| 112 | asyncResp->res.jsonValue["Name"] = registry + " Message Registry File"; |
| 113 | asyncResp->res.jsonValue["Description"] = |
| 114 | dmtf + registry + " Message Registry File Location"; |
| 115 | asyncResp->res.jsonValue["Id"] = header->registryPrefix; |
| 116 | asyncResp->res.jsonValue["Registry"] = header->id; |
| 117 | asyncResp->res.jsonValue["Languages"] = {"en"}; |
| 118 | asyncResp->res.jsonValue["Languages@odata.count"] = 1; |
| 119 | asyncResp->res.jsonValue["Location"] = { |
| 120 | {{"Language", "en"}, |
| 121 | {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}}; |
| 122 | |
| 123 | asyncResp->res.jsonValue["Location@odata.count"] = 1; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 124 | |
| 125 | if (url != nullptr) |
| 126 | { |
| 127 | asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url; |
| 128 | } |
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 | } |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 149 | const registries::Header* header = nullptr; |
| 150 | std::vector<const registries::MessageEntry*> registryEntries; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 151 | if (registry == "Base") |
| 152 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 153 | header = ®istries::base::header; |
| 154 | for (const registries::MessageEntry& entry : registries::base::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 155 | { |
| 156 | registryEntries.emplace_back(&entry); |
| 157 | } |
| 158 | } |
| 159 | else if (registry == "TaskEvent") |
| 160 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 161 | header = ®istries::task_event::header; |
| 162 | for (const registries::MessageEntry& entry : |
| 163 | registries::task_event::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 == "OpenBMC") |
| 169 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 170 | header = ®istries::openbmc::header; |
| 171 | for (const registries::MessageEntry& entry : |
| 172 | registries::openbmc::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 == "ResourceEvent") |
| 178 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 179 | header = ®istries::resource_event::header; |
| 180 | for (const registries::MessageEntry& entry : |
| 181 | registries::resource_event::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 182 | { |
| 183 | registryEntries.emplace_back(&entry); |
| 184 | } |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | messages::resourceNotFound( |
| 189 | asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile", |
| 190 | registry); |
| 191 | return; |
| 192 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 193 | |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 194 | if (registry != registryMatch) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 195 | { |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 196 | messages::resourceNotFound(asyncResp->res, header->type, registryMatch); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 197 | return; |
| 198 | } |
| 199 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 200 | asyncResp->res.jsonValue["@Redfish.Copyright"] = header->copyright; |
| 201 | asyncResp->res.jsonValue["@odata.type"] = header->type; |
| 202 | asyncResp->res.jsonValue["Id"] = header->id; |
| 203 | asyncResp->res.jsonValue["Name"] = header->name; |
| 204 | asyncResp->res.jsonValue["Language"] = header->language; |
| 205 | asyncResp->res.jsonValue["Description"] = header->description; |
| 206 | asyncResp->res.jsonValue["RegistryPrefix"] = header->registryPrefix; |
| 207 | asyncResp->res.jsonValue["RegistryVersion"] = header->registryVersion; |
| 208 | asyncResp->res.jsonValue["OwningEntity"] = header->owningEntity; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 209 | |
| 210 | nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; |
| 211 | |
| 212 | // Go through the Message Registry and populate each Message |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 213 | for (const registries::MessageEntry* message : registryEntries) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 214 | { |
| 215 | nlohmann::json& obj = messageObj[message->first]; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 216 | obj["Description"] = message->second.description; |
| 217 | obj["Message"] = message->second.message; |
| 218 | obj["Severity"] = message->second.messageSeverity; |
| 219 | obj["MessageSeverity"] = message->second.messageSeverity; |
| 220 | obj["NumberOfArgs"] = message->second.numberOfArgs; |
| 221 | obj["Resolution"] = message->second.resolution; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 222 | if (message->second.numberOfArgs > 0) |
| 223 | { |
| 224 | nlohmann::json& messageParamArray = obj["ParamTypes"]; |
| 225 | messageParamArray = nlohmann::json::array(); |
| 226 | for (const char* str : message->second.paramTypes) |
| 227 | { |
| 228 | if (str == nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 229 | { |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 230 | break; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 231 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 232 | messageParamArray.push_back(str); |
| 233 | } |
| 234 | } |
| 235 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | inline void requestRoutesMessageRegistry(App& app) |
| 239 | { |
| 240 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 241 | .privileges(redfish::privileges::getMessageRegistryFile) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 242 | .methods(boost::beast::http::verb::get)( |
| 243 | std::bind_front(handleMessageRegistryGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 244 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 245 | } // namespace redfish |