update service: use getCollectionMembers
There are some cases that getCollectionMembers can be leveraged
Tested:
GET https://127.0.0.1:443/redfish/v1/UpdateService/FirmwareInventory/
Returns the same result.
Redfish service validator passes.
Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: I417bc08cffd24c6c95abaf86013002ce705d20a4
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index ddb46f6..3d58d0d 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -23,6 +23,7 @@
#include "query.hpp"
#include "registries/privilege_registry.hpp"
#include "task.hpp"
+#include "utils/collection.hpp"
#include "utils/dbus_utils.hpp"
#include "utils/sw_utils.hpp"
@@ -842,47 +843,13 @@
asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/UpdateService/FirmwareInventory";
asyncResp->res.jsonValue["Name"] = "Software Inventory Collection";
-
- // Note that only firmware levels associated with a device
- // are stored under /xyz/openbmc_project/software therefore
- // to ensure only real FirmwareInventory items are returned,
- // this full object path must be used here as input to
- // mapper
- constexpr std::array<std::string_view, 1> interfaces = {
+ const std::array<const std::string_view, 1> iface = {
"xyz.openbmc_project.Software.Version"};
- dbus::utility::getSubTree(
- "/xyz/openbmc_project/software", 0, interfaces,
- [asyncResp](
- const boost::system::error_code& ec,
- const dbus::utility::MapperGetSubTreeResponse& subtree) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
- asyncResp->res.jsonValue["Members@odata.count"] = 0;
- for (const auto& obj : subtree)
- {
- sdbusplus::message::object_path path(obj.first);
- std::string swId = path.filename();
- if (swId.empty())
- {
- messages::internalError(asyncResp->res);
- BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!";
- return;
- }
-
- nlohmann::json& members = asyncResp->res.jsonValue["Members"];
- nlohmann::json::object_t member;
- member["@odata.id"] = boost::urls::format(
- "/redfish/v1/UpdateService/FirmwareInventory/{}", swId);
- members.emplace_back(std::move(member));
- asyncResp->res.jsonValue["Members@odata.count"] =
- members.size();
- }
- });
+ redfish::collection_util::getCollectionMembers(
+ asyncResp,
+ boost::urls::url("/redfish/v1/UpdateService/FirmwareInventory"),
+ iface, "/xyz/openbmc_project/software");
});
}
/* Fill related item links (i.e. bmc, bios) in for inventory */