diff options
author | Krzysztof Grobelny <krzysztof.grobelny@intel.com> | 2022-09-07 11:40:51 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-09-09 06:20:53 +0300 |
commit | d1bde9e590f165f28d948fda93e48d51b30bb463 (patch) | |
tree | aabfdc5dc75090eeb1066d99a30402efa5bf7505 /redfish-core/lib/account_service.hpp | |
parent | c6fecdabd58b4c380caf1b83801ad4eb54922fff (diff) | |
download | bmcweb-d1bde9e590f165f28d948fda93e48d51b30bb463.tar.xz |
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>
Diffstat (limited to 'redfish-core/lib/account_service.hpp')
-rw-r--r-- | redfish-core/lib/account_service.hpp | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index b6316ef915..5d8bb15f6c 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 @@ inline void 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 @@ inline void 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) { |