blob: 455bf70570f995d08bc916cddad75dcd81403975 [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:
Ed Tanous52cc1122020-07-18 13:51:21 -070031 MessageRegistryFileCollection(App& app) :
Jason M. Bills70304cb2019-03-27 12:03:59 -070032 Node(app, "/redfish/v1/Registries/")
33 {
34 entityPrivileges = {
35 {boost::beast::http::verb::get, {{"Login"}}},
36 {boost::beast::http::verb::head, {{"Login"}}},
37 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
38 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
39 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
40 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
41 }
42
43 private:
44 /**
45 * Functions triggers appropriate requests on DBus
46 */
zhanghch058d1b46d2021-04-01 11:18:24 +080047 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
48 const crow::Request&, const std::vector<std::string>&) override
Jason M. Bills70304cb2019-03-27 12:03:59 -070049 {
Jason M. Bills70304cb2019-03-27 12:03:59 -070050 // Collections don't include the static data added by SubRoute because
51 // it has a duplicate entry for members
Ed Tanous14c8aee2019-06-13 13:39:16 -070052
zhanghch058d1b46d2021-04-01 11:18:24 +080053 asyncResp->res.jsonValue = {
Ed Tanous14c8aee2019-06-13 13:39:16 -070054 {"@odata.type",
55 "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
Ed Tanous14c8aee2019-06-13 13:39:16 -070056 {"@odata.id", "/redfish/v1/Registries"},
57 {"Name", "MessageRegistryFile Collection"},
58 {"Description", "Collection of MessageRegistryFiles"},
Sunitha Harish74eec262020-06-25 10:00:01 -050059 {"Members@odata.count", 4},
Ed Tanous14c8aee2019-06-13 13:39:16 -070060 {"Members",
61 {{{"@odata.id", "/redfish/v1/Registries/Base"}},
James Feiste51c7102020-03-17 10:38:18 -070062 {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
Sunitha Harish74eec262020-06-25 10:00:01 -050063 {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
Ed Tanous14c8aee2019-06-13 13:39:16 -070064 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
Jason M. Bills70304cb2019-03-27 12:03:59 -070065 }
66};
67
James Feiste51c7102020-03-17 10:38:18 -070068class MessageRegistryFile : public Node
Jason M. Bills70304cb2019-03-27 12:03:59 -070069{
70 public:
Ed Tanous52cc1122020-07-18 13:51:21 -070071 MessageRegistryFile(App& app) :
James Feiste51c7102020-03-17 10:38:18 -070072 Node(app, "/redfish/v1/Registries/<str>/", std::string())
Jason M. Bills70304cb2019-03-27 12:03:59 -070073 {
74 entityPrivileges = {
75 {boost::beast::http::verb::get, {{"Login"}}},
76 {boost::beast::http::verb::head, {{"Login"}}},
77 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
78 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
79 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
80 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
81 }
82
83 private:
zhanghch058d1b46d2021-04-01 11:18:24 +080084 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
85 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -050086 const std::vector<std::string>& params) override
Jason M. Bills70304cb2019-03-27 12:03:59 -070087 {
James Feiste51c7102020-03-17 10:38:18 -070088 if (params.size() != 1)
89 {
zhanghch058d1b46d2021-04-01 11:18:24 +080090 messages::internalError(asyncResp->res);
James Feiste51c7102020-03-17 10:38:18 -070091 return;
92 }
93
Gunnar Mills1214b7e2020-06-04 10:11:30 -050094 const std::string& registry = params[0];
95 const message_registries::Header* header;
James Feiste51c7102020-03-17 10:38:18 -070096 std::string dmtf = "DMTF ";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050097 const char* url = nullptr;
James Feiste51c7102020-03-17 10:38:18 -070098
99 if (registry == "Base")
100 {
101 header = &message_registries::base::header;
102 url = message_registries::base::url;
103 }
104 else if (registry == "TaskEvent")
105 {
106 header = &message_registries::task_event::header;
107 url = message_registries::task_event::url;
108 }
109 else if (registry == "OpenBMC")
110 {
111 header = &message_registries::openbmc::header;
112 dmtf.clear();
113 }
Sunitha Harish74eec262020-06-25 10:00:01 -0500114 else if (registry == "ResourceEvent")
115 {
116 header = &message_registries::resource_event::header;
117 url = message_registries::resource_event::url;
118 }
James Feiste51c7102020-03-17 10:38:18 -0700119 else
120 {
121 messages::resourceNotFound(
zhanghch058d1b46d2021-04-01 11:18:24 +0800122 asyncResp->res,
123 "#MessageRegistryFile.v1_1_0.MessageRegistryFile", registry);
James Feiste51c7102020-03-17 10:38:18 -0700124 return;
125 }
126
zhanghch058d1b46d2021-04-01 11:18:24 +0800127 asyncResp->res.jsonValue = {
James Feiste51c7102020-03-17 10:38:18 -0700128 {"@odata.id", "/redfish/v1/Registries/" + registry},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700129 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
James Feiste51c7102020-03-17 10:38:18 -0700130 {"Name", registry + " Message Registry File"},
131 {"Description",
132 dmtf + registry + " Message Registry File Location"},
133 {"Id", header->registryPrefix},
134 {"Registry", header->id},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700135 {"Languages", {"en"}},
136 {"Languages@odata.count", 1},
137 {"Location",
138 {{{"Language", "en"},
James Feiste51c7102020-03-17 10:38:18 -0700139 {"Uri",
140 "/redfish/v1/Registries/" + registry + "/" + registry}}}},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700141 {"Location@odata.count", 1}};
James Feiste51c7102020-03-17 10:38:18 -0700142
143 if (url != nullptr)
144 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800145 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] = url;
James Feiste51c7102020-03-17 10:38:18 -0700146 }
Jason M. Bills70304cb2019-03-27 12:03:59 -0700147 }
148};
149
James Feiste51c7102020-03-17 10:38:18 -0700150class MessageRegistry : public Node
Jason M. Bills70304cb2019-03-27 12:03:59 -0700151{
152 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700153 MessageRegistry(App& app) :
James Feiste51c7102020-03-17 10:38:18 -0700154 Node(app, "/redfish/v1/Registries/<str>/<str>/", std::string(),
155 std::string())
Jason M. Bills70304cb2019-03-27 12:03:59 -0700156 {
157 entityPrivileges = {
158 {boost::beast::http::verb::get, {{"Login"}}},
159 {boost::beast::http::verb::head, {{"Login"}}},
160 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
161 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
162 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
163 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
164 }
165
166 private:
zhanghch058d1b46d2021-04-01 11:18:24 +0800167 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
168 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500169 const std::vector<std::string>& params) override
Jason M. Bills70304cb2019-03-27 12:03:59 -0700170 {
James Feiste51c7102020-03-17 10:38:18 -0700171 if (params.size() != 2)
172 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800173 messages::internalError(asyncResp->res);
James Feiste51c7102020-03-17 10:38:18 -0700174 return;
175 }
176
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500177 const std::string& registry = params[0];
178 const std::string& registry1 = params[1];
James Feiste51c7102020-03-17 10:38:18 -0700179
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500180 const message_registries::Header* header;
181 std::vector<const message_registries::MessageEntry*> registryEntries;
James Feiste51c7102020-03-17 10:38:18 -0700182 if (registry == "Base")
183 {
184 header = &message_registries::base::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500185 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700186 message_registries::base::registry)
187 {
188 registryEntries.emplace_back(&entry);
189 }
190 }
191 else if (registry == "TaskEvent")
192 {
193 header = &message_registries::task_event::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500194 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700195 message_registries::task_event::registry)
196 {
197 registryEntries.emplace_back(&entry);
198 }
199 }
200 else if (registry == "OpenBMC")
201 {
202 header = &message_registries::openbmc::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500203 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700204 message_registries::openbmc::registry)
205 {
206 registryEntries.emplace_back(&entry);
207 }
208 }
Sunitha Harish74eec262020-06-25 10:00:01 -0500209 else if (registry == "ResourceEvent")
210 {
211 header = &message_registries::resource_event::header;
212 for (const message_registries::MessageEntry& entry :
213 message_registries::resource_event::registry)
214 {
215 registryEntries.emplace_back(&entry);
216 }
217 }
James Feiste51c7102020-03-17 10:38:18 -0700218 else
219 {
220 messages::resourceNotFound(
zhanghch058d1b46d2021-04-01 11:18:24 +0800221 asyncResp->res,
222 "#MessageRegistryFile.v1_1_0.MessageRegistryFile", registry);
James Feiste51c7102020-03-17 10:38:18 -0700223 return;
224 }
225
226 if (registry != registry1)
227 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800228 messages::resourceNotFound(asyncResp->res, header->type, registry1);
James Feiste51c7102020-03-17 10:38:18 -0700229 return;
230 }
231
zhanghch058d1b46d2021-04-01 11:18:24 +0800232 asyncResp->res.jsonValue = {
233 {"@Redfish.Copyright", header->copyright},
234 {"@odata.type", header->type},
235 {"Id", header->id},
236 {"Name", header->name},
237 {"Language", header->language},
238 {"Description", header->description},
239 {"RegistryPrefix", header->registryPrefix},
240 {"RegistryVersion", header->registryVersion},
241 {"OwningEntity", header->owningEntity}};
Jason M. Bills70304cb2019-03-27 12:03:59 -0700242
zhanghch058d1b46d2021-04-01 11:18:24 +0800243 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
Jason M. Bills70304cb2019-03-27 12:03:59 -0700244
245 // Go through the Message Registry and populate each Message
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500246 for (const message_registries::MessageEntry* message : registryEntries)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700247 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500248 nlohmann::json& obj = messageObj[message->first];
James Feiste51c7102020-03-17 10:38:18 -0700249 obj = {{"Description", message->second.description},
250 {"Message", message->second.message},
251 {"Severity", message->second.severity},
Gunnar Millse7808c92020-07-08 21:17:44 -0500252 {"MessageSeverity", message->second.messageSeverity},
James Feiste51c7102020-03-17 10:38:18 -0700253 {"NumberOfArgs", message->second.numberOfArgs},
254 {"Resolution", message->second.resolution}};
255 if (message->second.numberOfArgs > 0)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700256 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500257 nlohmann::json& messageParamArray = obj["ParamTypes"];
258 for (const char* str : message->second.paramTypes)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700259 {
260 if (str == nullptr)
261 {
262 break;
263 }
264 messageParamArray.push_back(str);
265 }
266 }
267 }
268 }
269};
270
Jason M. Bills70304cb2019-03-27 12:03:59 -0700271} // namespace redfish