blob: 628c63a6ca89739e7efefaa558e9b8ff185eec03 [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"},
Ed Tanous14c8aee2019-06-13 13:39:16 -070055 {"@odata.id", "/redfish/v1/Registries"},
56 {"Name", "MessageRegistryFile Collection"},
57 {"Description", "Collection of MessageRegistryFiles"},
58 {"Members@odata.count", 2},
59 {"Members",
60 {{{"@odata.id", "/redfish/v1/Registries/Base"}},
61 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
62
63 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -070064 }
65};
66
67class BaseMessageRegistryFile : public Node
68{
69 public:
70 template <typename CrowApp>
71 BaseMessageRegistryFile(CrowApp &app) :
72 Node(app, "/redfish/v1/Registries/Base/")
73 {
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:
84 void doGet(crow::Response &res, const crow::Request &req,
85 const std::vector<std::string> &params) override
86 {
Ed Tanous14c8aee2019-06-13 13:39:16 -070087 res.jsonValue = {
88 {"@odata.id", "/redfish/v1/Registries/Base"},
89 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
Ed Tanous14c8aee2019-06-13 13:39:16 -070090 {"Name", "Base Message Registry File"},
91 {"Description", "DMTF Base Message Registry File Location"},
92 {"Id", message_registries::base::header.registryPrefix},
93 {"Registry", message_registries::base::header.id},
94 {"Languages", {"en"}},
95 {"Languages@odata.count", 1},
96 {"Location",
97 {{{"Language", "en"},
98 {"PublicationUri",
99 "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
100 {"Uri", "/redfish/v1/Registries/Base/Base"}}}},
101 {"Location@odata.count", 1}};
102 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -0700103 }
104};
105
106class BaseMessageRegistry : public Node
107{
108 public:
109 template <typename CrowApp>
110 BaseMessageRegistry(CrowApp &app) :
111 Node(app, "/redfish/v1/Registries/Base/Base/")
112 {
113 entityPrivileges = {
114 {boost::beast::http::verb::get, {{"Login"}}},
115 {boost::beast::http::verb::head, {{"Login"}}},
116 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
117 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
118 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
119 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
120 }
121
122 private:
123 void doGet(crow::Response &res, const crow::Request &req,
124 const std::vector<std::string> &params) override
125 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700126 res.jsonValue = {
127 {"@Redfish.Copyright", message_registries::base::header.copyright},
128 {"@odata.type", message_registries::base::header.type},
129 {"Id", message_registries::base::header.id},
130 {"Name", message_registries::base::header.name},
131 {"Language", message_registries::base::header.language},
132 {"Description", message_registries::base::header.description},
133 {"RegistryPrefix", message_registries::base::header.registryPrefix},
134 {"RegistryVersion",
135 message_registries::base::header.registryVersion},
136 {"OwningEntity", message_registries::base::header.owningEntity}};
Jason M. Bills70304cb2019-03-27 12:03:59 -0700137
Ed Tanous14c8aee2019-06-13 13:39:16 -0700138 nlohmann::json &messageObj = res.jsonValue["Messages"];
Jason M. Bills70304cb2019-03-27 12:03:59 -0700139
140 // Go through the Message Registry and populate each Message
141 for (const message_registries::MessageEntry &message :
142 message_registries::base::registry)
143 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700144 nlohmann::json &obj = messageObj[message.first];
145 obj = {{"Description", message.second.description},
Jason M. Bills70304cb2019-03-27 12:03:59 -0700146 {"Message", message.second.message},
147 {"Severity", message.second.severity},
148 {"NumberOfArgs", message.second.numberOfArgs},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700149 {"Resolution", message.second.resolution}};
Jason M. Bills70304cb2019-03-27 12:03:59 -0700150 if (message.second.numberOfArgs > 0)
151 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700152 nlohmann::json &messageParamArray = obj["ParamTypes"];
Jason M. Bills70304cb2019-03-27 12:03:59 -0700153 for (const char *str : message.second.paramTypes)
154 {
155 if (str == nullptr)
156 {
157 break;
158 }
159 messageParamArray.push_back(str);
160 }
161 }
162 }
Ed Tanous14c8aee2019-06-13 13:39:16 -0700163 res.end();
Jason M. Bills70304cb2019-03-27 12:03:59 -0700164 }
165};
166
Jason M. Billsfbe83782019-03-27 14:14:53 -0700167class OpenBMCMessageRegistryFile : public Node
168{
169 public:
170 template <typename CrowApp>
171 OpenBMCMessageRegistryFile(CrowApp &app) :
172 Node(app, "/redfish/v1/Registries/OpenBMC/")
173 {
174 entityPrivileges = {
175 {boost::beast::http::verb::get, {{"Login"}}},
176 {boost::beast::http::verb::head, {{"Login"}}},
177 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
178 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
179 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
180 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
181 }
182
183 private:
184 void doGet(crow::Response &res, const crow::Request &req,
185 const std::vector<std::string> &params) override
186 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700187 res.jsonValue = {
188 {"@odata.id", "/redfish/v1/Registries/OpenBMC"},
189 {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700190 {"Name", "Open BMC Message Registry File"},
191 {"Description", "Open BMC Message Registry File Location"},
192 {"Id", message_registries::openbmc::header.registryPrefix},
193 {"Registry", message_registries::openbmc::header.id},
194 {"Languages", {"en"}},
195 {"Languages@odata.count", 1},
196 {"Location",
197 {{{"Language", "en"},
198 {"Uri", "/redfish/v1/Registries/OpenBMC/OpenBMC"}}}},
199 {"Location@odata.count", 1}};
Jason M. Billsfbe83782019-03-27 14:14:53 -0700200
Ed Tanous14c8aee2019-06-13 13:39:16 -0700201 res.end();
Jason M. Billsfbe83782019-03-27 14:14:53 -0700202 }
203};
204
205class OpenBMCMessageRegistry : public Node
206{
207 public:
208 template <typename CrowApp>
209 OpenBMCMessageRegistry(CrowApp &app) :
210 Node(app, "/redfish/v1/Registries/OpenBMC/OpenBMC/")
211 {
212 entityPrivileges = {
213 {boost::beast::http::verb::get, {{"Login"}}},
214 {boost::beast::http::verb::head, {{"Login"}}},
215 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
216 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
217 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
218 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
219 }
220
221 private:
222 void doGet(crow::Response &res, const crow::Request &req,
223 const std::vector<std::string> &params) override
224 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700225 res.jsonValue = {
226 {"@Redfish.Copyright",
227 message_registries::openbmc::header.copyright},
228 {"@odata.type", message_registries::openbmc::header.type},
229 {"Id", message_registries::openbmc::header.id},
230 {"Name", message_registries::openbmc::header.name},
231 {"Language", message_registries::openbmc::header.language},
232 {"Description", message_registries::openbmc::header.description},
233 {"RegistryPrefix",
234 message_registries::openbmc::header.registryPrefix},
235 {"RegistryVersion",
236 message_registries::openbmc::header.registryVersion},
237 {"OwningEntity", message_registries::openbmc::header.owningEntity}};
Jason M. Billsfbe83782019-03-27 14:14:53 -0700238
Ed Tanous14c8aee2019-06-13 13:39:16 -0700239 nlohmann::json &messageObj = res.jsonValue["Messages"];
Jason M. Billsfbe83782019-03-27 14:14:53 -0700240 // Go through the Message Registry and populate each Message
241 for (const message_registries::MessageEntry &message :
242 message_registries::openbmc::registry)
243 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700244 nlohmann::json &obj = messageObj[message.first];
245 obj = {{"Description", message.second.description},
Jason M. Billsfbe83782019-03-27 14:14:53 -0700246 {"Message", message.second.message},
247 {"Severity", message.second.severity},
248 {"NumberOfArgs", message.second.numberOfArgs},
Ed Tanous14c8aee2019-06-13 13:39:16 -0700249 {"Resolution", message.second.resolution}};
Jason M. Billsfbe83782019-03-27 14:14:53 -0700250 if (message.second.numberOfArgs > 0)
251 {
Ed Tanous14c8aee2019-06-13 13:39:16 -0700252 nlohmann::json &messageParamArray = obj["ParamTypes"];
Ed Tanous271584a2019-07-09 16:24:22 -0700253 for (size_t i = 0; i < message.second.numberOfArgs; i++)
Jason M. Billsfbe83782019-03-27 14:14:53 -0700254 {
255 messageParamArray.push_back(message.second.paramTypes[i]);
256 }
257 }
258 }
Ed Tanous14c8aee2019-06-13 13:39:16 -0700259 res.end();
Jason M. Billsfbe83782019-03-27 14:14:53 -0700260 }
261};
262
Jason M. Bills70304cb2019-03-27 12:03:59 -0700263} // namespace redfish