xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision 74eec26b6ba3b14716db87cb8a837c33bdb69f62)
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"
22*74eec26bSSunitha Harish #include "registries/resource_event_message_registry.hpp"
23e51c710eSJames Feist #include "registries/task_event_message_registry.hpp"
2470304cb5SJason M. Bills 
2570304cb5SJason M. Bills namespace redfish
2670304cb5SJason M. Bills {
2770304cb5SJason M. Bills 
2870304cb5SJason M. Bills class MessageRegistryFileCollection : public Node
2970304cb5SJason M. Bills {
3070304cb5SJason M. Bills   public:
3170304cb5SJason M. Bills     template <typename CrowApp>
3270304cb5SJason M. Bills     MessageRegistryFileCollection(CrowApp& app) :
3370304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/")
3470304cb5SJason M. Bills     {
3570304cb5SJason M. Bills         entityPrivileges = {
3670304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
3770304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
3870304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3970304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
4070304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
4170304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
4270304cb5SJason M. Bills     }
4370304cb5SJason M. Bills 
4470304cb5SJason M. Bills   private:
4570304cb5SJason M. Bills     /**
4670304cb5SJason M. Bills      * Functions triggers appropriate requests on DBus
4770304cb5SJason M. Bills      */
4870304cb5SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
4970304cb5SJason M. Bills                const std::vector<std::string>& params) override
5070304cb5SJason M. Bills     {
5170304cb5SJason M. Bills         // Collections don't include the static data added by SubRoute because
5270304cb5SJason M. Bills         // it has a duplicate entry for members
5314c8aee2SEd Tanous 
5414c8aee2SEd Tanous         res.jsonValue = {
5514c8aee2SEd Tanous             {"@odata.type",
5614c8aee2SEd Tanous              "#MessageRegistryFileCollection.MessageRegistryFileCollection"},
5714c8aee2SEd Tanous             {"@odata.id", "/redfish/v1/Registries"},
5814c8aee2SEd Tanous             {"Name", "MessageRegistryFile Collection"},
5914c8aee2SEd Tanous             {"Description", "Collection of MessageRegistryFiles"},
60*74eec26bSSunitha Harish             {"Members@odata.count", 4},
6114c8aee2SEd Tanous             {"Members",
6214c8aee2SEd Tanous              {{{"@odata.id", "/redfish/v1/Registries/Base"}},
63e51c710eSJames Feist               {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
64*74eec26bSSunitha Harish               {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
6514c8aee2SEd Tanous               {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
6614c8aee2SEd Tanous 
6714c8aee2SEd Tanous         res.end();
6870304cb5SJason M. Bills     }
6970304cb5SJason M. Bills };
7070304cb5SJason M. Bills 
71e51c710eSJames Feist class MessageRegistryFile : public Node
7270304cb5SJason M. Bills {
7370304cb5SJason M. Bills   public:
7470304cb5SJason M. Bills     template <typename CrowApp>
75e51c710eSJames Feist     MessageRegistryFile(CrowApp& app) :
76e51c710eSJames Feist         Node(app, "/redfish/v1/Registries/<str>/", std::string())
7770304cb5SJason M. Bills     {
7870304cb5SJason M. Bills         entityPrivileges = {
7970304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
8070304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
8170304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
8270304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
8370304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
8470304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
8570304cb5SJason M. Bills     }
8670304cb5SJason M. Bills 
8770304cb5SJason M. Bills   private:
8870304cb5SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
8970304cb5SJason M. Bills                const std::vector<std::string>& params) override
9070304cb5SJason M. Bills     {
91e51c710eSJames Feist         if (params.size() != 1)
92e51c710eSJames Feist         {
93e51c710eSJames Feist             messages::internalError(res);
94e51c710eSJames Feist             res.end();
95e51c710eSJames Feist             return;
96e51c710eSJames Feist         }
97e51c710eSJames Feist 
98e51c710eSJames Feist         const std::string& registry = params[0];
99e51c710eSJames Feist         const message_registries::Header* header;
100e51c710eSJames Feist         std::string dmtf = "DMTF ";
101e51c710eSJames Feist         const char* url = nullptr;
102e51c710eSJames Feist 
103e51c710eSJames Feist         if (registry == "Base")
104e51c710eSJames Feist         {
105e51c710eSJames Feist             header = &message_registries::base::header;
106e51c710eSJames Feist             url = message_registries::base::url;
107e51c710eSJames Feist         }
108e51c710eSJames Feist         else if (registry == "TaskEvent")
109e51c710eSJames Feist         {
110e51c710eSJames Feist             header = &message_registries::task_event::header;
111e51c710eSJames Feist             url = message_registries::task_event::url;
112e51c710eSJames Feist         }
113e51c710eSJames Feist         else if (registry == "OpenBMC")
114e51c710eSJames Feist         {
115e51c710eSJames Feist             header = &message_registries::openbmc::header;
116e51c710eSJames Feist             dmtf.clear();
117e51c710eSJames Feist         }
118*74eec26bSSunitha Harish         else if (registry == "ResourceEvent")
119*74eec26bSSunitha Harish         {
120*74eec26bSSunitha Harish             header = &message_registries::resource_event::header;
121*74eec26bSSunitha Harish             url = message_registries::resource_event::url;
122*74eec26bSSunitha Harish         }
123e51c710eSJames Feist         else
124e51c710eSJames Feist         {
125e51c710eSJames Feist             messages::resourceNotFound(
126e51c710eSJames Feist                 res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
127e51c710eSJames Feist                 registry);
128e51c710eSJames Feist             res.end();
129e51c710eSJames Feist             return;
130e51c710eSJames Feist         }
131e51c710eSJames Feist 
13214c8aee2SEd Tanous         res.jsonValue = {
133e51c710eSJames Feist             {"@odata.id", "/redfish/v1/Registries/" + registry},
13414c8aee2SEd Tanous             {"@odata.type", "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
135e51c710eSJames Feist             {"Name", registry + " Message Registry File"},
136e51c710eSJames Feist             {"Description",
137e51c710eSJames Feist              dmtf + registry + " Message Registry File Location"},
138e51c710eSJames Feist             {"Id", header->registryPrefix},
139e51c710eSJames Feist             {"Registry", header->id},
14014c8aee2SEd Tanous             {"Languages", {"en"}},
14114c8aee2SEd Tanous             {"Languages@odata.count", 1},
14214c8aee2SEd Tanous             {"Location",
14314c8aee2SEd Tanous              {{{"Language", "en"},
144e51c710eSJames Feist                {"Uri",
145e51c710eSJames Feist                 "/redfish/v1/Registries/" + registry + "/" + registry}}}},
14614c8aee2SEd Tanous             {"Location@odata.count", 1}};
147e51c710eSJames Feist 
148e51c710eSJames Feist         if (url != nullptr)
149e51c710eSJames Feist         {
150e51c710eSJames Feist             res.jsonValue["Location"][0]["PublicationUri"] = url;
151e51c710eSJames Feist         }
152e51c710eSJames Feist 
15314c8aee2SEd Tanous         res.end();
15470304cb5SJason M. Bills     }
15570304cb5SJason M. Bills };
15670304cb5SJason M. Bills 
157e51c710eSJames Feist class MessageRegistry : public Node
15870304cb5SJason M. Bills {
15970304cb5SJason M. Bills   public:
16070304cb5SJason M. Bills     template <typename CrowApp>
161e51c710eSJames Feist     MessageRegistry(CrowApp& app) :
162e51c710eSJames Feist         Node(app, "/redfish/v1/Registries/<str>/<str>/", std::string(),
163e51c710eSJames Feist              std::string())
16470304cb5SJason M. Bills     {
16570304cb5SJason M. Bills         entityPrivileges = {
16670304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
16770304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
16870304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
16970304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
17070304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
17170304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
17270304cb5SJason M. Bills     }
17370304cb5SJason M. Bills 
17470304cb5SJason M. Bills   private:
17570304cb5SJason M. Bills     void doGet(crow::Response& res, const crow::Request& req,
17670304cb5SJason M. Bills                const std::vector<std::string>& params) override
17770304cb5SJason M. Bills     {
178e51c710eSJames Feist         if (params.size() != 2)
179e51c710eSJames Feist         {
180e51c710eSJames Feist             messages::internalError(res);
181e51c710eSJames Feist             res.end();
182e51c710eSJames Feist             return;
183e51c710eSJames Feist         }
184e51c710eSJames Feist 
185e51c710eSJames Feist         const std::string& registry = params[0];
186e51c710eSJames Feist         const std::string& registry1 = params[1];
187e51c710eSJames Feist 
188e51c710eSJames Feist         const message_registries::Header* header;
189e51c710eSJames Feist         std::vector<const message_registries::MessageEntry*> registryEntries;
190e51c710eSJames Feist         if (registry == "Base")
191e51c710eSJames Feist         {
192e51c710eSJames Feist             header = &message_registries::base::header;
193e51c710eSJames Feist             for (const message_registries::MessageEntry& entry :
194e51c710eSJames Feist                  message_registries::base::registry)
195e51c710eSJames Feist             {
196e51c710eSJames Feist                 registryEntries.emplace_back(&entry);
197e51c710eSJames Feist             }
198e51c710eSJames Feist         }
199e51c710eSJames Feist         else if (registry == "TaskEvent")
200e51c710eSJames Feist         {
201e51c710eSJames Feist             header = &message_registries::task_event::header;
202e51c710eSJames Feist             for (const message_registries::MessageEntry& entry :
203e51c710eSJames Feist                  message_registries::task_event::registry)
204e51c710eSJames Feist             {
205e51c710eSJames Feist                 registryEntries.emplace_back(&entry);
206e51c710eSJames Feist             }
207e51c710eSJames Feist         }
208e51c710eSJames Feist         else if (registry == "OpenBMC")
209e51c710eSJames Feist         {
210e51c710eSJames Feist             header = &message_registries::openbmc::header;
211e51c710eSJames Feist             for (const message_registries::MessageEntry& entry :
212e51c710eSJames Feist                  message_registries::openbmc::registry)
213e51c710eSJames Feist             {
214e51c710eSJames Feist                 registryEntries.emplace_back(&entry);
215e51c710eSJames Feist             }
216e51c710eSJames Feist         }
217*74eec26bSSunitha Harish         else if (registry == "ResourceEvent")
218*74eec26bSSunitha Harish         {
219*74eec26bSSunitha Harish             header = &message_registries::resource_event::header;
220*74eec26bSSunitha Harish             for (const message_registries::MessageEntry& entry :
221*74eec26bSSunitha Harish                  message_registries::resource_event::registry)
222*74eec26bSSunitha Harish             {
223*74eec26bSSunitha Harish                 registryEntries.emplace_back(&entry);
224*74eec26bSSunitha Harish             }
225*74eec26bSSunitha Harish         }
226e51c710eSJames Feist         else
227e51c710eSJames Feist         {
228e51c710eSJames Feist             messages::resourceNotFound(
229e51c710eSJames Feist                 res, "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
230e51c710eSJames Feist                 registry);
231e51c710eSJames Feist             res.end();
232e51c710eSJames Feist             return;
233e51c710eSJames Feist         }
234e51c710eSJames Feist 
235e51c710eSJames Feist         if (registry != registry1)
236e51c710eSJames Feist         {
237e51c710eSJames Feist             messages::resourceNotFound(res, header->type, registry1);
238e51c710eSJames Feist             res.end();
239e51c710eSJames Feist             return;
240e51c710eSJames Feist         }
241e51c710eSJames Feist 
242e51c710eSJames Feist         res.jsonValue = {{"@Redfish.Copyright", header->copyright},
243e51c710eSJames Feist                          {"@odata.type", header->type},
244e51c710eSJames Feist                          {"Id", header->id},
245e51c710eSJames Feist                          {"Name", header->name},
246e51c710eSJames Feist                          {"Language", header->language},
247e51c710eSJames Feist                          {"Description", header->description},
248e51c710eSJames Feist                          {"RegistryPrefix", header->registryPrefix},
249e51c710eSJames Feist                          {"RegistryVersion", header->registryVersion},
250e51c710eSJames Feist                          {"OwningEntity", header->owningEntity}};
25170304cb5SJason M. Bills 
25214c8aee2SEd Tanous         nlohmann::json& messageObj = res.jsonValue["Messages"];
25370304cb5SJason M. Bills 
25470304cb5SJason M. Bills         // Go through the Message Registry and populate each Message
255e51c710eSJames Feist         for (const message_registries::MessageEntry* message : registryEntries)
25670304cb5SJason M. Bills         {
257e51c710eSJames Feist             nlohmann::json& obj = messageObj[message->first];
258e51c710eSJames Feist             obj = {{"Description", message->second.description},
259e51c710eSJames Feist                    {"Message", message->second.message},
260e51c710eSJames Feist                    {"Severity", message->second.severity},
261e7808c93SGunnar Mills                    {"MessageSeverity", message->second.messageSeverity},
262e51c710eSJames Feist                    {"NumberOfArgs", message->second.numberOfArgs},
263e51c710eSJames Feist                    {"Resolution", message->second.resolution}};
264e51c710eSJames Feist             if (message->second.numberOfArgs > 0)
26570304cb5SJason M. Bills             {
26614c8aee2SEd Tanous                 nlohmann::json& messageParamArray = obj["ParamTypes"];
267e51c710eSJames Feist                 for (const char* str : message->second.paramTypes)
26870304cb5SJason M. Bills                 {
26970304cb5SJason M. Bills                     if (str == nullptr)
27070304cb5SJason M. Bills                     {
27170304cb5SJason M. Bills                         break;
27270304cb5SJason M. Bills                     }
27370304cb5SJason M. Bills                     messageParamArray.push_back(str);
27470304cb5SJason M. Bills                 }
27570304cb5SJason M. Bills             }
27670304cb5SJason M. Bills         }
27714c8aee2SEd Tanous         res.end();
27870304cb5SJason M. Bills     }
27970304cb5SJason M. Bills };
28070304cb5SJason M. Bills 
28170304cb5SJason M. Bills } // namespace redfish
282