blob: 6bbdb48f5e5143af9fa490ee329c6612f2706e30 [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"
Myung Baef7a26072024-12-04 10:08:59 -060013#include "registries_selector.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070014
Ed Tanousd7857202025-01-28 15:32:26 -080015#include <boost/beast/http/verb.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070016#include <boost/url/format.hpp>
17
Ed Tanous613dabe2022-07-09 11:17:36 -070018#include <array>
Ed Tanous56b81992024-12-02 10:36:37 -080019#include <format>
Ed Tanousd7857202025-01-28 15:32:26 -080020#include <functional>
21#include <memory>
22#include <optional>
23#include <span>
24#include <utility>
Ed Tanous613dabe2022-07-09 11:17:36 -070025
Jason M. Bills70304cb2019-03-27 12:03:59 -070026namespace redfish
27{
28
John Edward Broadbentdff07822021-07-13 11:20:47 -070029inline void handleMessageRegistryFileCollectionGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070030 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080031 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
John Edward Broadbentdff07822021-07-13 11:20:47 -070032{
Carson Labrado3ba00072022-06-06 19:40:56 +000033 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070034 {
35 return;
36 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070037 // Collections don't include the static data added by SubRoute
38 // because it has a duplicate entry for members
39
Ed Tanous14766872022-03-15 10:44:42 -070040 asyncResp->res.jsonValue["@odata.type"] =
41 "#MessageRegistryFileCollection.MessageRegistryFileCollection";
42 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Registries";
43 asyncResp->res.jsonValue["Name"] = "MessageRegistryFile Collection";
44 asyncResp->res.jsonValue["Description"] =
45 "Collection of MessageRegistryFiles";
Ed Tanous613dabe2022-07-09 11:17:36 -070046
47 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
Myung Baefb546102024-10-29 10:21:26 -050048
49 static constexpr const auto registryFiles = std::to_array(
50 {"Base", "TaskEvent", "ResourceEvent", "OpenBMC", "Telemetry",
51 "HeartbeatEvent"});
52
53 for (const char* memberName : registryFiles)
Ed Tanous613dabe2022-07-09 11:17:36 -070054 {
55 nlohmann::json::object_t member;
Patrick Williamsbd79bce2024-08-16 15:22:20 -040056 member["@odata.id"] =
57 boost::urls::format("/redfish/v1/Registries/{}", memberName);
Ed Tanous613dabe2022-07-09 11:17:36 -070058 members.emplace_back(std::move(member));
59 }
Myung Baefb546102024-10-29 10:21:26 -050060 asyncResp->res.jsonValue["Members@odata.count"] = members.size();
John Edward Broadbentdff07822021-07-13 11:20:47 -070061}
62
John Edward Broadbent7e860f12021-04-08 15:57:16 -070063inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070064{
Jason M. Bills70304cb2019-03-27 12:03:59 -070065 /**
66 * Functions triggers appropriate requests on DBus
67 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070068 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
Ed Tanoused398212021-06-09 17:05:54 -070069 .privileges(redfish::privileges::getMessageRegistryFileCollection)
Ed Tanous45ca1b82022-03-25 13:07:27 -070070 .methods(boost::beast::http::verb::get)(std::bind_front(
71 handleMessageRegistryFileCollectionGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -070072}
Ed Tanous14c8aee2019-06-13 13:39:16 -070073
John Edward Broadbentdff07822021-07-13 11:20:47 -070074inline void handleMessageRoutesMessageRegistryFileGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -070075 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -080076 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbentdff07822021-07-13 11:20:47 -070077 const std::string& registry)
78{
Carson Labrado3ba00072022-06-06 19:40:56 +000079 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070080 {
81 return;
82 }
John Edward Broadbentdff07822021-07-13 11:20:47 -070083 std::string dmtf = "DMTF ";
Myung Baef7a26072024-12-04 10:08:59 -060084 std::optional<registries::HeaderAndUrl> headerAndUrl =
85 registries::getRegistryHeaderAndUrlFromPrefix(registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070086
Myung Baef7a26072024-12-04 10:08:59 -060087 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -070088 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +080089 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
90 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -070091 return;
92 }
Myung Baef7a26072024-12-04 10:08:59 -060093 if (registry == "OpenBMC")
94 {
95 dmtf.clear();
96 }
97 const registries::Header& header = headerAndUrl->header;
98 const char* url = headerAndUrl->url;
John Edward Broadbentdff07822021-07-13 11:20:47 -070099
Ed Tanous14766872022-03-15 10:44:42 -0700100 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700101 boost::urls::format("/redfish/v1/Registries/{}", registry);
Ed Tanous14766872022-03-15 10:44:42 -0700102 asyncResp->res.jsonValue["@odata.type"] =
103 "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
104 asyncResp->res.jsonValue["Name"] = registry + " Message Registry File";
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400105 asyncResp->res.jsonValue["Description"] =
106 dmtf + registry + " Message Registry File Location";
Myung Baef7a26072024-12-04 10:08:59 -0600107 asyncResp->res.jsonValue["Id"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -0800108 asyncResp->res.jsonValue["Registry"] =
109 std::format("{}.{}.{}", header.registryPrefix, header.versionMajor,
110 header.versionMinor);
Ed Tanous613dabe2022-07-09 11:17:36 -0700111 nlohmann::json::array_t languages;
Myung Baef7a26072024-12-04 10:08:59 -0600112 languages.emplace_back(header.language);
Ed Tanous613dabe2022-07-09 11:17:36 -0700113 asyncResp->res.jsonValue["Languages@odata.count"] = languages.size();
114 asyncResp->res.jsonValue["Languages"] = std::move(languages);
115 nlohmann::json::array_t locationMembers;
116 nlohmann::json::object_t location;
Myung Baef7a26072024-12-04 10:08:59 -0600117 location["Language"] = header.language;
Ed Tanous613dabe2022-07-09 11:17:36 -0700118 location["Uri"] = "/redfish/v1/Registries/" + registry + "/" + registry;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700119
120 if (url != nullptr)
121 {
Ed Tanous613dabe2022-07-09 11:17:36 -0700122 location["PublicationUri"] = url;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700123 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700124 locationMembers.emplace_back(std::move(location));
125 asyncResp->res.jsonValue["Location@odata.count"] = locationMembers.size();
126 asyncResp->res.jsonValue["Location"] = std::move(locationMembers);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700127}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700128
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700129inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -0700130{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700131 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700132 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700133 .methods(boost::beast::http::verb::get)(std::bind_front(
134 handleMessageRoutesMessageRegistryFileGet, std::ref(app)));
John Edward Broadbentdff07822021-07-13 11:20:47 -0700135}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700136
John Edward Broadbentdff07822021-07-13 11:20:47 -0700137inline void handleMessageRegistryGet(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700138 crow::App& app, const crow::Request& req,
Ed Tanous104f09c2022-01-25 09:56:04 -0800139 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700140 const std::string& registry, const std::string& registryMatch)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700141
John Edward Broadbentdff07822021-07-13 11:20:47 -0700142{
Carson Labrado3ba00072022-06-06 19:40:56 +0000143 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -0700144 {
145 return;
146 }
Myung Baef7a26072024-12-04 10:08:59 -0600147
148 std::optional<registries::HeaderAndUrl> headerAndUrl =
149 registries::getRegistryHeaderAndUrlFromPrefix(registry);
150 if (!headerAndUrl)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700151 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800152 messages::resourceNotFound(asyncResp->res, "MessageRegistryFile",
153 registry);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700154 return;
155 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700156
Myung Baef7a26072024-12-04 10:08:59 -0600157 const registries::Header& header = headerAndUrl->header;
John Edward Broadbent6e8c18f2021-09-27 13:11:38 -0700158 if (registry != registryMatch)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700159 {
Myung Baef7a26072024-12-04 10:08:59 -0600160 messages::resourceNotFound(asyncResp->res, header.type, registryMatch);
John Edward Broadbentdff07822021-07-13 11:20:47 -0700161 return;
162 }
163
Myung Baef7a26072024-12-04 10:08:59 -0600164 asyncResp->res.jsonValue["@Redfish.Copyright"] = header.copyright;
165 asyncResp->res.jsonValue["@odata.type"] = header.type;
Ed Tanous56b81992024-12-02 10:36:37 -0800166 asyncResp->res.jsonValue["Id"] =
167 std::format("{}.{}.{}.{}", header.registryPrefix, header.versionMajor,
168 header.versionMinor, header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600169 asyncResp->res.jsonValue["Name"] = header.name;
170 asyncResp->res.jsonValue["Language"] = header.language;
171 asyncResp->res.jsonValue["Description"] = header.description;
172 asyncResp->res.jsonValue["RegistryPrefix"] = header.registryPrefix;
Ed Tanous56b81992024-12-02 10:36:37 -0800173 asyncResp->res.jsonValue["RegistryVersion"] =
174 std::format("{}.{}.{}", header.versionMajor, header.versionMinor,
175 header.versionPatch);
Myung Baef7a26072024-12-04 10:08:59 -0600176 asyncResp->res.jsonValue["OwningEntity"] = header.owningEntity;
John Edward Broadbentdff07822021-07-13 11:20:47 -0700177
178 nlohmann::json& messageObj = asyncResp->res.jsonValue["Messages"];
179
180 // Go through the Message Registry and populate each Message
Myung Baef7a26072024-12-04 10:08:59 -0600181 const std::span<const registries::MessageEntry> registryEntries =
182 registries::getRegistryFromPrefix(registry);
183
184 for (const registries::MessageEntry& message : registryEntries)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700185 {
Myung Baef7a26072024-12-04 10:08:59 -0600186 nlohmann::json& obj = messageObj[message.first];
187 obj["Description"] = message.second.description;
188 obj["Message"] = message.second.message;
189 obj["Severity"] = message.second.messageSeverity;
190 obj["MessageSeverity"] = message.second.messageSeverity;
191 obj["NumberOfArgs"] = message.second.numberOfArgs;
192 obj["Resolution"] = message.second.resolution;
193 if (message.second.numberOfArgs > 0)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700194 {
195 nlohmann::json& messageParamArray = obj["ParamTypes"];
196 messageParamArray = nlohmann::json::array();
Myung Baef7a26072024-12-04 10:08:59 -0600197 for (const char* str : message.second.paramTypes)
John Edward Broadbentdff07822021-07-13 11:20:47 -0700198 {
199 if (str == nullptr)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700200 {
John Edward Broadbentdff07822021-07-13 11:20:47 -0700201 break;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700202 }
John Edward Broadbentdff07822021-07-13 11:20:47 -0700203 messageParamArray.push_back(str);
204 }
205 }
206 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700207}
208
209inline void requestRoutesMessageRegistry(App& app)
210{
211 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700212 .privileges(redfish::privileges::getMessageRegistryFile)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700213 .methods(boost::beast::http::verb::get)(
214 std::bind_front(handleMessageRegistryGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700215}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700216} // namespace redfish