Refactor DBus EventLog Entry download
In order to maximize common code extraction in the follow-up patch,
refactor the code for LogEntry download, so that the requestRoutes
functions holds the important control flow checks.
This way we can make the handler common code for both
Systems DBus EventLog as well as Managers DBus EventLog.
Tested: Only code extraction. Code compiles.
Change-Id: If8ebdd9a1d4b37ae00bb7f6b2ceaedf0d2c37e5d
Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
diff --git a/redfish-core/lib/systems_logservices_dbus_eventlog.hpp b/redfish-core/lib/systems_logservices_dbus_eventlog.hpp
index 64f87da..c97c337 100644
--- a/redfish-core/lib/systems_logservices_dbus_eventlog.hpp
+++ b/redfish-core/lib/systems_logservices_dbus_eventlog.hpp
@@ -324,9 +324,42 @@
inline void downloadEventLogEntry(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& systemName, const std::string& entryID,
- const std::string& dumpType)
+ const std::string& entryID, const std::string& downloadEntryType)
{
+ std::string entryPath =
+ sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
+ entryID;
+
+ auto downloadEventLogEntryHandler =
+ [asyncResp, entryID,
+ downloadEntryType](const boost::system::error_code& ec,
+ const sdbusplus::message::unix_fd& unixfd) {
+ log_services_utils::downloadEntryCallback(
+ asyncResp, entryID, downloadEntryType, ec, unixfd);
+ };
+
+ dbus::utility::async_method_call(
+ asyncResp, std::move(downloadEventLogEntryHandler),
+ "xyz.openbmc_project.Logging", entryPath,
+ "xyz.openbmc_project.Logging.Entry", "GetEntry");
+}
+
+inline void handleSystemsDBusEventLogEntryDownloadGet(
+ crow::App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName, const std::string& entryId)
+{
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+ {
+ return;
+ }
+ if (!http_helpers::isContentTypeAllowed(
+ req.getHeaderValue("Accept"),
+ http_helpers::ContentType::OctetStream, true))
+ {
+ asyncResp->res.result(boost::beast::http::status::bad_request);
+ return;
+ }
if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
{
// Option currently returns no systems. TBD
@@ -341,41 +374,7 @@
return;
}
- std::string entryPath =
- sdbusplus::message::object_path("/xyz/openbmc_project/logging/entry") /
- entryID;
-
- auto downloadEventLogEntryHandler =
- [asyncResp, entryID,
- dumpType](const boost::system::error_code& ec,
- const sdbusplus::message::unix_fd& unixfd) {
- log_services_utils::downloadEntryCallback(asyncResp, entryID,
- dumpType, ec, unixfd);
- };
-
- dbus::utility::async_method_call(
- asyncResp, std::move(downloadEventLogEntryHandler),
- "xyz.openbmc_project.Logging", entryPath,
- "xyz.openbmc_project.Logging.Entry", "GetEntry");
-}
-
-inline void handleDBusEventLogEntryDownloadGet(
- crow::App& app, const std::string& dumpType, const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& systemName, const std::string& entryID)
-{
- if (!redfish::setUpRedfishRoute(app, req, asyncResp))
- {
- return;
- }
- if (!http_helpers::isContentTypeAllowed(
- req.getHeaderValue("Accept"),
- http_helpers::ContentType::OctetStream, true))
- {
- asyncResp->res.result(boost::beast::http::status::bad_request);
- return;
- }
- downloadEventLogEntry(asyncResp, systemName, entryID, dumpType);
+ downloadEventLogEntry(asyncResp, entryId, "System");
}
inline void requestRoutesDBusEventLogEntryCollection(App& app)
@@ -543,6 +542,6 @@
"/redfish/v1/Systems/<str>/LogServices/EventLog/Entries/<str>/attachment/")
.privileges(redfish::privileges::getLogEntry)
.methods(boost::beast::http::verb::get)(std::bind_front(
- handleDBusEventLogEntryDownloadGet, std::ref(app), "System"));
+ handleSystemsDBusEventLogEntryDownloadGet, std::ref(app)));
}
} // namespace redfish