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