blob: 31412f3eac23253bc6e7b7ea330db065001179eb [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001/*
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"
Jason M. Billsfbe83782019-03-27 14:14:53 -070021#include "registries/openbmc_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070022
23namespace redfish
24{
25
26class 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> &params) override
48 {
49 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
50 // Collections don't include the static data added by SubRoute because
51 // it has a duplicate entry for members
52 asyncResp->res.jsonValue["@odata.type"] =
53 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
54 asyncResp->res.jsonValue["@odata.context"] =
55 "/redfish/v1/"
56 "$metadata#MessageRegistryFileCollection."
57 "MessageRegistryFileCollection";
58 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
59 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
60 asyncResp->res.jsonValue["Description"] =
61 "Collection of MessageRegistryFiles";
62 nlohmann::json &messageRegistryFileArray =
63 asyncResp->res.jsonValue["Members"];
64 messageRegistryFileArray = nlohmann::json::array();
65 messageRegistryFileArray.push_back(
66 {{"@odata.id", "/redfish/v1/Registries/Base"}});
67 messageRegistryFileArray.push_back(
68 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}});
69 asyncResp->res.jsonValue["Members@odata.count"] =
70 messageRegistryFileArray.size();
71 }
72};
73
74class BaseMessageRegistryFile : public Node
75{
76 public:
77 template <typename CrowApp>
78 BaseMessageRegistryFile(CrowApp &app) :
79 Node(app, "/redfish/v1/Registries/Base/")
80 {
81 entityPrivileges = {
82 {boost::beast::http::verb::get, {{"Login"}}},
83 {boost::beast::http::verb::head, {{"Login"}}},
84 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
85 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
86 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
87 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
88 }
89
90 private:
91 void doGet(crow::Response &res, const crow::Request &req,
92 const std::vector<std::string> &params) override
93 {
94 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
95
96 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries/Base";
97 asyncResp->res.jsonValue["@odata.type"] =
98 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
99 asyncResp->res.jsonValue["@odata.context"] =
100 "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
101 asyncResp->res.jsonValue["Name"] = "Base Message Registry File";
102 asyncResp->res.jsonValue["Description"] =
103 "DMTF Base Message Registry File Location";
Jason M. Bills351d3062019-03-27 12:58:21 -0700104 asyncResp->res.jsonValue["Id"] =
105 message_registries::base::header.registryPrefix;
106 asyncResp->res.jsonValue["Registry"] =
107 message_registries::base::header.id;
Jason M. Bills70304cb2019-03-27 12:03:59 -0700108 nlohmann::json &messageRegistryLanguageArray =
109 asyncResp->res.jsonValue["Languages"];
110 messageRegistryLanguageArray = nlohmann::json::array();
111 messageRegistryLanguageArray.push_back({"en"});
112 asyncResp->res.jsonValue["Languages@odata.count"] =
113 messageRegistryLanguageArray.size();
114 nlohmann::json &messageRegistryLocationArray =
115 asyncResp->res.jsonValue["Location"];
116 messageRegistryLocationArray = nlohmann::json::array();
117 messageRegistryLocationArray.push_back(
118 {{"Language", "en"},
119 {"PublicationUri",
120 "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
121 {"Uri", "/redfish/v1/Registries/Base/Base"}});
122 asyncResp->res.jsonValue["Location@odata.count"] =
123 messageRegistryLocationArray.size();
124 }
125};
126
127class BaseMessageRegistry : public Node
128{
129 public:
130 template <typename CrowApp>
131 BaseMessageRegistry(CrowApp &app) :
132 Node(app, "/redfish/v1/Registries/Base/Base/")
133 {
134 entityPrivileges = {
135 {boost::beast::http::verb::get, {{"Login"}}},
136 {boost::beast::http::verb::head, {{"Login"}}},
137 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
138 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
139 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
140 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
141 }
142
143 private:
144 void doGet(crow::Response &res, const crow::Request &req,
145 const std::vector<std::string> &params) override
146 {
147 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
148
149 asyncResp->res.jsonValue["@Redfish.Copyright"] =
Jason M. Bills351d3062019-03-27 12:58:21 -0700150 message_registries::base::header.copyright;
Jason M. Bills70304cb2019-03-27 12:03:59 -0700151 asyncResp->res.jsonValue["@odata.type"] =
Jason M. Bills351d3062019-03-27 12:58:21 -0700152 message_registries::base::header.type;
153 asyncResp->res.jsonValue["Id"] = message_registries::base::header.id;
154 asyncResp->res.jsonValue["Name"] =
155 message_registries::base::header.name;
156 asyncResp->res.jsonValue["Language"] =
157 message_registries::base::header.language;
Jason M. Bills70304cb2019-03-27 12:03:59 -0700158 asyncResp->res.jsonValue["Description"] =
Jason M. Bills351d3062019-03-27 12:58:21 -0700159 message_registries::base::header.description;
160 asyncResp->res.jsonValue["RegistryPrefix"] =
161 message_registries::base::header.registryPrefix;
162 asyncResp->res.jsonValue["RegistryVersion"] =
163 message_registries::base::header.registryVersion;
164 asyncResp->res.jsonValue["OwningEntity"] =
165 message_registries::base::header.owningEntity;
Jason M. Bills70304cb2019-03-27 12:03:59 -0700166 nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
167 messageArray = nlohmann::json::array();
168
169 // Go through the Message Registry and populate each Message
170 for (const message_registries::MessageEntry &message :
171 message_registries::base::registry)
172 {
173 messageArray.push_back(
174 {{message.first,
175 {{"Description", message.second.description},
176 {"Message", message.second.message},
177 {"Severity", message.second.severity},
178 {"NumberOfArgs", message.second.numberOfArgs},
179 {"Resolution", message.second.resolution}}}});
180 if (message.second.numberOfArgs > 0)
181 {
182 nlohmann::json &messageParamArray =
183 messageArray.back()[message.first]["ParamTypes"];
184 for (const char *str : message.second.paramTypes)
185 {
186 if (str == nullptr)
187 {
188 break;
189 }
190 messageParamArray.push_back(str);
191 }
192 }
193 }
194 }
195};
196
Jason M. Billsfbe83782019-03-27 14:14:53 -0700197class OpenBMCMessageRegistryFile : public Node
198{
199 public:
200 template <typename CrowApp>
201 OpenBMCMessageRegistryFile(CrowApp &app) :
202 Node(app, "/redfish/v1/Registries/OpenBMC/")
203 {
204 entityPrivileges = {
205 {boost::beast::http::verb::get, {{"Login"}}},
206 {boost::beast::http::verb::head, {{"Login"}}},
207 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
208 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
209 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
210 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
211 }
212
213 private:
214 void doGet(crow::Response &res, const crow::Request &req,
215 const std::vector<std::string> &params) override
216 {
217 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
218
219 asyncResp->res.jsonValue["@odata.id"] =
220 "/redfish/v1/Registries/OpenBMC";
221 asyncResp->res.jsonValue["@odata.type"] =
222 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
223 asyncResp->res.jsonValue["@odata.context"] =
224 "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
225 asyncResp->res.jsonValue["Name"] = "Open BMC Message Registry File";
226 asyncResp->res.jsonValue["Description"] =
227 "Open BMC Message Registry File Location";
228 asyncResp->res.jsonValue["Id"] =
229 message_registries::openbmc::header.registryPrefix;
230 asyncResp->res.jsonValue["Registry"] =
231 message_registries::openbmc::header.id;
232 nlohmann::json &messageRegistryLanguageArray =
233 asyncResp->res.jsonValue["Languages"];
234 messageRegistryLanguageArray = nlohmann::json::array();
235 messageRegistryLanguageArray.push_back({"en"});
236 asyncResp->res.jsonValue["Languages@odata.count"] =
237 messageRegistryLanguageArray.size();
238 nlohmann::json &messageRegistryLocationArray =
239 asyncResp->res.jsonValue["Location"];
240 messageRegistryLocationArray = nlohmann::json::array();
241 messageRegistryLocationArray.push_back(
242 {{"Language", "en"},
243 {"Uri", "/redfish/v1/Registries/OpenBMC/OpenBMC"}});
244 asyncResp->res.jsonValue["Location@odata.count"] =
245 messageRegistryLocationArray.size();
246 }
247};
248
249class OpenBMCMessageRegistry : public Node
250{
251 public:
252 template <typename CrowApp>
253 OpenBMCMessageRegistry(CrowApp &app) :
254 Node(app, "/redfish/v1/Registries/OpenBMC/OpenBMC/")
255 {
256 entityPrivileges = {
257 {boost::beast::http::verb::get, {{"Login"}}},
258 {boost::beast::http::verb::head, {{"Login"}}},
259 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
260 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
261 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
262 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
263 }
264
265 private:
266 void doGet(crow::Response &res, const crow::Request &req,
267 const std::vector<std::string> &params) override
268 {
269 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
270
271 asyncResp->res.jsonValue["@Redfish.Copyright"] =
272 message_registries::openbmc::header.copyright;
273 asyncResp->res.jsonValue["@odata.type"] =
274 message_registries::openbmc::header.type;
275 asyncResp->res.jsonValue["Id"] = message_registries::openbmc::header.id;
276 asyncResp->res.jsonValue["Name"] =
277 message_registries::openbmc::header.name;
278 asyncResp->res.jsonValue["Language"] =
279 message_registries::openbmc::header.language;
280 asyncResp->res.jsonValue["Description"] =
281 message_registries::openbmc::header.description;
282 asyncResp->res.jsonValue["RegistryPrefix"] =
283 message_registries::openbmc::header.registryPrefix;
284 asyncResp->res.jsonValue["RegistryVersion"] =
285 message_registries::openbmc::header.registryVersion;
286 asyncResp->res.jsonValue["OwningEntity"] =
287 message_registries::openbmc::header.owningEntity;
288 nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
289 messageArray = nlohmann::json::array();
290
291 // Go through the Message Registry and populate each Message
292 for (const message_registries::MessageEntry &message :
293 message_registries::openbmc::registry)
294 {
295 messageArray.push_back(
296 {{message.first,
297 {{"Description", message.second.description},
298 {"Message", message.second.message},
299 {"Severity", message.second.severity},
300 {"NumberOfArgs", message.second.numberOfArgs},
301 {"Resolution", message.second.resolution}}}});
302 if (message.second.numberOfArgs > 0)
303 {
304 nlohmann::json &messageParamArray =
305 messageArray.back()[message.first]["ParamTypes"];
306 for (int i = 0; i < message.second.numberOfArgs; i++)
307 {
308 messageParamArray.push_back(message.second.paramTypes[i]);
309 }
310 }
311 }
312 }
313};
314
Jason M. Bills70304cb2019-03-27 12:03:59 -0700315} // namespace redfish