blob: 57e0ad2433d563cc8914e01bf7853484211ae10f [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"
Sunitha Harish74eec262020-06-25 10:00:01 -050022#include "registries/resource_event_message_registry.hpp"
James Feiste51c7102020-03-17 10:38:18 -070023#include "registries/task_event_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070024
25namespace redfish
26{
27
28class MessageRegistryFileCollection : public Node
29{
30 public:
31 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050032 MessageRegistryFileCollection(CrowApp& app) :
Jason M. Bills70304cb2019-03-27 12:03:59 -070033 Node(app, "/redfish/v1/Registries/")
34 {
35 entityPrivileges = {
36 {boost::beast::http::verb::get, {{"Login"}}},
37 {boost::beast::http::verb::head, {{"Login"}}},
38 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
39 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
40 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
41 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
42 }
43
44 private:
45 /**
46 * Functions triggers appropriate requests on DBus
47 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -050048 void doGet(crow::Response& res, const crow::Request& req,
49 const std::vector<std::string>& params) override
Jason M. Bills70304cb2019-03-27 12:03:59 -070050 {
Jason M. Bills70304cb2019-03-27 12:03:59 -070051 // Collections don't include the static data added by SubRoute because
52 // it has a duplicate entry for members
Ed Tanous14c8aee2019-06-13 13:39:16 -070053
54 res.jsonValue = {
55 {"@odata.type",
56 "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
Ed Tanous14c8aee2019-06-13 13:39:16 -070057 {"@odata.id", "/redfish/v1/Registries"},
58 {"Name", "MessageRegistryFile Collection"},
59 {"Description", "Collection of MessageRegistryFiles"},
Sunitha Harish74eec262020-06-25 10:00:01 -050060 {"Members@odata.count", 4},
Ed Tanous14c8aee2019-06-13 13:39:16 -070061 {"Members",
62 {{{"@odata.id", "/redfish/v1/Registries/Base"}},
James Feiste51c7102020-03-17 10:38:18 -070063 {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
Sunitha Harish74eec262020-06-25 10:00:01 -050064 {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
Ed Tanous14c8aee2019-06-13 13:39:16 -070065 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
66
67 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -070068 }
69};
70
James Feiste51c7102020-03-17 10:38:18 -070071class MessageRegistryFile : public Node
Jason M. Bills70304cb2019-03-27 12:03:59 -070072{
73 public:
74 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050075 MessageRegistryFile(CrowApp& app) :
James Feiste51c7102020-03-17 10:38:18 -070076 Node(app, "/redfish/v1/Registries/<str>/", std::string())
Jason M. Bills70304cb2019-03-27 12:03:59 -070077 {
78 entityPrivileges = {
79 {boost::beast::http::verb::get, {{"Login"}}},
80 {boost::beast::http::verb::head, {{"Login"}}},
81 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
82 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
83 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
84 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
85 }
86
87 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -050088 void doGet(crow::Response& res, const crow::Request& req,
89 const std::vector<std::string>& params) override
Jason M. Bills70304cb2019-03-27 12:03:59 -070090 {
James Feiste51c7102020-03-17 10:38:18 -070091 if (params.size() != 1)
92 {
93 messages::internalError(res);
94 res.end();
95 return;
96 }
97
Gunnar Mills1214b7e2020-06-04 10:11:30 -050098 const std::string& registry = params[0];
99 const message_registries::Header* header;
James Feiste51c7102020-03-17 10:38:18 -0700100 std::string dmtf = "DMTF ";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500101 const char* url = nullptr;
James Feiste51c7102020-03-17 10:38:18 -0700102
103 if (registry == "Base")
104 {
105 header = &message_registries::base::header;
106 url = message_registries::base::url;
107 }
108 else if (registry == "TaskEvent")
109 {
110 header = &message_registries::task_event::header;
111 url = message_registries::task_event::url;
112 }
113 else if (registry == "OpenBMC")
114 {
115 header = &message_registries::openbmc::header;
116 dmtf.clear();
117 }
Sunitha Harish74eec262020-06-25 10:00:01 -0500118 else if (registry == "ResourceEvent")
119 {
120 header = &message_registries::resource_event::header;
121 url = message_registries::resource_event::url;
122 }
James Feiste51c7102020-03-17 10:38:18 -0700123 else
124 {
125 messages::resourceNotFound(
126 res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
127 registry);
128 res.end();
129 return;
130 }
131
Ed Tanous14c8aee2019-06-13 13:39:16 -0700132 res.jsonValue = {
James Feiste51c7102020-03-17 10:38:18 -0700133 {"@odata.id", "/redfish/v1/Registries/" + registry},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700134 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
James Feiste51c7102020-03-17 10:38:18 -0700135 {"Name", registry + " Message Registry File"},
136 {"Description",
137 dmtf + registry + " Message Registry File Location"},
138 {"Id", header->registryPrefix},
139 {"Registry", header->id},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700140 {"Languages", {"en"}},
141 {"Languages@odata.count", 1},
142 {"Location",
143 {{{"Language", "en"},
James Feiste51c7102020-03-17 10:38:18 -0700144 {"Uri",
145 "/redfish/v1/Registries/" + registry + "/" + registry}}}},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700146 {"Location@odata.count", 1}};
James Feiste51c7102020-03-17 10:38:18 -0700147
148 if (url != nullptr)
149 {
150 res.jsonValue["Location"][0]["PublicationUri"] = url;
151 }
152
Ed Tanous14c8aee2019-06-13 13:39:16 -0700153 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -0700154 }
155};
156
James Feiste51c7102020-03-17 10:38:18 -0700157class MessageRegistry : public Node
Jason M. Bills70304cb2019-03-27 12:03:59 -0700158{
159 public:
160 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500161 MessageRegistry(CrowApp& app) :
James Feiste51c7102020-03-17 10:38:18 -0700162 Node(app, "/redfish/v1/Registries/<str>/<str>/", std::string(),
163 std::string())
Jason M. Bills70304cb2019-03-27 12:03:59 -0700164 {
165 entityPrivileges = {
166 {boost::beast::http::verb::get, {{"Login"}}},
167 {boost::beast::http::verb::head, {{"Login"}}},
168 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
169 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
170 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
171 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
172 }
173
174 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500175 void doGet(crow::Response& res, const crow::Request& req,
176 const std::vector<std::string>& params) override
Jason M. Bills70304cb2019-03-27 12:03:59 -0700177 {
James Feiste51c7102020-03-17 10:38:18 -0700178 if (params.size() != 2)
179 {
180 messages::internalError(res);
181 res.end();
182 return;
183 }
184
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500185 const std::string& registry = params[0];
186 const std::string& registry1 = params[1];
James Feiste51c7102020-03-17 10:38:18 -0700187
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500188 const message_registries::Header* header;
189 std::vector<const message_registries::MessageEntry*> registryEntries;
James Feiste51c7102020-03-17 10:38:18 -0700190 if (registry == "Base")
191 {
192 header = &message_registries::base::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500193 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700194 message_registries::base::registry)
195 {
196 registryEntries.emplace_back(&entry);
197 }
198 }
199 else if (registry == "TaskEvent")
200 {
201 header = &message_registries::task_event::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500202 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700203 message_registries::task_event::registry)
204 {
205 registryEntries.emplace_back(&entry);
206 }
207 }
208 else if (registry == "OpenBMC")
209 {
210 header = &message_registries::openbmc::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500211 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700212 message_registries::openbmc::registry)
213 {
214 registryEntries.emplace_back(&entry);
215 }
216 }
Sunitha Harish74eec262020-06-25 10:00:01 -0500217 else if (registry == "ResourceEvent")
218 {
219 header = &message_registries::resource_event::header;
220 for (const message_registries::MessageEntry& entry :
221 message_registries::resource_event::registry)
222 {
223 registryEntries.emplace_back(&entry);
224 }
225 }
James Feiste51c7102020-03-17 10:38:18 -0700226 else
227 {
228 messages::resourceNotFound(
229 res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
230 registry);
231 res.end();
232 return;
233 }
234
235 if (registry != registry1)
236 {
237 messages::resourceNotFound(res, header->type, registry1);
238 res.end();
239 return;
240 }
241
242 res.jsonValue = {{"@Redfish.Copyright", header->copyright},
243 {"@odata.type", header->type},
244 {"Id", header->id},
245 {"Name", header->name},
246 {"Language", header->language},
247 {"Description", header->description},
248 {"RegistryPrefix", header->registryPrefix},
249 {"RegistryVersion", header->registryVersion},
250 {"OwningEntity", header->owningEntity}};
Jason M. Bills70304cb2019-03-27 12:03:59 -0700251
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500252 nlohmann::json& messageObj = res.jsonValue["Messages"];
Jason M. Bills70304cb2019-03-27 12:03:59 -0700253
254 // Go through the Message Registry and populate each Message
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500255 for (const message_registries::MessageEntry* message : registryEntries)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700256 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500257 nlohmann::json& obj = messageObj[message->first];
James Feiste51c7102020-03-17 10:38:18 -0700258 obj = {{"Description", message->second.description},
259 {"Message", message->second.message},
260 {"Severity", message->second.severity},
Gunnar Millse7808c92020-07-08 21:17:44 -0500261 {"MessageSeverity", message->second.messageSeverity},
James Feiste51c7102020-03-17 10:38:18 -0700262 {"NumberOfArgs", message->second.numberOfArgs},
263 {"Resolution", message->second.resolution}};
264 if (message->second.numberOfArgs > 0)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700265 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500266 nlohmann::json& messageParamArray = obj["ParamTypes"];
267 for (const char* str : message->second.paramTypes)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700268 {
269 if (str == nullptr)
270 {
271 break;
272 }
273 messageParamArray.push_back(str);
274 }
275 }
276 }
Ed Tanous14c8aee2019-06-13 13:39:16 -0700277 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -0700278 }
279};
280
Jason M. Bills70304cb2019-03-27 12:03:59 -0700281} // namespace redfish