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