used sdbusplus::unpackPropertiesNoThrow part 8
used sdbusplus::unpackPropertiesNoThrow in other places, also replaced
all usages of "GetAll" with sdbusplus::asio::getAllProperties
bmcweb size: 2697640 -> 2685336 (-12304)
compressed size: 1129728 -> 1126078 (-3650)
Tested:
- Executed redfish service validator, no new errors detected
Change-Id: I916e462e004fcbde67c209daef295de8f5fb68eb
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index b6316ef..5d8bb15 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -23,6 +23,8 @@
#include <query.hpp>
#include <registries/privilege_registry.hpp>
#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
#include <utils/json_utils.hpp>
namespace redfish
@@ -1291,7 +1293,9 @@
asyncResp->res.jsonValue["LDAP"]["Certificates"]["@odata.id"] =
"/redfish/v1/AccountService/LDAP/Certificates";
}
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
+ "/xyz/openbmc_project/user", "xyz.openbmc_project.User.AccountPolicy",
[asyncResp](const boost::system::error_code ec,
const dbus::utility::DBusPropertiesMap& propertiesList) {
if (ec)
@@ -1299,41 +1303,43 @@
messages::internalError(asyncResp->res);
return;
}
+
BMCWEB_LOG_DEBUG << "Got " << propertiesList.size()
<< "properties for AccountService";
- for (const std::pair<std::string, dbus::utility::DbusVariantType>&
- property : propertiesList)
+
+ const uint8_t* minPasswordLength = nullptr;
+ const uint32_t* accountUnlockTimeout = nullptr;
+ const uint16_t* maxLoginAttemptBeforeLockout = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), propertiesList,
+ "MinPasswordLength", minPasswordLength, "AccountUnlockTimeout",
+ accountUnlockTimeout, "MaxLoginAttemptBeforeLockout",
+ maxLoginAttemptBeforeLockout);
+
+ if (!success)
{
- if (property.first == "MinPasswordLength")
- {
- const uint8_t* value = std::get_if<uint8_t>(&property.second);
- if (value != nullptr)
- {
- asyncResp->res.jsonValue["MinPasswordLength"] = *value;
- }
- }
- if (property.first == "AccountUnlockTimeout")
- {
- const uint32_t* value = std::get_if<uint32_t>(&property.second);
- if (value != nullptr)
- {
- asyncResp->res.jsonValue["AccountLockoutDuration"] = *value;
- }
- }
- if (property.first == "MaxLoginAttemptBeforeLockout")
- {
- const uint16_t* value = std::get_if<uint16_t>(&property.second);
- if (value != nullptr)
- {
- asyncResp->res.jsonValue["AccountLockoutThreshold"] =
- *value;
- }
- }
+ messages::internalError(asyncResp->res);
+ return;
}
- },
- "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
- "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.User.AccountPolicy");
+
+ if (minPasswordLength != nullptr)
+ {
+ asyncResp->res.jsonValue["MinPasswordLength"] = *minPasswordLength;
+ }
+
+ if (accountUnlockTimeout != nullptr)
+ {
+ asyncResp->res.jsonValue["AccountLockoutDuration"] =
+ *accountUnlockTimeout;
+ }
+
+ if (maxLoginAttemptBeforeLockout != nullptr)
+ {
+ asyncResp->res.jsonValue["AccountLockoutThreshold"] =
+ *maxLoginAttemptBeforeLockout;
+ }
+ });
auto callback = [asyncResp](bool success, const LDAPConfigData& confData,
const std::string& ldapType) {