xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision 14c8aee20d25e59bda722e5d09527ee675c926e2)
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"
21fbe8378fSJason 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         // Collections don't include the static data added by SubRoute because
5070304cb5SJason M. Bills         // it has a duplicate entry for members
51*14c8aee2SEd Tanous 
52*14c8aee2SEd Tanous         res.jsonValue = {
53*14c8aee2SEd Tanous             {"@odata.type",
54*14c8aee2SEd Tanous              "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
55*14c8aee2SEd Tanous             {"@odata.context", "/redfish/v1/"
5670304cb5SJason M. Bills                                "$metadata#MessageRegistryFileCollection."
57*14c8aee2SEd Tanous                                "MessageRegistryFileCollection"},
58*14c8aee2SEd Tanous             {"@odata.id", "/redfish/v1/Registries"},
59*14c8aee2SEd Tanous             {"Name", "MessageRegistryFile Collection"},
60*14c8aee2SEd Tanous             {"Description", "Collection of MessageRegistryFiles"},
61*14c8aee2SEd Tanous             {"Members@odata.count", 2},
62*14c8aee2SEd Tanous             {"Members",
63*14c8aee2SEd Tanous              {{{"@odata.id", "/redfish/v1/Registries/Base"}},
64*14c8aee2SEd Tanous               {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
65*14c8aee2SEd Tanous 
66*14c8aee2SEd Tanous         res.end();
6770304cb5SJason M. Bills     }
6870304cb5SJason M. Bills };
6970304cb5SJason M. Bills 
7070304cb5SJason M. Bills class BaseMessageRegistryFile : public Node
7170304cb5SJason M. Bills {
7270304cb5SJason M. Bills   public:
7370304cb5SJason M. Bills     template <typename CrowApp>
7470304cb5SJason M. Bills     BaseMessageRegistryFile(CrowApp &app) :
7570304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/")
7670304cb5SJason M. Bills     {
7770304cb5SJason M. Bills         entityPrivileges = {
7870304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
7970304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
8070304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
8170304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
8270304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
8370304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
8470304cb5SJason M. Bills     }
8570304cb5SJason M. Bills 
8670304cb5SJason M. Bills   private:
8770304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
8870304cb5SJason M. Bills                const std::vector<std::string> &params) override
8970304cb5SJason M. Bills     {
90*14c8aee2SEd Tanous         res.jsonValue = {
91*14c8aee2SEd Tanous             {"@odata.id", "/redfish/v1/Registries/Base"},
92*14c8aee2SEd Tanous             {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
93*14c8aee2SEd Tanous             {"@odata.context",
94*14c8aee2SEd Tanous              "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile"},
95*14c8aee2SEd Tanous             {"Name", "Base Message Registry File"},
96*14c8aee2SEd Tanous             {"Description", "DMTF Base Message Registry File Location"},
97*14c8aee2SEd Tanous             {"Id", message_registries::base::header.registryPrefix},
98*14c8aee2SEd Tanous             {"Registry", message_registries::base::header.id},
99*14c8aee2SEd Tanous             {"Languages", {"en"}},
100*14c8aee2SEd Tanous             {"Languages@odata.count", 1},
101*14c8aee2SEd Tanous             {"Location",
102*14c8aee2SEd Tanous              {{{"Language", "en"},
10370304cb5SJason M. Bills                {"PublicationUri",
10470304cb5SJason M. Bills                 "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
105*14c8aee2SEd Tanous                {"Uri", "/redfish/v1/Registries/Base/Base"}}}},
106*14c8aee2SEd Tanous             {"Location@odata.count", 1}};
107*14c8aee2SEd Tanous         res.end();
10870304cb5SJason M. Bills     }
10970304cb5SJason M. Bills };
11070304cb5SJason M. Bills 
11170304cb5SJason M. Bills class BaseMessageRegistry : public Node
11270304cb5SJason M. Bills {
11370304cb5SJason M. Bills   public:
11470304cb5SJason M. Bills     template <typename CrowApp>
11570304cb5SJason M. Bills     BaseMessageRegistry(CrowApp &app) :
11670304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/Base/")
11770304cb5SJason M. Bills     {
11870304cb5SJason M. Bills         entityPrivileges = {
11970304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
12070304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
12170304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
12270304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
12370304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
12470304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
12570304cb5SJason M. Bills     }
12670304cb5SJason M. Bills 
12770304cb5SJason M. Bills   private:
12870304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
12970304cb5SJason M. Bills                const std::vector<std::string> &params) override
13070304cb5SJason M. Bills     {
131*14c8aee2SEd Tanous         res.jsonValue = {
132*14c8aee2SEd Tanous             {"@Redfish.Copyright", message_registries::base::header.copyright},
133*14c8aee2SEd Tanous             {"@odata.type", message_registries::base::header.type},
134*14c8aee2SEd Tanous             {"Id", message_registries::base::header.id},
135*14c8aee2SEd Tanous             {"Name", message_registries::base::header.name},
136*14c8aee2SEd Tanous             {"Language", message_registries::base::header.language},
137*14c8aee2SEd Tanous             {"Description", message_registries::base::header.description},
138*14c8aee2SEd Tanous             {"RegistryPrefix", message_registries::base::header.registryPrefix},
139*14c8aee2SEd Tanous             {"RegistryVersion",
140*14c8aee2SEd Tanous              message_registries::base::header.registryVersion},
141*14c8aee2SEd Tanous             {"OwningEntity", message_registries::base::header.owningEntity}};
14270304cb5SJason M. Bills 
143*14c8aee2SEd Tanous         nlohmann::json &messageObj = res.jsonValue["Messages"];
14470304cb5SJason M. Bills 
14570304cb5SJason M. Bills         // Go through the Message Registry and populate each Message
14670304cb5SJason M. Bills         for (const message_registries::MessageEntry &message :
14770304cb5SJason M. Bills              message_registries::base::registry)
14870304cb5SJason M. Bills         {
149*14c8aee2SEd Tanous             nlohmann::json &obj = messageObj[message.first];
150*14c8aee2SEd Tanous             obj = {{"Description", message.second.description},
15170304cb5SJason M. Bills                    {"Message", message.second.message},
15270304cb5SJason M. Bills                    {"Severity", message.second.severity},
15370304cb5SJason M. Bills                    {"NumberOfArgs", message.second.numberOfArgs},
154*14c8aee2SEd Tanous                    {"Resolution", message.second.resolution}};
15570304cb5SJason M. Bills             if (message.second.numberOfArgs > 0)
15670304cb5SJason M. Bills             {
157*14c8aee2SEd Tanous                 nlohmann::json &messageParamArray = obj["ParamTypes"];
15870304cb5SJason M. Bills                 for (const char *str : message.second.paramTypes)
15970304cb5SJason M. Bills                 {
16070304cb5SJason M. Bills                     if (str == nullptr)
16170304cb5SJason M. Bills                     {
16270304cb5SJason M. Bills                         break;
16370304cb5SJason M. Bills                     }
16470304cb5SJason M. Bills                     messageParamArray.push_back(str);
16570304cb5SJason M. Bills                 }
16670304cb5SJason M. Bills             }
16770304cb5SJason M. Bills         }
168*14c8aee2SEd Tanous         res.end();
16970304cb5SJason M. Bills     }
17070304cb5SJason M. Bills };
17170304cb5SJason M. Bills 
172fbe8378fSJason M. Bills class OpenBMCMessageRegistryFile : public Node
173fbe8378fSJason M. Bills {
174fbe8378fSJason M. Bills   public:
175fbe8378fSJason M. Bills     template <typename CrowApp>
176fbe8378fSJason M. Bills     OpenBMCMessageRegistryFile(CrowApp &app) :
177fbe8378fSJason M. Bills         Node(app, "/redfish/v1/Registries/OpenBMC/")
178fbe8378fSJason M. Bills     {
179fbe8378fSJason M. Bills         entityPrivileges = {
180fbe8378fSJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
181fbe8378fSJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
182fbe8378fSJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
183fbe8378fSJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
184fbe8378fSJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
185fbe8378fSJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
186fbe8378fSJason M. Bills     }
187fbe8378fSJason M. Bills 
188fbe8378fSJason M. Bills   private:
189fbe8378fSJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
190fbe8378fSJason M. Bills                const std::vector<std::string> &params) override
191fbe8378fSJason M. Bills     {
192*14c8aee2SEd Tanous         res.jsonValue = {
193*14c8aee2SEd Tanous             {"@odata.id", "/redfish/v1/Registries/OpenBMC"},
194*14c8aee2SEd Tanous             {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
195*14c8aee2SEd Tanous             {"@odata.context",
196*14c8aee2SEd Tanous              "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile"},
197*14c8aee2SEd Tanous             {"Name", "Open BMC Message Registry File"},
198*14c8aee2SEd Tanous             {"Description", "Open BMC Message Registry File Location"},
199*14c8aee2SEd Tanous             {"Id", message_registries::openbmc::header.registryPrefix},
200*14c8aee2SEd Tanous             {"Registry", message_registries::openbmc::header.id},
201*14c8aee2SEd Tanous             {"Languages", {"en"}},
202*14c8aee2SEd Tanous             {"Languages@odata.count", 1},
203*14c8aee2SEd Tanous             {"Location",
204*14c8aee2SEd Tanous              {{{"Language", "en"},
205*14c8aee2SEd Tanous                {"Uri", "/redfish/v1/Registries/OpenBMC/OpenBMC"}}}},
206*14c8aee2SEd Tanous             {"Location@odata.count", 1}};
207fbe8378fSJason M. Bills 
208*14c8aee2SEd Tanous         res.end();
209fbe8378fSJason M. Bills     }
210fbe8378fSJason M. Bills };
211fbe8378fSJason M. Bills 
212fbe8378fSJason M. Bills class OpenBMCMessageRegistry : public Node
213fbe8378fSJason M. Bills {
214fbe8378fSJason M. Bills   public:
215fbe8378fSJason M. Bills     template <typename CrowApp>
216fbe8378fSJason M. Bills     OpenBMCMessageRegistry(CrowApp &app) :
217fbe8378fSJason M. Bills         Node(app, "/redfish/v1/Registries/OpenBMC/OpenBMC/")
218fbe8378fSJason M. Bills     {
219fbe8378fSJason M. Bills         entityPrivileges = {
220fbe8378fSJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
221fbe8378fSJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
222fbe8378fSJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
223fbe8378fSJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
224fbe8378fSJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
225fbe8378fSJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
226fbe8378fSJason M. Bills     }
227fbe8378fSJason M. Bills 
228fbe8378fSJason M. Bills   private:
229fbe8378fSJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
230fbe8378fSJason M. Bills                const std::vector<std::string> &params) override
231fbe8378fSJason M. Bills     {
232*14c8aee2SEd Tanous         res.jsonValue = {
233*14c8aee2SEd Tanous             {"@Redfish.Copyright",
234*14c8aee2SEd Tanous              message_registries::openbmc::header.copyright},
235*14c8aee2SEd Tanous             {"@odata.type", message_registries::openbmc::header.type},
236*14c8aee2SEd Tanous             {"Id", message_registries::openbmc::header.id},
237*14c8aee2SEd Tanous             {"Name", message_registries::openbmc::header.name},
238*14c8aee2SEd Tanous             {"Language", message_registries::openbmc::header.language},
239*14c8aee2SEd Tanous             {"Description", message_registries::openbmc::header.description},
240*14c8aee2SEd Tanous             {"RegistryPrefix",
241*14c8aee2SEd Tanous              message_registries::openbmc::header.registryPrefix},
242*14c8aee2SEd Tanous             {"RegistryVersion",
243*14c8aee2SEd Tanous              message_registries::openbmc::header.registryVersion},
244*14c8aee2SEd Tanous             {"OwningEntity", message_registries::openbmc::header.owningEntity}};
245fbe8378fSJason M. Bills 
246*14c8aee2SEd Tanous         nlohmann::json &messageObj = res.jsonValue["Messages"];
247fbe8378fSJason M. Bills         // Go through the Message Registry and populate each Message
248fbe8378fSJason M. Bills         for (const message_registries::MessageEntry &message :
249fbe8378fSJason M. Bills              message_registries::openbmc::registry)
250fbe8378fSJason M. Bills         {
251*14c8aee2SEd Tanous             nlohmann::json &obj = messageObj[message.first];
252*14c8aee2SEd Tanous             obj = {{"Description", message.second.description},
253fbe8378fSJason M. Bills                    {"Message", message.second.message},
254fbe8378fSJason M. Bills                    {"Severity", message.second.severity},
255fbe8378fSJason M. Bills                    {"NumberOfArgs", message.second.numberOfArgs},
256*14c8aee2SEd Tanous                    {"Resolution", message.second.resolution}};
257fbe8378fSJason M. Bills             if (message.second.numberOfArgs > 0)
258fbe8378fSJason M. Bills             {
259*14c8aee2SEd Tanous                 nlohmann::json &messageParamArray = obj["ParamTypes"];
260fbe8378fSJason M. Bills                 for (int i = 0; i < message.second.numberOfArgs; i++)
261fbe8378fSJason M. Bills                 {
262fbe8378fSJason M. Bills                     messageParamArray.push_back(message.second.paramTypes[i]);
263fbe8378fSJason M. Bills                 }
264fbe8378fSJason M. Bills             }
265fbe8378fSJason M. Bills         }
266*14c8aee2SEd Tanous         res.end();
267fbe8378fSJason M. Bills     }
268fbe8378fSJason M. Bills };
269fbe8378fSJason M. Bills 
27070304cb5SJason M. Bills } // namespace redfish
271