blob: 1878070227efb94c641128c2dc65c2fa2747011a [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"
James Feiste51c7102020-03-17 10:38:18 -070022#include "registries/task_event_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070023
24namespace redfish
25{
26
27class MessageRegistryFileCollection : public Node
28{
29 public:
30 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050031 MessageRegistryFileCollection(CrowApp& 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 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -050047 void doGet(crow::Response& res, const crow::Request& req,
48 const std::vector<std::string>& params) 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
53 res.jsonValue = {
54 {"@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"},
James Feiste51c7102020-03-17 10:38:18 -070059 {"Members@odata.count", 3},
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"}},
Ed Tanous14c8aee2019-06-13 13:39:16 -070063 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
64
65 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -070066 }
67};
68
James Feiste51c7102020-03-17 10:38:18 -070069class MessageRegistryFile : public Node
Jason M. Bills70304cb2019-03-27 12:03:59 -070070{
71 public:
72 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050073 MessageRegistryFile(CrowApp& app) :
James Feiste51c7102020-03-17 10:38:18 -070074 Node(app, "/redfish/v1/Registries/<str>/", std::string())
Jason M. Bills70304cb2019-03-27 12:03:59 -070075 {
76 entityPrivileges = {
77 {boost::beast::http::verb::get, {{"Login"}}},
78 {boost::beast::http::verb::head, {{"Login"}}},
79 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
80 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
81 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
82 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
83 }
84
85 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -050086 void doGet(crow::Response& res, const crow::Request& req,
87 const std::vector<std::string>& params) override
Jason M. Bills70304cb2019-03-27 12:03:59 -070088 {
James Feiste51c7102020-03-17 10:38:18 -070089 if (params.size() != 1)
90 {
91 messages::internalError(res);
92 res.end();
93 return;
94 }
95
Gunnar Mills1214b7e2020-06-04 10:11:30 -050096 const std::string& registry = params[0];
97 const message_registries::Header* header;
James Feiste51c7102020-03-17 10:38:18 -070098 std::string dmtf = "DMTF ";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050099 const char* url = nullptr;
James Feiste51c7102020-03-17 10:38:18 -0700100
101 if (registry == "Base")
102 {
103 header = &message_registries::base::header;
104 url = message_registries::base::url;
105 }
106 else if (registry == "TaskEvent")
107 {
108 header = &message_registries::task_event::header;
109 url = message_registries::task_event::url;
110 }
111 else if (registry == "OpenBMC")
112 {
113 header = &message_registries::openbmc::header;
114 dmtf.clear();
115 }
116 else
117 {
118 messages::resourceNotFound(
119 res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
120 registry);
121 res.end();
122 return;
123 }
124
Ed Tanous14c8aee2019-06-13 13:39:16 -0700125 res.jsonValue = {
James Feiste51c7102020-03-17 10:38:18 -0700126 {"@odata.id", "/redfish/v1/Registries/" + registry},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700127 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
James Feiste51c7102020-03-17 10:38:18 -0700128 {"Name", registry + " Message Registry File"},
129 {"Description",
130 dmtf + registry + " Message Registry File Location"},
131 {"Id", header->registryPrefix},
132 {"Registry", header->id},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700133 {"Languages", {"en"}},
134 {"Languages@odata.count", 1},
135 {"Location",
136 {{{"Language", "en"},
James Feiste51c7102020-03-17 10:38:18 -0700137 {"Uri",
138 "/redfish/v1/Registries/" + registry + "/" + registry}}}},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700139 {"Location@odata.count", 1}};
James Feiste51c7102020-03-17 10:38:18 -0700140
141 if (url != nullptr)
142 {
143 res.jsonValue["Location"][0]["PublicationUri"] = url;
144 }
145
Ed Tanous14c8aee2019-06-13 13:39:16 -0700146 res.end();
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:
153 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500154 MessageRegistry(CrowApp& app) :
James Feiste51c7102020-03-17 10:38:18 -0700155 Node(app, "/redfish/v1/Registries/<str>/<str>/", std::string(),
156 std::string())
Jason M. Bills70304cb2019-03-27 12:03:59 -0700157 {
158 entityPrivileges = {
159 {boost::beast::http::verb::get, {{"Login"}}},
160 {boost::beast::http::verb::head, {{"Login"}}},
161 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
162 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
163 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
164 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
165 }
166
167 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500168 void doGet(crow::Response& res, const crow::Request& req,
169 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 {
173 messages::internalError(res);
174 res.end();
175 return;
176 }
177
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500178 const std::string& registry = params[0];
179 const std::string& registry1 = params[1];
James Feiste51c7102020-03-17 10:38:18 -0700180
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500181 const message_registries::Header* header;
182 std::vector<const message_registries::MessageEntry*> registryEntries;
James Feiste51c7102020-03-17 10:38:18 -0700183 if (registry == "Base")
184 {
185 header = &message_registries::base::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500186 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700187 message_registries::base::registry)
188 {
189 registryEntries.emplace_back(&entry);
190 }
191 }
192 else if (registry == "TaskEvent")
193 {
194 header = &message_registries::task_event::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500195 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700196 message_registries::task_event::registry)
197 {
198 registryEntries.emplace_back(&entry);
199 }
200 }
201 else if (registry == "OpenBMC")
202 {
203 header = &message_registries::openbmc::header;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500204 for (const message_registries::MessageEntry& entry :
James Feiste51c7102020-03-17 10:38:18 -0700205 message_registries::openbmc::registry)
206 {
207 registryEntries.emplace_back(&entry);
208 }
209 }
210 else
211 {
212 messages::resourceNotFound(
213 res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
214 registry);
215 res.end();
216 return;
217 }
218
219 if (registry != registry1)
220 {
221 messages::resourceNotFound(res, header->type, registry1);
222 res.end();
223 return;
224 }
225
226 res.jsonValue = {{"@Redfish.Copyright", header->copyright},
227 {"@odata.type", header->type},
228 {"Id", header->id},
229 {"Name", header->name},
230 {"Language", header->language},
231 {"Description", header->description},
232 {"RegistryPrefix", header->registryPrefix},
233 {"RegistryVersion", header->registryVersion},
234 {"OwningEntity", header->owningEntity}};
Jason M. Bills70304cb2019-03-27 12:03:59 -0700235
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500236 nlohmann::json& messageObj = res.jsonValue["Messages"];
Jason M. Bills70304cb2019-03-27 12:03:59 -0700237
238 // Go through the Message Registry and populate each Message
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500239 for (const message_registries::MessageEntry* message : registryEntries)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700240 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500241 nlohmann::json& obj = messageObj[message->first];
James Feiste51c7102020-03-17 10:38:18 -0700242 obj = {{"Description", message->second.description},
243 {"Message", message->second.message},
244 {"Severity", message->second.severity},
245 {"NumberOfArgs", message->second.numberOfArgs},
246 {"Resolution", message->second.resolution}};
247 if (message->second.numberOfArgs > 0)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700248 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500249 nlohmann::json& messageParamArray = obj["ParamTypes"];
250 for (const char* str : message->second.paramTypes)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700251 {
252 if (str == nullptr)
253 {
254 break;
255 }
256 messageParamArray.push_back(str);
257 }
258 }
259 }
Ed Tanous14c8aee2019-06-13 13:39:16 -0700260 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -0700261 }
262};
263
Jason M. Bills70304cb2019-03-27 12:03:59 -0700264} // namespace redfish