xref: /openbmc/bmcweb/redfish-core/lib/message_registries.hpp (revision ac70637e290eeae1708efb19173ae074ca0178fe)
1 /*
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"
21 #include "registries/openbmc_message_registry.hpp"
22 
23 namespace redfish
24 {
25 
26 class 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     {
49         // Collections don't include the static data added by SubRoute because
50         // it has a duplicate entry for members
51 
52         res.jsonValue = {
53             {"@odata.type",
54              "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
55             {"@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();
64     }
65 };
66 
67 class 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     {
87         res.jsonValue = {
88             {"@odata.id", "/redfish/v1/Registries/Base"},
89             {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
90             {"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();
103     }
104 };
105 
106 class 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     {
126         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}};
137 
138         nlohmann::json &messageObj = res.jsonValue["Messages"];
139 
140         // Go through the Message Registry and populate each Message
141         for (const message_registries::MessageEntry &message :
142              message_registries::base::registry)
143         {
144             nlohmann::json &obj = messageObj[message.first];
145             obj = {{"Description", message.second.description},
146                    {"Message", message.second.message},
147                    {"Severity", message.second.severity},
148                    {"NumberOfArgs", message.second.numberOfArgs},
149                    {"Resolution", message.second.resolution}};
150             if (message.second.numberOfArgs > 0)
151             {
152                 nlohmann::json &messageParamArray = obj["ParamTypes"];
153                 for (const char *str : message.second.paramTypes)
154                 {
155                     if (str == nullptr)
156                     {
157                         break;
158                     }
159                     messageParamArray.push_back(str);
160                 }
161             }
162         }
163         res.end();
164     }
165 };
166 
167 class 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     {
187         res.jsonValue = {
188             {"@odata.id", "/redfish/v1/Registries/OpenBMC"},
189             {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
190             {"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}};
200 
201         res.end();
202     }
203 };
204 
205 class 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     {
225         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}};
238 
239         nlohmann::json &messageObj = res.jsonValue["Messages"];
240         // Go through the Message Registry and populate each Message
241         for (const message_registries::MessageEntry &message :
242              message_registries::openbmc::registry)
243         {
244             nlohmann::json &obj = messageObj[message.first];
245             obj = {{"Description", message.second.description},
246                    {"Message", message.second.message},
247                    {"Severity", message.second.severity},
248                    {"NumberOfArgs", message.second.numberOfArgs},
249                    {"Resolution", message.second.resolution}};
250             if (message.second.numberOfArgs > 0)
251             {
252                 nlohmann::json &messageParamArray = obj["ParamTypes"];
253                 for (size_t i = 0; i < message.second.numberOfArgs; i++)
254                 {
255                     messageParamArray.push_back(message.second.paramTypes[i]);
256                 }
257             }
258         }
259         res.end();
260     }
261 };
262 
263 } // namespace redfish
264