xref: /openbmc/bmcweb/features/redfish/lib/message_registries.hpp (revision 351d3063e86c5a6047c995ba72552bd82df86489)
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"
2170304cb5SJason M. Bills 
2270304cb5SJason M. Bills namespace redfish
2370304cb5SJason M. Bills {
2470304cb5SJason M. Bills 
2570304cb5SJason M. Bills class MessageRegistryFileCollection : public Node
2670304cb5SJason M. Bills {
2770304cb5SJason M. Bills   public:
2870304cb5SJason M. Bills     template <typename CrowApp>
2970304cb5SJason M. Bills     MessageRegistryFileCollection(CrowApp &app) :
3070304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/")
3170304cb5SJason M. Bills     {
3270304cb5SJason M. Bills         entityPrivileges = {
3370304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
3470304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
3570304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3670304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3770304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3870304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3970304cb5SJason M. Bills     }
4070304cb5SJason M. Bills 
4170304cb5SJason M. Bills   private:
4270304cb5SJason M. Bills     /**
4370304cb5SJason M. Bills      * Functions triggers appropriate requests on DBus
4470304cb5SJason M. Bills      */
4570304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
4670304cb5SJason M. Bills                const std::vector<std::string> &params) override
4770304cb5SJason M. Bills     {
4870304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
4970304cb5SJason M. Bills         // Collections don't include the static data added by SubRoute because
5070304cb5SJason M. Bills         // it has a duplicate entry for members
5170304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
5270304cb5SJason M. Bills             "#MessageRegistryFileCollection.MessageRegistryFileCollection";
5370304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.context"] =
5470304cb5SJason M. Bills             "/redfish/v1/"
5570304cb5SJason M. Bills             "$metadata#MessageRegistryFileCollection."
5670304cb5SJason M. Bills             "MessageRegistryFileCollection";
5770304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
5870304cb5SJason M. Bills         asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
5970304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
6070304cb5SJason M. Bills             "Collection of MessageRegistryFiles";
6170304cb5SJason M. Bills         nlohmann::json &messageRegistryFileArray =
6270304cb5SJason M. Bills             asyncResp->res.jsonValue["Members"];
6370304cb5SJason M. Bills         messageRegistryFileArray = nlohmann::json::array();
6470304cb5SJason M. Bills         messageRegistryFileArray.push_back(
6570304cb5SJason M. Bills             {{"@odata.id", "/redfish/v1/Registries/Base"}});
6670304cb5SJason M. Bills         messageRegistryFileArray.push_back(
6770304cb5SJason M. Bills             {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}});
6870304cb5SJason M. Bills         asyncResp->res.jsonValue["Members@odata.count"] =
6970304cb5SJason M. Bills             messageRegistryFileArray.size();
7070304cb5SJason M. Bills     }
7170304cb5SJason M. Bills };
7270304cb5SJason M. Bills 
7370304cb5SJason M. Bills class BaseMessageRegistryFile : public Node
7470304cb5SJason M. Bills {
7570304cb5SJason M. Bills   public:
7670304cb5SJason M. Bills     template <typename CrowApp>
7770304cb5SJason M. Bills     BaseMessageRegistryFile(CrowApp &app) :
7870304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/")
7970304cb5SJason M. Bills     {
8070304cb5SJason M. Bills         entityPrivileges = {
8170304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
8270304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
8370304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
8470304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
8570304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
8670304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
8770304cb5SJason M. Bills     }
8870304cb5SJason M. Bills 
8970304cb5SJason M. Bills   private:
9070304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
9170304cb5SJason M. Bills                const std::vector<std::string> &params) override
9270304cb5SJason M. Bills     {
9370304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
9470304cb5SJason M. Bills 
9570304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries/Base";
9670304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
9770304cb5SJason M. Bills             "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
9870304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.context"] =
9970304cb5SJason M. Bills             "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
10070304cb5SJason M. Bills         asyncResp->res.jsonValue["Name"] = "Base Message Registry File";
10170304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
10270304cb5SJason M. Bills             "DMTF Base Message Registry File Location";
103*351d3063SJason M. Bills         asyncResp->res.jsonValue["Id"] =
104*351d3063SJason M. Bills             message_registries::base::header.registryPrefix;
105*351d3063SJason M. Bills         asyncResp->res.jsonValue["Registry"] =
106*351d3063SJason M. Bills             message_registries::base::header.id;
10770304cb5SJason M. Bills         nlohmann::json &messageRegistryLanguageArray =
10870304cb5SJason M. Bills             asyncResp->res.jsonValue["Languages"];
10970304cb5SJason M. Bills         messageRegistryLanguageArray = nlohmann::json::array();
11070304cb5SJason M. Bills         messageRegistryLanguageArray.push_back({"en"});
11170304cb5SJason M. Bills         asyncResp->res.jsonValue["Languages@odata.count"] =
11270304cb5SJason M. Bills             messageRegistryLanguageArray.size();
11370304cb5SJason M. Bills         nlohmann::json &messageRegistryLocationArray =
11470304cb5SJason M. Bills             asyncResp->res.jsonValue["Location"];
11570304cb5SJason M. Bills         messageRegistryLocationArray = nlohmann::json::array();
11670304cb5SJason M. Bills         messageRegistryLocationArray.push_back(
11770304cb5SJason M. Bills             {{"Language", "en"},
11870304cb5SJason M. Bills              {"PublicationUri",
11970304cb5SJason M. Bills               "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
12070304cb5SJason M. Bills              {"Uri", "/redfish/v1/Registries/Base/Base"}});
12170304cb5SJason M. Bills         asyncResp->res.jsonValue["Location@odata.count"] =
12270304cb5SJason M. Bills             messageRegistryLocationArray.size();
12370304cb5SJason M. Bills     }
12470304cb5SJason M. Bills };
12570304cb5SJason M. Bills 
12670304cb5SJason M. Bills class BaseMessageRegistry : public Node
12770304cb5SJason M. Bills {
12870304cb5SJason M. Bills   public:
12970304cb5SJason M. Bills     template <typename CrowApp>
13070304cb5SJason M. Bills     BaseMessageRegistry(CrowApp &app) :
13170304cb5SJason M. Bills         Node(app, "/redfish/v1/Registries/Base/Base/")
13270304cb5SJason M. Bills     {
13370304cb5SJason M. Bills         entityPrivileges = {
13470304cb5SJason M. Bills             {boost::beast::http::verb::get, {{"Login"}}},
13570304cb5SJason M. Bills             {boost::beast::http::verb::head, {{"Login"}}},
13670304cb5SJason M. Bills             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
13770304cb5SJason M. Bills             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
13870304cb5SJason M. Bills             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
13970304cb5SJason M. Bills             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
14070304cb5SJason M. Bills     }
14170304cb5SJason M. Bills 
14270304cb5SJason M. Bills   private:
14370304cb5SJason M. Bills     void doGet(crow::Response &res, const crow::Request &req,
14470304cb5SJason M. Bills                const std::vector<std::string> &params) override
14570304cb5SJason M. Bills     {
14670304cb5SJason M. Bills         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
14770304cb5SJason M. Bills 
14870304cb5SJason M. Bills         asyncResp->res.jsonValue["@Redfish.Copyright"] =
149*351d3063SJason M. Bills             message_registries::base::header.copyright;
15070304cb5SJason M. Bills         asyncResp->res.jsonValue["@odata.type"] =
151*351d3063SJason M. Bills             message_registries::base::header.type;
152*351d3063SJason M. Bills         asyncResp->res.jsonValue["Id"] = message_registries::base::header.id;
153*351d3063SJason M. Bills         asyncResp->res.jsonValue["Name"] =
154*351d3063SJason M. Bills             message_registries::base::header.name;
155*351d3063SJason M. Bills         asyncResp->res.jsonValue["Language"] =
156*351d3063SJason M. Bills             message_registries::base::header.language;
15770304cb5SJason M. Bills         asyncResp->res.jsonValue["Description"] =
158*351d3063SJason M. Bills             message_registries::base::header.description;
159*351d3063SJason M. Bills         asyncResp->res.jsonValue["RegistryPrefix"] =
160*351d3063SJason M. Bills             message_registries::base::header.registryPrefix;
161*351d3063SJason M. Bills         asyncResp->res.jsonValue["RegistryVersion"] =
162*351d3063SJason M. Bills             message_registries::base::header.registryVersion;
163*351d3063SJason M. Bills         asyncResp->res.jsonValue["OwningEntity"] =
164*351d3063SJason M. Bills             message_registries::base::header.owningEntity;
16570304cb5SJason M. Bills         nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
16670304cb5SJason M. Bills         messageArray = nlohmann::json::array();
16770304cb5SJason M. Bills 
16870304cb5SJason M. Bills         // Go through the Message Registry and populate each Message
16970304cb5SJason M. Bills         for (const message_registries::MessageEntry &message :
17070304cb5SJason M. Bills              message_registries::base::registry)
17170304cb5SJason M. Bills         {
17270304cb5SJason M. Bills             messageArray.push_back(
17370304cb5SJason M. Bills                 {{message.first,
17470304cb5SJason M. Bills                   {{"Description", message.second.description},
17570304cb5SJason M. Bills                    {"Message", message.second.message},
17670304cb5SJason M. Bills                    {"Severity", message.second.severity},
17770304cb5SJason M. Bills                    {"NumberOfArgs", message.second.numberOfArgs},
17870304cb5SJason M. Bills                    {"Resolution", message.second.resolution}}}});
17970304cb5SJason M. Bills             if (message.second.numberOfArgs > 0)
18070304cb5SJason M. Bills             {
18170304cb5SJason M. Bills                 nlohmann::json &messageParamArray =
18270304cb5SJason M. Bills                     messageArray.back()[message.first]["ParamTypes"];
18370304cb5SJason M. Bills                 for (const char *str : message.second.paramTypes)
18470304cb5SJason M. Bills                 {
18570304cb5SJason M. Bills                     if (str == nullptr)
18670304cb5SJason M. Bills                     {
18770304cb5SJason M. Bills                         break;
18870304cb5SJason M. Bills                     }
18970304cb5SJason M. Bills                     messageParamArray.push_back(str);
19070304cb5SJason M. Bills                 }
19170304cb5SJason M. Bills             }
19270304cb5SJason M. Bills         }
19370304cb5SJason M. Bills     }
19470304cb5SJason M. Bills };
19570304cb5SJason M. Bills 
19670304cb5SJason M. Bills } // namespace redfish
197