xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision 351d3063e86c5a6047c995ba72552bd82df86489)
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 
22 namespace redfish
23 {
24 
25 class MessageRegistryFileCollection : public Node
26 {
27   public:
28     template <typename CrowApp>
29     MessageRegistryFileCollection(CrowApp &app) :
30         Node(app, "/redfish/v1/Registries/")
31     {
32         entityPrivileges = {
33             {boost::beast::http::verb::get, {{"Login"}}},
34             {boost::beast::http::verb::head, {{"Login"}}},
35             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
36             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
37             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
38             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
39     }
40 
41   private:
42     /**
43      * Functions triggers appropriate requests on DBus
44      */
45     void doGet(crow::Response &res, const crow::Request &req,
46                const std::vector<std::string> &params) override
47     {
48         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
49         // Collections don't include the static data added by SubRoute because
50         // it has a duplicate entry for members
51         asyncResp->res.jsonValue["@odata.type"] =
52             "#MessageRegistryFileCollection.MessageRegistryFileCollection";
53         asyncResp->res.jsonValue["@odata.context"] =
54             "/redfish/v1/"
55             "$metadata#MessageRegistryFileCollection."
56             "MessageRegistryFileCollection";
57         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
58         asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
59         asyncResp->res.jsonValue["Description"] =
60             "Collection of MessageRegistryFiles";
61         nlohmann::json &messageRegistryFileArray =
62             asyncResp->res.jsonValue["Members"];
63         messageRegistryFileArray = nlohmann::json::array();
64         messageRegistryFileArray.push_back(
65             {{"@odata.id", "/redfish/v1/Registries/Base"}});
66         messageRegistryFileArray.push_back(
67             {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}});
68         asyncResp->res.jsonValue["Members@odata.count"] =
69             messageRegistryFileArray.size();
70     }
71 };
72 
73 class BaseMessageRegistryFile : public Node
74 {
75   public:
76     template <typename CrowApp>
77     BaseMessageRegistryFile(CrowApp &app) :
78         Node(app, "/redfish/v1/Registries/Base/")
79     {
80         entityPrivileges = {
81             {boost::beast::http::verb::get, {{"Login"}}},
82             {boost::beast::http::verb::head, {{"Login"}}},
83             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
84             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
85             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
86             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
87     }
88 
89   private:
90     void doGet(crow::Response &res, const crow::Request &req,
91                const std::vector<std::string> &params) override
92     {
93         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
94 
95         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries/Base";
96         asyncResp->res.jsonValue["@odata.type"] =
97             "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
98         asyncResp->res.jsonValue["@odata.context"] =
99             "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
100         asyncResp->res.jsonValue["Name"] = "Base Message Registry File";
101         asyncResp->res.jsonValue["Description"] =
102             "DMTF Base Message Registry File Location";
103         asyncResp->res.jsonValue["Id"] =
104             message_registries::base::header.registryPrefix;
105         asyncResp->res.jsonValue["Registry"] =
106             message_registries::base::header.id;
107         nlohmann::json &messageRegistryLanguageArray =
108             asyncResp->res.jsonValue["Languages"];
109         messageRegistryLanguageArray = nlohmann::json::array();
110         messageRegistryLanguageArray.push_back({"en"});
111         asyncResp->res.jsonValue["Languages@odata.count"] =
112             messageRegistryLanguageArray.size();
113         nlohmann::json &messageRegistryLocationArray =
114             asyncResp->res.jsonValue["Location"];
115         messageRegistryLocationArray = nlohmann::json::array();
116         messageRegistryLocationArray.push_back(
117             {{"Language", "en"},
118              {"PublicationUri",
119               "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
120              {"Uri", "/redfish/v1/Registries/Base/Base"}});
121         asyncResp->res.jsonValue["Location@odata.count"] =
122             messageRegistryLocationArray.size();
123     }
124 };
125 
126 class BaseMessageRegistry : public Node
127 {
128   public:
129     template <typename CrowApp>
130     BaseMessageRegistry(CrowApp &app) :
131         Node(app, "/redfish/v1/Registries/Base/Base/")
132     {
133         entityPrivileges = {
134             {boost::beast::http::verb::get, {{"Login"}}},
135             {boost::beast::http::verb::head, {{"Login"}}},
136             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
137             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
138             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
139             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
140     }
141 
142   private:
143     void doGet(crow::Response &res, const crow::Request &req,
144                const std::vector<std::string> &params) override
145     {
146         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
147 
148         asyncResp->res.jsonValue["@Redfish.Copyright"] =
149             message_registries::base::header.copyright;
150         asyncResp->res.jsonValue["@odata.type"] =
151             message_registries::base::header.type;
152         asyncResp->res.jsonValue["Id"] = message_registries::base::header.id;
153         asyncResp->res.jsonValue["Name"] =
154             message_registries::base::header.name;
155         asyncResp->res.jsonValue["Language"] =
156             message_registries::base::header.language;
157         asyncResp->res.jsonValue["Description"] =
158             message_registries::base::header.description;
159         asyncResp->res.jsonValue["RegistryPrefix"] =
160             message_registries::base::header.registryPrefix;
161         asyncResp->res.jsonValue["RegistryVersion"] =
162             message_registries::base::header.registryVersion;
163         asyncResp->res.jsonValue["OwningEntity"] =
164             message_registries::base::header.owningEntity;
165         nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
166         messageArray = nlohmann::json::array();
167 
168         // Go through the Message Registry and populate each Message
169         for (const message_registries::MessageEntry &message :
170              message_registries::base::registry)
171         {
172             messageArray.push_back(
173                 {{message.first,
174                   {{"Description", message.second.description},
175                    {"Message", message.second.message},
176                    {"Severity", message.second.severity},
177                    {"NumberOfArgs", message.second.numberOfArgs},
178                    {"Resolution", message.second.resolution}}}});
179             if (message.second.numberOfArgs > 0)
180             {
181                 nlohmann::json &messageParamArray =
182                     messageArray.back()[message.first]["ParamTypes"];
183                 for (const char *str : message.second.paramTypes)
184                 {
185                     if (str == nullptr)
186                     {
187                         break;
188                     }
189                     messageParamArray.push_back(str);
190                 }
191             }
192         }
193     }
194 };
195 
196 } // namespace redfish
197