blob: f01caf901b9b2a8454fd4d826d5dc71e1dc76788 [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001/*
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
22namespace redfish
23{
24
25class 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
73class 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"] = "Base";
104 asyncResp->res.jsonValue["Registry"] = "Base.1.4";
105 nlohmann::json &messageRegistryLanguageArray =
106 asyncResp->res.jsonValue["Languages"];
107 messageRegistryLanguageArray = nlohmann::json::array();
108 messageRegistryLanguageArray.push_back({"en"});
109 asyncResp->res.jsonValue["Languages@odata.count"] =
110 messageRegistryLanguageArray.size();
111 nlohmann::json &messageRegistryLocationArray =
112 asyncResp->res.jsonValue["Location"];
113 messageRegistryLocationArray = nlohmann::json::array();
114 messageRegistryLocationArray.push_back(
115 {{"Language", "en"},
116 {"PublicationUri",
117 "https://redfish.dmtf.org/registries/Base.1.4.0.json"},
118 {"Uri", "/redfish/v1/Registries/Base/Base"}});
119 asyncResp->res.jsonValue["Location@odata.count"] =
120 messageRegistryLocationArray.size();
121 }
122};
123
124class BaseMessageRegistry : public Node
125{
126 public:
127 template <typename CrowApp>
128 BaseMessageRegistry(CrowApp &app) :
129 Node(app, "/redfish/v1/Registries/Base/Base/")
130 {
131 entityPrivileges = {
132 {boost::beast::http::verb::get, {{"Login"}}},
133 {boost::beast::http::verb::head, {{"Login"}}},
134 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
135 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
136 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
137 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
138 }
139
140 private:
141 void doGet(crow::Response &res, const crow::Request &req,
142 const std::vector<std::string> &params) override
143 {
144 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
145
146 asyncResp->res.jsonValue["@Redfish.Copyright"] =
147 "Copyright 2014-2018 DMTF. All rights reserved.";
148 asyncResp->res.jsonValue["@odata.type"] =
149 "#MessageRegistry.v1_0_0.MessageRegistry";
150 asyncResp->res.jsonValue["Id"] = "Base.1.4.0";
151 asyncResp->res.jsonValue["Name"] = "Base Message Registry";
152 asyncResp->res.jsonValue["Language"] = "en";
153 asyncResp->res.jsonValue["Description"] =
154 "This registry defines the base messages for Redfish";
155 asyncResp->res.jsonValue["RegistryPrefix"] = "Base";
156 asyncResp->res.jsonValue["RegistryVersion"] = "1.4.0";
157 asyncResp->res.jsonValue["OwningEntity"] = "DMTF";
158 nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
159 messageArray = nlohmann::json::array();
160
161 // Go through the Message Registry and populate each Message
162 for (const message_registries::MessageEntry &message :
163 message_registries::base::registry)
164 {
165 messageArray.push_back(
166 {{message.first,
167 {{"Description", message.second.description},
168 {"Message", message.second.message},
169 {"Severity", message.second.severity},
170 {"NumberOfArgs", message.second.numberOfArgs},
171 {"Resolution", message.second.resolution}}}});
172 if (message.second.numberOfArgs > 0)
173 {
174 nlohmann::json &messageParamArray =
175 messageArray.back()[message.first]["ParamTypes"];
176 for (const char *str : message.second.paramTypes)
177 {
178 if (str == nullptr)
179 {
180 break;
181 }
182 messageParamArray.push_back(str);
183 }
184 }
185 }
186 }
187};
188
189} // namespace redfish