xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision 70304cb594859b3862eeecc0a16c8e6e9a126530)
1*70304cb5SJason M. Bills /*
2*70304cb5SJason M. Bills // Copyright (c) 2019 Intel Corporation
3*70304cb5SJason M. Bills //
4*70304cb5SJason M. Bills // Licensed under the Apache License, Version 2.0 (the "License");
5*70304cb5SJason M. Bills // you may not use this file except in compliance with the License.
6*70304cb5SJason M. Bills // You may obtain a copy of the License at
7*70304cb5SJason M. Bills //
8*70304cb5SJason M. Bills //      http://www.apache.org/licenses/LICENSE-2.0
9*70304cb5SJason M. Bills //
10*70304cb5SJason M. Bills // Unless required by applicable law or agreed to in writing, software
11*70304cb5SJason M. Bills // distributed under the License is distributed on an "AS IS" BASIS,
12*70304cb5SJason M. Bills // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*70304cb5SJason M. Bills // See the License for the specific language governing permissions and
14*70304cb5SJason M. Bills // limitations under the License.
15*70304cb5SJason M. Bills */
16*70304cb5SJason M. Bills #pragma once
17*70304cb5SJason M. Bills 
18*70304cb5SJason M. Bills #include "node.hpp"
19*70304cb5SJason M. Bills #include "registries.hpp"
20*70304cb5SJason M. Bills #include "registries/base_message_registry.hpp"
21*70304cb5SJason M. Bills 
22*70304cb5SJason M. Bills namespace redfish
23*70304cb5SJason M. Bills {
24*70304cb5SJason M. Bills 
25*70304cb5SJason M. Bills class MessageRegistryFileCollection : public Node
26*70304cb5SJason M. Bills {
27*70304cb5SJason M. Bills   public:
28*70304cb5SJason M. Bills     template <typename CrowApp>
29*70304cb5SJason M. Bills     MessageRegistryFileCollection(CrowApp &app) :
30*70304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/")
31*70304cb5SJason M. Bills     {
32*70304cb5SJason M. Bills         entityPrivileges = {
33*70304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
34*70304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
35*70304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
36*70304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
37*70304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
38*70304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
39*70304cb5SJason M. Bills     }
40*70304cb5SJason M. Bills 
41*70304cb5SJason M. Bills   private:
42*70304cb5SJason M. Bills     /**
43*70304cb5SJason M. Bills      * Functions triggers appropriate requests on DBus
44*70304cb5SJason M. Bills      */
45*70304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
46*70304cb5SJason M. Bills                const std::vector<std::string> &params) override
47*70304cb5SJason M. Bills     {
48*70304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
49*70304cb5SJason M. Bills         // Collections don't include the static data added by SubRoute because
50*70304cb5SJason M. Bills         // it has a duplicate entry for members
51*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
52*70304cb5SJason M. Bills             "#MessageRegistryFileCollection.MessageRegistryFileCollection";
53*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.context"] =
54*70304cb5SJason M. Bills             "/redfish/v1/"
55*70304cb5SJason M. Bills             "$metadata#MessageRegistryFileCollection."
56*70304cb5SJason M. Bills             "MessageRegistryFileCollection";
57*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
58*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
59*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
60*70304cb5SJason M. Bills             "Collection of MessageRegistryFiles";
61*70304cb5SJason M. Bills         nlohmann::json &messageRegistryFileArray =
62*70304cb5SJason M. Bills             asyncResp->res.jsonValue["Members"];
63*70304cb5SJason M. Bills         messageRegistryFileArray = nlohmann::json::array();
64*70304cb5SJason M. Bills         messageRegistryFileArray.push_back(
65*70304cb5SJason M. Bills             {{"@odata.id", "/redfish/v1/Registries/Base"}});
66*70304cb5SJason M. Bills         messageRegistryFileArray.push_back(
67*70304cb5SJason M. Bills             {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}});
68*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
69*70304cb5SJason M. Bills             messageRegistryFileArray.size();
70*70304cb5SJason M. Bills     }
71*70304cb5SJason M. Bills };
72*70304cb5SJason M. Bills 
73*70304cb5SJason M. Bills class BaseMessageRegistryFile : public Node
74*70304cb5SJason M. Bills {
75*70304cb5SJason M. Bills   public:
76*70304cb5SJason M. Bills     template <typename CrowApp>
77*70304cb5SJason M. Bills     BaseMessageRegistryFile(CrowApp &app) :
78*70304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/")
79*70304cb5SJason M. Bills     {
80*70304cb5SJason M. Bills         entityPrivileges = {
81*70304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
82*70304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
83*70304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
84*70304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
85*70304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
86*70304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
87*70304cb5SJason M. Bills     }
88*70304cb5SJason M. Bills 
89*70304cb5SJason M. Bills   private:
90*70304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
91*70304cb5SJason M. Bills                const std::vector<std::string> &params) override
92*70304cb5SJason M. Bills     {
93*70304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
94*70304cb5SJason M. Bills 
95*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries/Base";
96*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
97*70304cb5SJason M. Bills             "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
98*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.context"] =
99*70304cb5SJason M. Bills             "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
100*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Base Message Registry File";
101*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
102*70304cb5SJason M. Bills             "DMTF Base Message Registry File Location";
103*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Id"] = "Base";
104*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Registry"] = "Base.1.4";
105*70304cb5SJason M. Bills         nlohmann::json &messageRegistryLanguageArray =
106*70304cb5SJason M. Bills             asyncResp->res.jsonValue["Languages"];
107*70304cb5SJason M. Bills         messageRegistryLanguageArray = nlohmann::json::array();
108*70304cb5SJason M. Bills         messageRegistryLanguageArray.push_back({"en"});
109*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Languages@odata.count"] =
110*70304cb5SJason M. Bills             messageRegistryLanguageArray.size();
111*70304cb5SJason M. Bills         nlohmann::json &messageRegistryLocationArray =
112*70304cb5SJason M. Bills             asyncResp->res.jsonValue["Location"];
113*70304cb5SJason M. Bills         messageRegistryLocationArray = nlohmann::json::array();
114*70304cb5SJason M. Bills         messageRegistryLocationArray.push_back(
115*70304cb5SJason M. Bills             {{"Language", "en"},
116*70304cb5SJason M. Bills              {"PublicationUri",
117*70304cb5SJason M. Bills               "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
118*70304cb5SJason M. Bills              {"Uri", "/redfish/v1/Registries/Base/Base"}});
119*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Location@odata.count"] =
120*70304cb5SJason M. Bills             messageRegistryLocationArray.size();
121*70304cb5SJason M. Bills     }
122*70304cb5SJason M. Bills };
123*70304cb5SJason M. Bills 
124*70304cb5SJason M. Bills class BaseMessageRegistry : public Node
125*70304cb5SJason M. Bills {
126*70304cb5SJason M. Bills   public:
127*70304cb5SJason M. Bills     template <typename CrowApp>
128*70304cb5SJason M. Bills     BaseMessageRegistry(CrowApp &app) :
129*70304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/Base/")
130*70304cb5SJason M. Bills     {
131*70304cb5SJason M. Bills         entityPrivileges = {
132*70304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
133*70304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
134*70304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
135*70304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
136*70304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
137*70304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
138*70304cb5SJason M. Bills     }
139*70304cb5SJason M. Bills 
140*70304cb5SJason M. Bills   private:
141*70304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
142*70304cb5SJason M. Bills                const std::vector<std::string> &params) override
143*70304cb5SJason M. Bills     {
144*70304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
145*70304cb5SJason M. Bills 
146*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@Redfish.Copyright"] =
147*70304cb5SJason M. Bills             "Copyright 2014-2018 DMTF. All rights reserved.";
148*70304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
149*70304cb5SJason M. Bills             "#MessageRegistry.v1_0_0.MessageRegistry";
150*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Id"] = "Base.1.4.0";
151*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Base Message Registry";
152*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Language"] = "en";
153*70304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
154*70304cb5SJason M. Bills             "This registry defines the base messages for Redfish";
155*70304cb5SJason M. Bills         asyncResp->res.jsonValue["RegistryPrefix"] = "Base";
156*70304cb5SJason M. Bills         asyncResp->res.jsonValue["RegistryVersion"] = "1.4.0";
157*70304cb5SJason M. Bills         asyncResp->res.jsonValue["OwningEntity"] = "DMTF";
158*70304cb5SJason M. Bills         nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
159*70304cb5SJason M. Bills         messageArray = nlohmann::json::array();
160*70304cb5SJason M. Bills 
161*70304cb5SJason M. Bills         // Go through the Message Registry and populate each Message
162*70304cb5SJason M. Bills         for (const message_registries::MessageEntry &message :
163*70304cb5SJason M. Bills              message_registries::base::registry)
164*70304cb5SJason M. Bills         {
165*70304cb5SJason M. Bills             messageArray.push_back(
166*70304cb5SJason M. Bills                 {{message.first,
167*70304cb5SJason M. Bills                   {{"Description", message.second.description},
168*70304cb5SJason M. Bills                    {"Message", message.second.message},
169*70304cb5SJason M. Bills                    {"Severity", message.second.severity},
170*70304cb5SJason M. Bills                    {"NumberOfArgs", message.second.numberOfArgs},
171*70304cb5SJason M. Bills                    {"Resolution", message.second.resolution}}}});
172*70304cb5SJason M. Bills             if (message.second.numberOfArgs > 0)
173*70304cb5SJason M. Bills             {
174*70304cb5SJason M. Bills                 nlohmann::json &messageParamArray =
175*70304cb5SJason M. Bills                     messageArray.back()[message.first]["ParamTypes"];
176*70304cb5SJason M. Bills                 for (const char *str : message.second.paramTypes)
177*70304cb5SJason M. Bills                 {
178*70304cb5SJason M. Bills                     if (str == nullptr)
179*70304cb5SJason M. Bills                     {
180*70304cb5SJason M. Bills                         break;
181*70304cb5SJason M. Bills                     }
182*70304cb5SJason M. Bills                     messageParamArray.push_back(str);
183*70304cb5SJason M. Bills                 }
184*70304cb5SJason M. Bills             }
185*70304cb5SJason M. Bills         }
186*70304cb5SJason M. Bills     }
187*70304cb5SJason M. Bills };
188*70304cb5SJason M. Bills 
189*70304cb5SJason M. Bills } // namespace redfish
190