blob: 325fe6bd907c5421d326518cbf1645b1f38210e6 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2019 Intel Corporation
Jason M. Bills70304cb2019-03-27 12:03:59 -07004#pragma once
5
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08007#include "async_resp.hpp"
8#include "error_messages.hpp"
9#include "http_request.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080010#include "query.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070011#include "registries.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080012#include "registries/privilege_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070013
Ed Tanousd7857202025-01-28 15:32:26 -080014#include <boost/beast/http/verb.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070015#include <boost/url/format.hpp>
16
Ed Tanous56b81992024-12-02 10:36:37 -080017#include <format>
Ed Tanousd7857202025-01-28 15:32:26 -080018#include <functional>
19#include <memory>
20#include <optional>
Patrick Williams4a102cd2025-02-27 14:52:54 -050021#include <ranges>
Ed Tanousd7857202025-01-28 15:32:26 -080022#include <utility>
Ed Tanous613dabe2022-07-09 11:17:36 -070023
Jason M. Bills70304cb2019-03-27 12:03:59 -070024namespace redfish
25{
26
John Edward Broadbentdff07822021-07-13 11:20:47 -070027inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070028 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080029 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070030{
Carson Labrado3ba00072022-06-06 19:40:56 +000031 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070032 {
33 return;
34 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070035 // Collections don't include the static data added by SubRoute
36 // because it has a duplicate entry for members
37
Ed Tanous14766872022-03-15 10:44:42 -070038 asyncResp->res.jsonValue["@odata.type"] =
39 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
40 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
41 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
42 asyncResp->res.jsonValue["Description"] =
43 "Collection of MessageRegistryFiles";
Ed Tanous613dabe2022-07-09 11:17:36 -070044
45 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
Myung Baefb546102024-10-29 10:21:26 -050046
Patrick Williams4a102cd2025-02-27 14:52:54 -050047 for (const auto& memberName : std::views::keys(registries::allRegistries()))
Ed Tanous613dabe2022-07-09 11:17:36 -070048 {
49 nlohmann::json::object_t member;
Patrick Williamsbd79bce2024-08-16 15:22:20 -040050 member["@odata.id"] =
51 boost::urls::format("/redfish/v1/Registries/{}", memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070052 members.emplace_back(std::move(member));
53 }
Myung Baefb546102024-10-29 10:21:26 -050054 asyncResp->res.jsonValue["Members@odata.count"] = members.size();
John Edward Broadbentdff07822021-07-13 11:20:47 -070055}
56
John Edward Broadbent7e860f12021-04-08 15:57:16 -070057inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070058{
Jason M. Bills70304cb2019-03-27 12:03:59 -070059 /**
60 * Functions triggers appropriate requests on DBus
61 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070062 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070063 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070064 .methods(boost::beast::http::verb::get)(std::bind_front(
65 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070066}
Ed Tanous14c8aee2019-06-13 13:39:16 -070067
John Edward Broadbentdff07822021-07-13 11:20:47 -070068inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070069 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080070 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070071 const std::string& registry)
72{
Carson Labrado3ba00072022-06-06 19:40:56 +000073 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070074 {
75 return;
76 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070077 std::string dmtf = "DMTF ";
Patrick Williams4a102cd2025-02-27 14:52:54 -050078 std::optional<registries::RegistryEntryRef> registryEntry =
79 registries::getRegistryFromPrefix(registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070080
Patrick Williams4a102cd2025-02-27 14:52:54 -050081 if (!registryEntry)
John Edward Broadbentdff07822021-07-13 11:20:47 -070082 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +080083 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
84 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070085 return;
86 }
Myung Baef7a26072024-12-04 10:08:59 -060087 if (registry == "OpenBMC")
88 {
89 dmtf.clear();
90 }
Patrick Williams4a102cd2025-02-27 14:52:54 -050091 const registries::Header& header = registryEntry->get().header;
92 const char* url = registryEntry->get().url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070093
Ed Tanous14766872022-03-15 10:44:42 -070094 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -070095 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -070096 asyncResp->res.jsonValue["@odata.type"] =
97 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
98 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williamsbd79bce2024-08-16 15:22:20 -040099 asyncResp->res.jsonValue["Description"] =
100 dmtf + registry + " Message Registry File Location";
Myung Baef7a26072024-12-04 10:08:59 -0600101 asyncResp->res.jsonValue["Id"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -0800102 asyncResp->res.jsonValue["Registry"] =
103 std::format("{}.{}.{}", header.registryPrefix, header.versionMajor,
104 header.versionMinor);
Ed Tanous613dabe2022-07-09 11:17:36 -0700105 nlohmann::json::array_t languages;
Myung Baef7a26072024-12-04 10:08:59 -0600106 languages.emplace_back(header.language);
Ed Tanous613dabe2022-07-09 11:17:36 -0700107 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
108 asyncResp->res.jsonValue["Languages"] = std::move(languages);
109 nlohmann::json::array_t locationMembers;
110 nlohmann::json::object_t location;
Myung Baef7a26072024-12-04 10:08:59 -0600111 location["Language"] = header.language;
Ed Tanous613dabe2022-07-09 11:17:36 -0700112 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700113
114 if (url != nullptr)
115 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700116 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700117 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700118 locationMembers.emplace_back(std::move(location));
119 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
120 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700121}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700122
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700123inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700124{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700125 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700126 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700127 .methods(boost::beast::http::verb::get)(std::bind_front(
128 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700129}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700130
John Edward Broadbentdff07822021-07-13 11:20:47 -0700131inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700132 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800133 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700134 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700135
John Edward Broadbentdff07822021-07-13 11:20:47 -0700136{
Carson Labrado3ba00072022-06-06 19:40:56 +0000137 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700138 {
139 return;
140 }
Myung Baef7a26072024-12-04 10:08:59 -0600141
Patrick Williams4a102cd2025-02-27 14:52:54 -0500142 std::optional<registries::RegistryEntryRef> registryEntry =
143 registries::getRegistryFromPrefix(registry);
144 if (!registryEntry)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700145 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800146 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
147 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700148 return;
149 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700150
Patrick Williams4a102cd2025-02-27 14:52:54 -0500151 const registries::Header& header = registryEntry->get().header;
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700152 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700153 {
Myung Baef7a26072024-12-04 10:08:59 -0600154 messages::resourceNotFound(asyncResp->res, header.type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700155 return;
156 }
157
Myung Baef7a26072024-12-04 10:08:59 -0600158 asyncResp->res.jsonValue["@Redfish.Copyright"] = header.copyright;
159 asyncResp->res.jsonValue["@odata.type"] = header.type;
Ed Tanous56b81992024-12-02 10:36:37 -0800160 asyncResp->res.jsonValue["Id"] =
161 std::format("{}.{}.{}.{}", header.registryPrefix, header.versionMajor,
162 header.versionMinor, header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600163 asyncResp->res.jsonValue["Name"] = header.name;
164 asyncResp->res.jsonValue["Language"] = header.language;
165 asyncResp->res.jsonValue["Description"] = header.description;
166 asyncResp->res.jsonValue["RegistryPrefix"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -0800167 asyncResp->res.jsonValue["RegistryVersion"] =
168 std::format("{}.{}.{}", header.versionMajor, header.versionMinor,
169 header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600170 asyncResp->res.jsonValue["OwningEntity"] = header.owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700171
172 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
173
174 // Go through the Message Registry and populate each Message
Patrick Williams4a102cd2025-02-27 14:52:54 -0500175 const registries::MessageEntries registryEntries =
176 registries::getRegistryMessagesFromPrefix(registry);
Myung Baef7a26072024-12-04 10:08:59 -0600177
178 for (const registries::MessageEntry& message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700179 {
Myung Baef7a26072024-12-04 10:08:59 -0600180 nlohmann::json& obj = messageObj[message.first];
181 obj["Description"] = message.second.description;
182 obj["Message"] = message.second.message;
183 obj["Severity"] = message.second.messageSeverity;
184 obj["MessageSeverity"] = message.second.messageSeverity;
185 obj["NumberOfArgs"] = message.second.numberOfArgs;
186 obj["Resolution"] = message.second.resolution;
187 if (message.second.numberOfArgs > 0)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700188 {
189 nlohmann::json& messageParamArray = obj["ParamTypes"];
190 messageParamArray = nlohmann::json::array();
Myung Baef7a26072024-12-04 10:08:59 -0600191 for (const char* str : message.second.paramTypes)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700192 {
193 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700194 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700195 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700196 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700197 messageParamArray.push_back(str);
198 }
199 }
200 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700201}
202
203inline void requestRoutesMessageRegistry(App& app)
204{
205 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700206 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700207 .methods(boost::beast::http::verb::get)(
208 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700209}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700210} // namespace redfish