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 18 #include "node.hpp" 19 #include "registries.hpp" 20 #include "registries/base_message_registry.hpp" 21 #include "registries/openbmc_message_registry.hpp" 22 23 namespace redfish 24 { 25 26 class MessageRegistryFileCollection : public Node 27 { 28 public: 29 template <typename CrowApp> 30 MessageRegistryFileCollection(CrowApp &app) : 31 Node(app, "/redfish/v1/Registries/") 32 { 33 entityPrivileges = { 34 {boost::beast::http::verb::get, {{"Login"}}}, 35 {boost::beast::http::verb::head, {{"Login"}}}, 36 {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 37 {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 38 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 39 {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 40 } 41 42 private: 43 /** 44 * Functions triggers appropriate requests on DBus 45 */ 46 void doGet(crow::Response &res, const crow::Request &req, 47 const std::vector<std::string> ¶ms) override 48 { 49 // Collections don't include the static data added by SubRoute because 50 // it has a duplicate entry for members 51 52 res.jsonValue = { 53 {"@odata.type", 54 "#MessageRegistryFileCollection.MessageRegistryFileCollection"}, 55 {"@odata.context", "/redfish/v1/" 56 "$metadata#MessageRegistryFileCollection." 57 "MessageRegistryFileCollection"}, 58 {"@odata.id", "/redfish/v1/Registries"}, 59 {"Name", "MessageRegistryFile Collection"}, 60 {"Description", "Collection of MessageRegistryFiles"}, 61 {"Members@odata.count", 2}, 62 {"Members", 63 {{{"@odata.id", "/redfish/v1/Registries/Base"}}, 64 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}}; 65 66 res.end(); 67 } 68 }; 69 70 class BaseMessageRegistryFile : public Node 71 { 72 public: 73 template <typename CrowApp> 74 BaseMessageRegistryFile(CrowApp &app) : 75 Node(app, "/redfish/v1/Registries/Base/") 76 { 77 entityPrivileges = { 78 {boost::beast::http::verb::get, {{"Login"}}}, 79 {boost::beast::http::verb::head, {{"Login"}}}, 80 {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 81 {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 82 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 83 {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 84 } 85 86 private: 87 void doGet(crow::Response &res, const crow::Request &req, 88 const std::vector<std::string> ¶ms) override 89 { 90 res.jsonValue = { 91 {"@odata.id", "/redfish/v1/Registries/Base"}, 92 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"}, 93 {"@odata.context", 94 "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile"}, 95 {"Name", "Base Message Registry File"}, 96 {"Description", "DMTF Base Message Registry File Location"}, 97 {"Id", message_registries::base::header.registryPrefix}, 98 {"Registry", message_registries::base::header.id}, 99 {"Languages", {"en"}}, 100 {"Languages@odata.count", 1}, 101 {"Location", 102 {{{"Language", "en"}, 103 {"PublicationUri", 104 "https://redfish.dmtf.org/registries/Base.1.4.0.json"}, 105 {"Uri", "/redfish/v1/Registries/Base/Base"}}}}, 106 {"Location@odata.count", 1}}; 107 res.end(); 108 } 109 }; 110 111 class BaseMessageRegistry : public Node 112 { 113 public: 114 template <typename CrowApp> 115 BaseMessageRegistry(CrowApp &app) : 116 Node(app, "/redfish/v1/Registries/Base/Base/") 117 { 118 entityPrivileges = { 119 {boost::beast::http::verb::get, {{"Login"}}}, 120 {boost::beast::http::verb::head, {{"Login"}}}, 121 {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 122 {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 123 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 124 {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 125 } 126 127 private: 128 void doGet(crow::Response &res, const crow::Request &req, 129 const std::vector<std::string> ¶ms) override 130 { 131 res.jsonValue = { 132 {"@Redfish.Copyright", message_registries::base::header.copyright}, 133 {"@odata.type", message_registries::base::header.type}, 134 {"Id", message_registries::base::header.id}, 135 {"Name", message_registries::base::header.name}, 136 {"Language", message_registries::base::header.language}, 137 {"Description", message_registries::base::header.description}, 138 {"RegistryPrefix", message_registries::base::header.registryPrefix}, 139 {"RegistryVersion", 140 message_registries::base::header.registryVersion}, 141 {"OwningEntity", message_registries::base::header.owningEntity}}; 142 143 nlohmann::json &messageObj = res.jsonValue["Messages"]; 144 145 // Go through the Message Registry and populate each Message 146 for (const message_registries::MessageEntry &message : 147 message_registries::base::registry) 148 { 149 nlohmann::json &obj = messageObj[message.first]; 150 obj = {{"Description", message.second.description}, 151 {"Message", message.second.message}, 152 {"Severity", message.second.severity}, 153 {"NumberOfArgs", message.second.numberOfArgs}, 154 {"Resolution", message.second.resolution}}; 155 if (message.second.numberOfArgs > 0) 156 { 157 nlohmann::json &messageParamArray = obj["ParamTypes"]; 158 for (const char *str : message.second.paramTypes) 159 { 160 if (str == nullptr) 161 { 162 break; 163 } 164 messageParamArray.push_back(str); 165 } 166 } 167 } 168 res.end(); 169 } 170 }; 171 172 class OpenBMCMessageRegistryFile : public Node 173 { 174 public: 175 template <typename CrowApp> 176 OpenBMCMessageRegistryFile(CrowApp &app) : 177 Node(app, "/redfish/v1/Registries/OpenBMC/") 178 { 179 entityPrivileges = { 180 {boost::beast::http::verb::get, {{"Login"}}}, 181 {boost::beast::http::verb::head, {{"Login"}}}, 182 {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 183 {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 184 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 185 {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 186 } 187 188 private: 189 void doGet(crow::Response &res, const crow::Request &req, 190 const std::vector<std::string> ¶ms) override 191 { 192 res.jsonValue = { 193 {"@odata.id", "/redfish/v1/Registries/OpenBMC"}, 194 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"}, 195 {"@odata.context", 196 "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile"}, 197 {"Name", "Open BMC Message Registry File"}, 198 {"Description", "Open BMC Message Registry File Location"}, 199 {"Id", message_registries::openbmc::header.registryPrefix}, 200 {"Registry", message_registries::openbmc::header.id}, 201 {"Languages", {"en"}}, 202 {"Languages@odata.count", 1}, 203 {"Location", 204 {{{"Language", "en"}, 205 {"Uri", "/redfish/v1/Registries/OpenBMC/OpenBMC"}}}}, 206 {"Location@odata.count", 1}}; 207 208 res.end(); 209 } 210 }; 211 212 class OpenBMCMessageRegistry : public Node 213 { 214 public: 215 template <typename CrowApp> 216 OpenBMCMessageRegistry(CrowApp &app) : 217 Node(app, "/redfish/v1/Registries/OpenBMC/OpenBMC/") 218 { 219 entityPrivileges = { 220 {boost::beast::http::verb::get, {{"Login"}}}, 221 {boost::beast::http::verb::head, {{"Login"}}}, 222 {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 223 {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 224 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 225 {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 226 } 227 228 private: 229 void doGet(crow::Response &res, const crow::Request &req, 230 const std::vector<std::string> ¶ms) override 231 { 232 res.jsonValue = { 233 {"@Redfish.Copyright", 234 message_registries::openbmc::header.copyright}, 235 {"@odata.type", message_registries::openbmc::header.type}, 236 {"Id", message_registries::openbmc::header.id}, 237 {"Name", message_registries::openbmc::header.name}, 238 {"Language", message_registries::openbmc::header.language}, 239 {"Description", message_registries::openbmc::header.description}, 240 {"RegistryPrefix", 241 message_registries::openbmc::header.registryPrefix}, 242 {"RegistryVersion", 243 message_registries::openbmc::header.registryVersion}, 244 {"OwningEntity", message_registries::openbmc::header.owningEntity}}; 245 246 nlohmann::json &messageObj = res.jsonValue["Messages"]; 247 // Go through the Message Registry and populate each Message 248 for (const message_registries::MessageEntry &message : 249 message_registries::openbmc::registry) 250 { 251 nlohmann::json &obj = messageObj[message.first]; 252 obj = {{"Description", message.second.description}, 253 {"Message", message.second.message}, 254 {"Severity", message.second.severity}, 255 {"NumberOfArgs", message.second.numberOfArgs}, 256 {"Resolution", message.second.resolution}}; 257 if (message.second.numberOfArgs > 0) 258 { 259 nlohmann::json &messageParamArray = obj["ParamTypes"]; 260 for (size_t i = 0; i < message.second.numberOfArgs; i++) 261 { 262 messageParamArray.push_back(message.second.paramTypes[i]); 263 } 264 } 265 } 266 res.end(); 267 } 268 }; 269 270 } // namespace redfish 271