blob: 96ce0c2006f9ff8f35ef4f791ca250f34bc99dfc [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 {
Jason M. Bills70304cb2019-03-27 12:03:59 -070049 // Collections don't include the static data added by SubRoute because
50 // it has a duplicate entry for members
Ed Tanous14c8aee2019-06-13 13:39:16 -070051
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();
Jason M. Bills70304cb2019-03-27 12:03:59 -070067 }
68};
69
70class 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> &params) override
89 {
Ed Tanous14c8aee2019-06-13 13:39:16 -070090 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();
Jason M. Bills70304cb2019-03-27 12:03:59 -0700108 }
109};
110
111class 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> &params) override
130 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700131 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}};
Jason M. Bills70304cb2019-03-27 12:03:59 -0700142
Ed Tanous14c8aee2019-06-13 13:39:16 -0700143 nlohmann::json &messageObj = res.jsonValue["Messages"];
Jason M. Bills70304cb2019-03-27 12:03:59 -0700144
145 // Go through the Message Registry and populate each Message
146 for (const message_registries::MessageEntry &message :
147 message_registries::base::registry)
148 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700149 nlohmann::json &obj = messageObj[message.first];
150 obj = {{"Description", message.second.description},
Jason M. Bills70304cb2019-03-27 12:03:59 -0700151 {"Message", message.second.message},
152 {"Severity", message.second.severity},
153 {"NumberOfArgs", message.second.numberOfArgs},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700154 {"Resolution", message.second.resolution}};
Jason M. Bills70304cb2019-03-27 12:03:59 -0700155 if (message.second.numberOfArgs > 0)
156 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700157 nlohmann::json &messageParamArray = obj["ParamTypes"];
Jason M. Bills70304cb2019-03-27 12:03:59 -0700158 for (const char *str : message.second.paramTypes)
159 {
160 if (str == nullptr)
161 {
162 break;
163 }
164 messageParamArray.push_back(str);
165 }
166 }
167 }
Ed Tanous14c8aee2019-06-13 13:39:16 -0700168 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -0700169 }
170};
171
Jason M. Billsfbe83782019-03-27 14:14:53 -0700172class 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> &params) override
191 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700192 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}};
Jason M. Billsfbe83782019-03-27 14:14:53 -0700207
Ed Tanous14c8aee2019-06-13 13:39:16 -0700208 res.end();
Jason M. Billsfbe83782019-03-27 14:14:53 -0700209 }
210};
211
212class 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> &params) override
231 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700232 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}};
Jason M. Billsfbe83782019-03-27 14:14:53 -0700245
Ed Tanous14c8aee2019-06-13 13:39:16 -0700246 nlohmann::json &messageObj = res.jsonValue["Messages"];
Jason M. Billsfbe83782019-03-27 14:14:53 -0700247 // Go through the Message Registry and populate each Message
248 for (const message_registries::MessageEntry &message :
249 message_registries::openbmc::registry)
250 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700251 nlohmann::json &obj = messageObj[message.first];
252 obj = {{"Description", message.second.description},
Jason M. Billsfbe83782019-03-27 14:14:53 -0700253 {"Message", message.second.message},
254 {"Severity", message.second.severity},
255 {"NumberOfArgs", message.second.numberOfArgs},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700256 {"Resolution", message.second.resolution}};
Jason M. Billsfbe83782019-03-27 14:14:53 -0700257 if (message.second.numberOfArgs > 0)
258 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700259 nlohmann::json &messageParamArray = obj["ParamTypes"];
Ed Tanous271584a2019-07-09 16:24:22 -0700260 for (size_t i = 0; i < message.second.numberOfArgs; i++)
Jason M. Billsfbe83782019-03-27 14:14:53 -0700261 {
262 messageParamArray.push_back(message.second.paramTypes[i]);
263 }
264 }
265 }
Ed Tanous14c8aee2019-06-13 13:39:16 -0700266 res.end();
Jason M. Billsfbe83782019-03-27 14:14:53 -0700267 }
268};
269
Jason M. Bills70304cb2019-03-27 12:03:59 -0700270} // namespace redfish