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 | { |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 35 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 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 | |
| 42 | asyncResp->res.jsonValue = { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 43 | {"@odata.type", |
| 44 | "#MessageRegistryFileCollection.MessageRegistryFileCollection"}, |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 45 | {"@odata.id", "/redfish/v1/Registries"}, |
| 46 | {"Name", "MessageRegistryFile Collection"}, |
| 47 | {"Description", "Collection of MessageRegistryFiles"}, |
| 48 | {"Members@odata.count", 4}, |
| 49 | {"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"}}}}}; |
| 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 | { |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 72 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 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 | |
| 108 | asyncResp->res.jsonValue = { |
| 109 | {"@odata.id", "/redfish/v1/Registries/" + registry}, |
| 110 | {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"}, |
| 111 | {"Name", registry + " Message Registry File"}, |
| 112 | {"Description", dmtf + registry + " Message Registry File Location"}, |
| 113 | {"Id", header->registryPrefix}, |
| 114 | {"Registry", header->id}, |
| 115 | {"Languages", {"en"}}, |
| 116 | {"Languages@odata.count", 1}, |
| 117 | {"Location", |
| 118 | {{{"Language", "en"}, |
| 119 | {"Uri", "/redfish/v1/Registries/" + registry + "/" + registry}}}}, |
| 120 | {"Location@odata.count", 1}}; |
| 121 | |
| 122 | if (url != nullptr) |
| 123 | { |
| 124 | asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url; |
| 125 | } |
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 | { |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 142 | if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) |
| 143 | { |
| 144 | return; |
| 145 | } |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 146 | const registries::Header* header = nullptr; |
| 147 | std::vector<const registries::MessageEntry*> registryEntries; |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 148 | if (registry == "Base") |
| 149 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 150 | header = ®istries::base::header; |
| 151 | for (const registries::MessageEntry& entry : registries::base::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 152 | { |
| 153 | registryEntries.emplace_back(&entry); |
| 154 | } |
| 155 | } |
| 156 | else if (registry == "TaskEvent") |
| 157 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 158 | header = ®istries::task_event::header; |
| 159 | for (const registries::MessageEntry& entry : |
| 160 | registries::task_event::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 161 | { |
| 162 | registryEntries.emplace_back(&entry); |
| 163 | } |
| 164 | } |
| 165 | else if (registry == "OpenBMC") |
| 166 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 167 | header = ®istries::openbmc::header; |
| 168 | for (const registries::MessageEntry& entry : |
| 169 | registries::openbmc::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 170 | { |
| 171 | registryEntries.emplace_back(&entry); |
| 172 | } |
| 173 | } |
| 174 | else if (registry == "ResourceEvent") |
| 175 | { |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 176 | header = ®istries::resource_event::header; |
| 177 | for (const registries::MessageEntry& entry : |
| 178 | registries::resource_event::registry) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 179 | { |
| 180 | registryEntries.emplace_back(&entry); |
| 181 | } |
| 182 | } |
| 183 | else |
| 184 | { |
| 185 | messages::resourceNotFound( |
| 186 | asyncResp->res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile", |
| 187 | registry); |
| 188 | return; |
| 189 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 190 | |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 191 | if (registry != registryMatch) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 192 | { |
John Edward Broadbent | 6e8c18f | 2021-09-27 13:11:38 -0700 | [diff] [blame] | 193 | messages::resourceNotFound(asyncResp->res, header->type, registryMatch); |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 194 | return; |
| 195 | } |
| 196 | |
| 197 | asyncResp->res.jsonValue = {{"@Redfish.Copyright", header->copyright}, |
| 198 | {"@odata.type", header->type}, |
| 199 | {"Id", header->id}, |
| 200 | {"Name", header->name}, |
| 201 | {"Language", header->language}, |
| 202 | {"Description", header->description}, |
| 203 | {"RegistryPrefix", header->registryPrefix}, |
| 204 | {"RegistryVersion", header->registryVersion}, |
| 205 | {"OwningEntity", header->owningEntity}}; |
| 206 | |
| 207 | nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"]; |
| 208 | |
| 209 | // Go through the Message Registry and populate each Message |
Ed Tanous | fffb8c1 | 2022-02-07 23:53:03 -0800 | [diff] [blame] | 210 | for (const registries::MessageEntry* message : registryEntries) |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 211 | { |
| 212 | nlohmann::json& obj = messageObj[message->first]; |
| 213 | obj = {{"Description", message->second.description}, |
| 214 | {"Message", message->second.message}, |
Ed Tanous | 5f2b84e | 2022-02-08 00:41:53 -0800 | [diff] [blame] | 215 | {"Severity", message->second.messageSeverity}, |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 216 | {"MessageSeverity", message->second.messageSeverity}, |
| 217 | {"NumberOfArgs", message->second.numberOfArgs}, |
| 218 | {"Resolution", message->second.resolution}}; |
| 219 | if (message->second.numberOfArgs > 0) |
| 220 | { |
| 221 | nlohmann::json& messageParamArray = obj["ParamTypes"]; |
| 222 | messageParamArray = nlohmann::json::array(); |
| 223 | for (const char* str : message->second.paramTypes) |
| 224 | { |
| 225 | if (str == nullptr) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 226 | { |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 227 | break; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 228 | } |
John Edward Broadbent | dff0782 | 2021-07-13 11:20:47 -0700 | [diff] [blame] | 229 | messageParamArray.push_back(str); |
| 230 | } |
| 231 | } |
| 232 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | inline void requestRoutesMessageRegistry(App& app) |
| 236 | { |
| 237 | BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 238 | .privileges(redfish::privileges::getMessageRegistryFile) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame^] | 239 | .methods(boost::beast::http::verb::get)( |
| 240 | std::bind_front(handleMessageRegistryGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 241 | } |
Jason M. Bills | 70304cb | 2019-03-27 12:03:59 -0700 | [diff] [blame] | 242 | } // namespace redfish |