xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision fbe8378fd5d8ee926f260ae71c877cc6a64a7594)
170304cb5SJason M. Bills /*
270304cb5SJason M. Bills // Copyright (c) 2019 Intel Corporation
370304cb5SJason M. Bills //
470304cb5SJason M. Bills // Licensed under the Apache License, Version 2.0 (the "License");
570304cb5SJason M. Bills // you may not use this file except in compliance with the License.
670304cb5SJason M. Bills // You may obtain a copy of the License at
770304cb5SJason M. Bills //
870304cb5SJason M. Bills //      http://www.apache.org/licenses/LICENSE-2.0
970304cb5SJason M. Bills //
1070304cb5SJason M. Bills // Unless required by applicable law or agreed to in writing, software
1170304cb5SJason M. Bills // distributed under the License is distributed on an "AS IS" BASIS,
1270304cb5SJason M. Bills // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1370304cb5SJason M. Bills // See the License for the specific language governing permissions and
1470304cb5SJason M. Bills // limitations under the License.
1570304cb5SJason M. Bills */
1670304cb5SJason M. Bills #pragma once
1770304cb5SJason M. Bills 
1870304cb5SJason M. Bills #include "node.hpp"
1970304cb5SJason M. Bills #include "registries.hpp"
2070304cb5SJason M. Bills #include "registries/base_message_registry.hpp"
21*fbe8378fSJason M. Bills #include "registries/openbmc_message_registry.hpp"
2270304cb5SJason M. Bills 
2370304cb5SJason M. Bills namespace redfish
2470304cb5SJason M. Bills {
2570304cb5SJason M. Bills 
2670304cb5SJason M. Bills class MessageRegistryFileCollection : public Node
2770304cb5SJason M. Bills {
2870304cb5SJason M. Bills   public:
2970304cb5SJason M. Bills     template <typename CrowApp>
3070304cb5SJason M. Bills     MessageRegistryFileCollection(CrowApp &app) :
3170304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/")
3270304cb5SJason M. Bills     {
3370304cb5SJason M. Bills         entityPrivileges = {
3470304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
3570304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
3670304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3770304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3870304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3970304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
4070304cb5SJason M. Bills     }
4170304cb5SJason M. Bills 
4270304cb5SJason M. Bills   private:
4370304cb5SJason M. Bills     /**
4470304cb5SJason M. Bills      * Functions triggers appropriate requests on DBus
4570304cb5SJason M. Bills      */
4670304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
4770304cb5SJason M. Bills                const std::vector<std::string> &params) override
4870304cb5SJason M. Bills     {
4970304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
5070304cb5SJason M. Bills         // Collections don't include the static data added by SubRoute because
5170304cb5SJason M. Bills         // it has a duplicate entry for members
5270304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
5370304cb5SJason M. Bills             "#MessageRegistryFileCollection.MessageRegistryFileCollection";
5470304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.context"] =
5570304cb5SJason M. Bills             "/redfish/v1/"
5670304cb5SJason M. Bills             "$metadata#MessageRegistryFileCollection."
5770304cb5SJason M. Bills             "MessageRegistryFileCollection";
5870304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
5970304cb5SJason M. Bills         asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
6070304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
6170304cb5SJason M. Bills             "Collection of MessageRegistryFiles";
6270304cb5SJason M. Bills         nlohmann::json &messageRegistryFileArray =
6370304cb5SJason M. Bills             asyncResp->res.jsonValue["Members"];
6470304cb5SJason M. Bills         messageRegistryFileArray = nlohmann::json::array();
6570304cb5SJason M. Bills         messageRegistryFileArray.push_back(
6670304cb5SJason M. Bills             {{"@odata.id", "/redfish/v1/Registries/Base"}});
6770304cb5SJason M. Bills         messageRegistryFileArray.push_back(
6870304cb5SJason M. Bills             {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}});
6970304cb5SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
7070304cb5SJason M. Bills             messageRegistryFileArray.size();
7170304cb5SJason M. Bills     }
7270304cb5SJason M. Bills };
7370304cb5SJason M. Bills 
7470304cb5SJason M. Bills class BaseMessageRegistryFile : public Node
7570304cb5SJason M. Bills {
7670304cb5SJason M. Bills   public:
7770304cb5SJason M. Bills     template <typename CrowApp>
7870304cb5SJason M. Bills     BaseMessageRegistryFile(CrowApp &app) :
7970304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/")
8070304cb5SJason M. Bills     {
8170304cb5SJason M. Bills         entityPrivileges = {
8270304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
8370304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
8470304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
8570304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
8670304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
8770304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
8870304cb5SJason M. Bills     }
8970304cb5SJason M. Bills 
9070304cb5SJason M. Bills   private:
9170304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
9270304cb5SJason M. Bills                const std::vector<std::string> &params) override
9370304cb5SJason M. Bills     {
9470304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
9570304cb5SJason M. Bills 
9670304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries/Base";
9770304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
9870304cb5SJason M. Bills             "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
9970304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.context"] =
10070304cb5SJason M. Bills             "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
10170304cb5SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Base Message Registry File";
10270304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
10370304cb5SJason M. Bills             "DMTF Base Message Registry File Location";
104351d3063SJason M. Bills         asyncResp->res.jsonValue["Id"] =
105351d3063SJason M. Bills             message_registries::base::header.registryPrefix;
106351d3063SJason M. Bills         asyncResp->res.jsonValue["Registry"] =
107351d3063SJason M. Bills             message_registries::base::header.id;
10870304cb5SJason M. Bills         nlohmann::json &messageRegistryLanguageArray =
10970304cb5SJason M. Bills             asyncResp->res.jsonValue["Languages"];
11070304cb5SJason M. Bills         messageRegistryLanguageArray = nlohmann::json::array();
11170304cb5SJason M. Bills         messageRegistryLanguageArray.push_back({"en"});
11270304cb5SJason M. Bills         asyncResp->res.jsonValue["Languages@odata.count"] =
11370304cb5SJason M. Bills             messageRegistryLanguageArray.size();
11470304cb5SJason M. Bills         nlohmann::json &messageRegistryLocationArray =
11570304cb5SJason M. Bills             asyncResp->res.jsonValue["Location"];
11670304cb5SJason M. Bills         messageRegistryLocationArray = nlohmann::json::array();
11770304cb5SJason M. Bills         messageRegistryLocationArray.push_back(
11870304cb5SJason M. Bills             {{"Language", "en"},
11970304cb5SJason M. Bills              {"PublicationUri",
12070304cb5SJason M. Bills               "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
12170304cb5SJason M. Bills              {"Uri", "/redfish/v1/Registries/Base/Base"}});
12270304cb5SJason M. Bills         asyncResp->res.jsonValue["Location@odata.count"] =
12370304cb5SJason M. Bills             messageRegistryLocationArray.size();
12470304cb5SJason M. Bills     }
12570304cb5SJason M. Bills };
12670304cb5SJason M. Bills 
12770304cb5SJason M. Bills class BaseMessageRegistry : public Node
12870304cb5SJason M. Bills {
12970304cb5SJason M. Bills   public:
13070304cb5SJason M. Bills     template <typename CrowApp>
13170304cb5SJason M. Bills     BaseMessageRegistry(CrowApp &app) :
13270304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/Base/")
13370304cb5SJason M. Bills     {
13470304cb5SJason M. Bills         entityPrivileges = {
13570304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
13670304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
13770304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
13870304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
13970304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
14070304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
14170304cb5SJason M. Bills     }
14270304cb5SJason M. Bills 
14370304cb5SJason M. Bills   private:
14470304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
14570304cb5SJason M. Bills                const std::vector<std::string> &params) override
14670304cb5SJason M. Bills     {
14770304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
14870304cb5SJason M. Bills 
14970304cb5SJason M. Bills         asyncResp->res.jsonValue["@Redfish.Copyright"] =
150351d3063SJason M. Bills             message_registries::base::header.copyright;
15170304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
152351d3063SJason M. Bills             message_registries::base::header.type;
153351d3063SJason M. Bills         asyncResp->res.jsonValue["Id"] = message_registries::base::header.id;
154351d3063SJason M. Bills         asyncResp->res.jsonValue["Name"] =
155351d3063SJason M. Bills             message_registries::base::header.name;
156351d3063SJason M. Bills         asyncResp->res.jsonValue["Language"] =
157351d3063SJason M. Bills             message_registries::base::header.language;
15870304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
159351d3063SJason M. Bills             message_registries::base::header.description;
160351d3063SJason M. Bills         asyncResp->res.jsonValue["RegistryPrefix"] =
161351d3063SJason M. Bills             message_registries::base::header.registryPrefix;
162351d3063SJason M. Bills         asyncResp->res.jsonValue["RegistryVersion"] =
163351d3063SJason M. Bills             message_registries::base::header.registryVersion;
164351d3063SJason M. Bills         asyncResp->res.jsonValue["OwningEntity"] =
165351d3063SJason M. Bills             message_registries::base::header.owningEntity;
16670304cb5SJason M. Bills         nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
16770304cb5SJason M. Bills         messageArray = nlohmann::json::array();
16870304cb5SJason M. Bills 
16970304cb5SJason M. Bills         // Go through the Message Registry and populate each Message
17070304cb5SJason M. Bills         for (const message_registries::MessageEntry &message :
17170304cb5SJason M. Bills              message_registries::base::registry)
17270304cb5SJason M. Bills         {
17370304cb5SJason M. Bills             messageArray.push_back(
17470304cb5SJason M. Bills                 {{message.first,
17570304cb5SJason M. Bills                   {{"Description", message.second.description},
17670304cb5SJason M. Bills                    {"Message", message.second.message},
17770304cb5SJason M. Bills                    {"Severity", message.second.severity},
17870304cb5SJason M. Bills                    {"NumberOfArgs", message.second.numberOfArgs},
17970304cb5SJason M. Bills                    {"Resolution", message.second.resolution}}}});
18070304cb5SJason M. Bills             if (message.second.numberOfArgs > 0)
18170304cb5SJason M. Bills             {
18270304cb5SJason M. Bills                 nlohmann::json &messageParamArray =
18370304cb5SJason M. Bills                     messageArray.back()[message.first]["ParamTypes"];
18470304cb5SJason M. Bills                 for (const char *str : message.second.paramTypes)
18570304cb5SJason M. Bills                 {
18670304cb5SJason M. Bills                     if (str == nullptr)
18770304cb5SJason M. Bills                     {
18870304cb5SJason M. Bills                         break;
18970304cb5SJason M. Bills                     }
19070304cb5SJason M. Bills                     messageParamArray.push_back(str);
19170304cb5SJason M. Bills                 }
19270304cb5SJason M. Bills             }
19370304cb5SJason M. Bills         }
19470304cb5SJason M. Bills     }
19570304cb5SJason M. Bills };
19670304cb5SJason M. Bills 
197*fbe8378fSJason M. Bills class OpenBMCMessageRegistryFile : public Node
198*fbe8378fSJason M. Bills {
199*fbe8378fSJason M. Bills   public:
200*fbe8378fSJason M. Bills     template <typename CrowApp>
201*fbe8378fSJason M. Bills     OpenBMCMessageRegistryFile(CrowApp &app) :
202*fbe8378fSJason M. Bills         Node(app, "/redfish/v1/Registries/OpenBMC/")
203*fbe8378fSJason M. Bills     {
204*fbe8378fSJason M. Bills         entityPrivileges = {
205*fbe8378fSJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
206*fbe8378fSJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
207*fbe8378fSJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
208*fbe8378fSJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
209*fbe8378fSJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
210*fbe8378fSJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
211*fbe8378fSJason M. Bills     }
212*fbe8378fSJason M. Bills 
213*fbe8378fSJason M. Bills   private:
214*fbe8378fSJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
215*fbe8378fSJason M. Bills                const std::vector<std::string> &params) override
216*fbe8378fSJason M. Bills     {
217*fbe8378fSJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
218*fbe8378fSJason M. Bills 
219*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["@odata.id"] =
220*fbe8378fSJason M. Bills             "/redfish/v1/Registries/OpenBMC";
221*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
222*fbe8378fSJason M. Bills             "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
223*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["@odata.context"] =
224*fbe8378fSJason M. Bills             "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
225*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Name"] = "Open BMC Message Registry File";
226*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Description"] =
227*fbe8378fSJason M. Bills             "Open BMC Message Registry File Location";
228*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Id"] =
229*fbe8378fSJason M. Bills             message_registries::openbmc::header.registryPrefix;
230*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Registry"] =
231*fbe8378fSJason M. Bills             message_registries::openbmc::header.id;
232*fbe8378fSJason M. Bills         nlohmann::json &messageRegistryLanguageArray =
233*fbe8378fSJason M. Bills             asyncResp->res.jsonValue["Languages"];
234*fbe8378fSJason M. Bills         messageRegistryLanguageArray = nlohmann::json::array();
235*fbe8378fSJason M. Bills         messageRegistryLanguageArray.push_back({"en"});
236*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Languages@odata.count"] =
237*fbe8378fSJason M. Bills             messageRegistryLanguageArray.size();
238*fbe8378fSJason M. Bills         nlohmann::json &messageRegistryLocationArray =
239*fbe8378fSJason M. Bills             asyncResp->res.jsonValue["Location"];
240*fbe8378fSJason M. Bills         messageRegistryLocationArray = nlohmann::json::array();
241*fbe8378fSJason M. Bills         messageRegistryLocationArray.push_back(
242*fbe8378fSJason M. Bills             {{"Language", "en"},
243*fbe8378fSJason M. Bills              {"Uri", "/redfish/v1/Registries/OpenBMC/OpenBMC"}});
244*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Location@odata.count"] =
245*fbe8378fSJason M. Bills             messageRegistryLocationArray.size();
246*fbe8378fSJason M. Bills     }
247*fbe8378fSJason M. Bills };
248*fbe8378fSJason M. Bills 
249*fbe8378fSJason M. Bills class OpenBMCMessageRegistry : public Node
250*fbe8378fSJason M. Bills {
251*fbe8378fSJason M. Bills   public:
252*fbe8378fSJason M. Bills     template <typename CrowApp>
253*fbe8378fSJason M. Bills     OpenBMCMessageRegistry(CrowApp &app) :
254*fbe8378fSJason M. Bills         Node(app, "/redfish/v1/Registries/OpenBMC/OpenBMC/")
255*fbe8378fSJason M. Bills     {
256*fbe8378fSJason M. Bills         entityPrivileges = {
257*fbe8378fSJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
258*fbe8378fSJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
259*fbe8378fSJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
260*fbe8378fSJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
261*fbe8378fSJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
262*fbe8378fSJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
263*fbe8378fSJason M. Bills     }
264*fbe8378fSJason M. Bills 
265*fbe8378fSJason M. Bills   private:
266*fbe8378fSJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
267*fbe8378fSJason M. Bills                const std::vector<std::string> &params) override
268*fbe8378fSJason M. Bills     {
269*fbe8378fSJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
270*fbe8378fSJason M. Bills 
271*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["@Redfish.Copyright"] =
272*fbe8378fSJason M. Bills             message_registries::openbmc::header.copyright;
273*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
274*fbe8378fSJason M. Bills             message_registries::openbmc::header.type;
275*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Id"] = message_registries::openbmc::header.id;
276*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Name"] =
277*fbe8378fSJason M. Bills             message_registries::openbmc::header.name;
278*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Language"] =
279*fbe8378fSJason M. Bills             message_registries::openbmc::header.language;
280*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["Description"] =
281*fbe8378fSJason M. Bills             message_registries::openbmc::header.description;
282*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["RegistryPrefix"] =
283*fbe8378fSJason M. Bills             message_registries::openbmc::header.registryPrefix;
284*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["RegistryVersion"] =
285*fbe8378fSJason M. Bills             message_registries::openbmc::header.registryVersion;
286*fbe8378fSJason M. Bills         asyncResp->res.jsonValue["OwningEntity"] =
287*fbe8378fSJason M. Bills             message_registries::openbmc::header.owningEntity;
288*fbe8378fSJason M. Bills         nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
289*fbe8378fSJason M. Bills         messageArray = nlohmann::json::array();
290*fbe8378fSJason M. Bills 
291*fbe8378fSJason M. Bills         // Go through the Message Registry and populate each Message
292*fbe8378fSJason M. Bills         for (const message_registries::MessageEntry &message :
293*fbe8378fSJason M. Bills              message_registries::openbmc::registry)
294*fbe8378fSJason M. Bills         {
295*fbe8378fSJason M. Bills             messageArray.push_back(
296*fbe8378fSJason M. Bills                 {{message.first,
297*fbe8378fSJason M. Bills                   {{"Description", message.second.description},
298*fbe8378fSJason M. Bills                    {"Message", message.second.message},
299*fbe8378fSJason M. Bills                    {"Severity", message.second.severity},
300*fbe8378fSJason M. Bills                    {"NumberOfArgs", message.second.numberOfArgs},
301*fbe8378fSJason M. Bills                    {"Resolution", message.second.resolution}}}});
302*fbe8378fSJason M. Bills             if (message.second.numberOfArgs > 0)
303*fbe8378fSJason M. Bills             {
304*fbe8378fSJason M. Bills                 nlohmann::json &messageParamArray =
305*fbe8378fSJason M. Bills                     messageArray.back()[message.first]["ParamTypes"];
306*fbe8378fSJason M. Bills                 for (int i = 0; i < message.second.numberOfArgs; i++)
307*fbe8378fSJason M. Bills                 {
308*fbe8378fSJason M. Bills                     messageParamArray.push_back(message.second.paramTypes[i]);
309*fbe8378fSJason M. Bills                 }
310*fbe8378fSJason M. Bills             }
311*fbe8378fSJason M. Bills         }
312*fbe8378fSJason M. Bills     }
313*fbe8378fSJason M. Bills };
314*fbe8378fSJason M. Bills 
31570304cb5SJason M. Bills } // namespace redfish
316