Refactor setProperty method

SetProperty is a method we should use more, and use consistently in the
codebase, this commit makes it consistently used from the utility
namespace.

Tested: Refactor.  Code compiles.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I5939317d23483e16bd98a8298f53e75604ef374d
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 8a893e3..9f3c96e 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -53,7 +53,6 @@
 constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable";
 constexpr const char* ldapPrivMapperInterface =
     "xyz.openbmc_project.User.PrivilegeMapper";
-constexpr const char* propertyInterface = "org.freedesktop.DBus.Properties";
 
 struct LDAPRoleMapData
 {
@@ -259,20 +258,18 @@
         return;
     }
 
-    crow::connections::systemBus->async_method_call(
-        [asyncResp](const boost::system::error_code ec) {
-        if (ec)
-        {
-            BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
-            messages::internalError(asyncResp->res);
-            return;
-        }
-        messages::success(asyncResp->res);
-        },
-        "xyz.openbmc_project.User.Manager", dbusObjectPath,
-        "org.freedesktop.DBus.Properties", "Set",
-        "xyz.openbmc_project.User.Attributes", "UserGroups",
-        dbus::utility::DbusVariantType{updatedUserGroups});
+    sdbusplus::asio::setProperty(
+        *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
+        dbusObjectPath, "xyz.openbmc_project.User.Attributes", "UserGroups",
+        updatedUserGroups, [asyncResp](const boost::system::error_code& ec) {
+            if (ec)
+            {
+                BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+                messages::internalError(asyncResp->res);
+                return;
+            }
+            messages::success(asyncResp->res);
+        });
 }
 
 inline void userErrorMessageHandler(
@@ -426,7 +423,11 @@
                 // If "RemoteGroup" info is provided
                 if (remoteGroup)
                 {
-                    crow::connections::systemBus->async_method_call(
+                    sdbusplus::asio::setProperty(
+                        *crow::connections::systemBus, ldapDbusService,
+                        roleMapObjData[index].first,
+                        "xyz.openbmc_project.User.PrivilegeMapperEntry",
+                        "GroupName", *remoteGroup,
                         [asyncResp, roleMapObjData, serverType, index,
                          remoteGroup](const boost::system::error_code& ec,
                                       const sdbusplus::message_t& msg) {
@@ -451,19 +452,17 @@
                         asyncResp->res
                             .jsonValue[serverType]["RemoteRoleMapping"][index]
                                       ["RemoteGroup"] = *remoteGroup;
-                        },
-                        ldapDbusService, roleMapObjData[index].first,
-                        propertyInterface, "Set",
-                        "xyz.openbmc_project.User.PrivilegeMapperEntry",
-                        "GroupName",
-                        dbus::utility::DbusVariantType(
-                            std::move(*remoteGroup)));
+                        });
                 }
 
                 // If "LocalRole" info is provided
                 if (localRole)
                 {
-                    crow::connections::systemBus->async_method_call(
+                    sdbusplus::asio::setProperty(
+                        *crow::connections::systemBus, ldapDbusService,
+                        roleMapObjData[index].first,
+                        "xyz.openbmc_project.User.PrivilegeMapperEntry",
+                        "Privilege", *localRole,
                         [asyncResp, roleMapObjData, serverType, index,
                          localRole](const boost::system::error_code& ec,
                                     const sdbusplus::message_t& msg) {
@@ -487,13 +486,7 @@
                         asyncResp->res
                             .jsonValue[serverType]["RemoteRoleMapping"][index]
                                       ["LocalRole"] = *localRole;
-                        },
-                        ldapDbusService, roleMapObjData[index].first,
-                        propertyInterface, "Set",
-                        "xyz.openbmc_project.User.PrivilegeMapperEntry",
-                        "Privilege",
-                        dbus::utility::DbusVariantType(
-                            getPrivilegeFromRoleId(std::move(*localRole))));
+                        });
                 }
             }
             // Create a new RoleMapping Object.
@@ -802,7 +795,9 @@
     const std::string& ldapServerElementName,
     const std::string& ldapConfigObject)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::asio::setProperty(
+        *crow::connections::systemBus, ldapDbusService, ldapConfigObject,
+        ldapConfigInterface, "LDAPServerURI", serviceAddressList.front(),
         [asyncResp, ldapServerElementName, serviceAddressList](
             const boost::system::error_code& ec, sdbusplus::message_t& msg) {
         if (ec)
@@ -833,10 +828,7 @@
                                             serviceAddressList.front());
         }
         BMCWEB_LOG_DEBUG << "Updated the service address";
-        },
-        ldapDbusService, ldapConfigObject, propertyInterface, "Set",
-        ldapConfigInterface, "LDAPServerURI",
-        dbus::utility::DbusVariantType(serviceAddressList.front()));
+        });
 }
 /**
  * @brief updates the LDAP Bind DN and updates the
@@ -853,9 +845,11 @@
                         const std::string& ldapServerElementName,
                         const std::string& ldapConfigObject)
 {
-    crow::connections::systemBus->async_method_call(
-        [asyncResp, username,
-         ldapServerElementName](const boost::system::error_code& ec) {
+    sdbusplus::asio::setProperty(*crow::connections::systemBus, ldapDbusService,
+                                 ldapConfigObject, ldapConfigInterface,
+                                 "LDAPBindDN", username,
+                                 [asyncResp, username, ldapServerElementName](
+                                     const boost::system::error_code& ec) {
         if (ec)
         {
             BMCWEB_LOG_DEBUG << "Error occurred in updating the username";
@@ -865,10 +859,7 @@
         asyncResp->res.jsonValue[ldapServerElementName]["Authentication"]
                                 ["Username"] = username;
         BMCWEB_LOG_DEBUG << "Updated the username";
-        },
-        ldapDbusService, ldapConfigObject, propertyInterface, "Set",
-        ldapConfigInterface, "LDAPBindDN",
-        dbus::utility::DbusVariantType(username));
+    });
 }
 
 /**
@@ -885,9 +876,11 @@
                         const std::string& ldapServerElementName,
                         const std::string& ldapConfigObject)
 {
-    crow::connections::systemBus->async_method_call(
-        [asyncResp, password,
-         ldapServerElementName](const boost::system::error_code& ec) {
+    sdbusplus::asio::setProperty(*crow::connections::systemBus, ldapDbusService,
+                                 ldapConfigObject, ldapConfigInterface,
+                                 "LDAPBindDNPassword", password,
+                                 [asyncResp, password, ldapServerElementName](
+                                     const boost::system::error_code& ec) {
         if (ec)
         {
             BMCWEB_LOG_DEBUG << "Error occurred in updating the password";
@@ -897,10 +890,7 @@
         asyncResp->res.jsonValue[ldapServerElementName]["Authentication"]
                                 ["Password"] = "";
         BMCWEB_LOG_DEBUG << "Updated the password";
-        },
-        ldapDbusService, ldapConfigObject, propertyInterface, "Set",
-        ldapConfigInterface, "LDAPBindDNPassword",
-        dbus::utility::DbusVariantType(password));
+    });
 }
 
 /**
@@ -918,10 +908,12 @@
                       const std::string& ldapServerElementName,
                       const std::string& ldapConfigObject)
 {
-    crow::connections::systemBus->async_method_call(
-        [asyncResp, baseDNList,
-         ldapServerElementName](const boost::system::error_code& ec,
-                                const sdbusplus::message_t& msg) {
+    sdbusplus::asio::setProperty(*crow::connections::systemBus, ldapDbusService,
+                                 ldapConfigObject, ldapConfigInterface,
+                                 "LDAPBaseDN", baseDNList.front(),
+                                 [asyncResp, baseDNList, ldapServerElementName](
+                                     const boost::system::error_code& ec,
+                                     const sdbusplus::message_t& msg) {
         if (ec)
         {
             BMCWEB_LOG_DEBUG << "Error Occurred in Updating the base DN";
@@ -950,10 +942,7 @@
                 asyncResp->res, "BaseDistinguishedNames", baseDNList.front());
         }
         BMCWEB_LOG_DEBUG << "Updated the base DN";
-        },
-        ldapDbusService, ldapConfigObject, propertyInterface, "Set",
-        ldapConfigInterface, "LDAPBaseDN",
-        dbus::utility::DbusVariantType(baseDNList.front()));
+    });
 }
 /**
  * @brief updates the LDAP user name attribute and updates the
@@ -970,7 +959,9 @@
                             const std::string& ldapServerElementName,
                             const std::string& ldapConfigObject)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::asio::setProperty(
+        *crow::connections::systemBus, ldapDbusService, ldapConfigObject,
+        ldapConfigInterface, "UserNameAttribute", userNameAttribute,
         [asyncResp, userNameAttribute,
          ldapServerElementName](const boost::system::error_code& ec) {
         if (ec)
@@ -985,10 +976,7 @@
             serverTypeJson["LDAPService"]["SearchSettings"];
         searchSettingsJson["UsernameAttribute"] = userNameAttribute;
         BMCWEB_LOG_DEBUG << "Updated the user name attr.";
-        },
-        ldapDbusService, ldapConfigObject, propertyInterface, "Set",
-        ldapConfigInterface, "UserNameAttribute",
-        dbus::utility::DbusVariantType(userNameAttribute));
+        });
 }
 /**
  * @brief updates the LDAP group attribute and updates the
@@ -1005,7 +993,9 @@
     const std::string& ldapServerElementName,
     const std::string& ldapConfigObject)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::asio::setProperty(
+        *crow::connections::systemBus, ldapDbusService, ldapConfigObject,
+        ldapConfigInterface, "GroupNameAttribute", groupsAttribute,
         [asyncResp, groupsAttribute,
          ldapServerElementName](const boost::system::error_code& ec) {
         if (ec)
@@ -1020,10 +1010,7 @@
             serverTypeJson["LDAPService"]["SearchSettings"];
         searchSettingsJson["GroupsAttribute"] = groupsAttribute;
         BMCWEB_LOG_DEBUG << "Updated the groupname attr";
-        },
-        ldapDbusService, ldapConfigObject, propertyInterface, "Set",
-        ldapConfigInterface, "GroupNameAttribute",
-        dbus::utility::DbusVariantType(groupsAttribute));
+        });
 }
 /**
  * @brief updates the LDAP service enable and updates the
@@ -1039,7 +1026,9 @@
     const std::string& ldapServerElementName,
     const std::string& ldapConfigObject)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::asio::setProperty(
+        *crow::connections::systemBus, ldapDbusService, ldapConfigObject,
+        ldapEnableInterface, "Enabled", serviceEnabled,
         [asyncResp, serviceEnabled,
          ldapServerElementName](const boost::system::error_code& ec) {
         if (ec)
@@ -1051,10 +1040,7 @@
         asyncResp->res.jsonValue[ldapServerElementName]["ServiceEnabled"] =
             serviceEnabled;
         BMCWEB_LOG_DEBUG << "Updated Service enable = " << serviceEnabled;
-        },
-        ldapDbusService, ldapConfigObject, propertyInterface, "Set",
-        ldapEnableInterface, "Enabled",
-        dbus::utility::DbusVariantType(serviceEnabled));
+        });
 }
 
 inline void
@@ -1363,21 +1349,19 @@
 
             if (enabled)
             {
-                crow::connections::systemBus->async_method_call(
-                    [asyncResp](const boost::system::error_code& ec) {
-                if (ec)
-                {
-                    BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
-                    messages::internalError(asyncResp->res);
-                    return;
-                }
-                messages::success(asyncResp->res);
-                return;
-                    },
+                sdbusplus::asio::setProperty(
+                    *crow::connections::systemBus,
                     "xyz.openbmc_project.User.Manager", dbusObjectPath,
-                    "org.freedesktop.DBus.Properties", "Set",
                     "xyz.openbmc_project.User.Attributes", "UserEnabled",
-                    dbus::utility::DbusVariantType{*enabled});
+                    *enabled, [asyncResp](const boost::system::error_code& ec) {
+                        if (ec)
+                        {
+                            BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+                            messages::internalError(asyncResp->res);
+                            return;
+                        }
+                        messages::success(asyncResp->res);
+                    });
             }
 
             if (roleId)
@@ -1390,20 +1374,19 @@
                     return;
                 }
 
-                crow::connections::systemBus->async_method_call(
-                    [asyncResp](const boost::system::error_code& ec) {
-                if (ec)
-                {
-                    BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
-                    messages::internalError(asyncResp->res);
-                    return;
-                }
-                messages::success(asyncResp->res);
-                    },
+                sdbusplus::asio::setProperty(
+                    *crow::connections::systemBus,
                     "xyz.openbmc_project.User.Manager", dbusObjectPath,
-                    "org.freedesktop.DBus.Properties", "Set",
                     "xyz.openbmc_project.User.Attributes", "UserPrivilege",
-                    dbus::utility::DbusVariantType{priv});
+                    priv, [asyncResp](const boost::system::error_code& ec) {
+                        if (ec)
+                        {
+                            BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+                            messages::internalError(asyncResp->res);
+                            return;
+                        }
+                        messages::success(asyncResp->res);
+                    });
             }
 
             if (locked)
@@ -1418,7 +1401,11 @@
                     return;
                 }
 
-                crow::connections::systemBus->async_method_call(
+                sdbusplus::asio::setProperty(
+                    *crow::connections::systemBus,
+                    "xyz.openbmc_project.User.Manager", dbusObjectPath,
+                    "xyz.openbmc_project.User.Attributes",
+                    "UserLockedForFailedAttempt", *locked,
                     [asyncResp](const boost::system::error_code& ec) {
                 if (ec)
                 {
@@ -1427,13 +1414,7 @@
                     return;
                 }
                 messages::success(asyncResp->res);
-                return;
-                    },
-                    "xyz.openbmc_project.User.Manager", dbusObjectPath,
-                    "org.freedesktop.DBus.Properties", "Set",
-                    "xyz.openbmc_project.User.Attributes",
-                    "UserLockedForFailedAttempt",
-                    dbus::utility::DbusVariantType{*locked});
+                    });
             }
 
             if (accountTypes)
@@ -1603,7 +1584,11 @@
 
     if (minPasswordLength)
     {
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::asio::setProperty(
+            *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
+            "/xyz/openbmc_project/user",
+            "xyz.openbmc_project.User.AccountPolicy", "MinPasswordLength",
+            *minPasswordLength,
             [asyncResp](const boost::system::error_code& ec) {
             if (ec)
             {
@@ -1611,11 +1596,7 @@
                 return;
             }
             messages::success(asyncResp->res);
-            },
-            "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
-            "org.freedesktop.DBus.Properties", "Set",
-            "xyz.openbmc_project.User.AccountPolicy", "MinPasswordLength",
-            dbus::utility::DbusVariantType(*minPasswordLength));
+            });
     }
 
     if (maxPasswordLength)
@@ -1651,23 +1632,26 @@
 
     if (unlockTimeout)
     {
-        crow::connections::systemBus->async_method_call(
-            [asyncResp](const boost::system::error_code& ec) {
-            if (ec)
-            {
-                messages::internalError(asyncResp->res);
-                return;
-            }
-            messages::success(asyncResp->res);
-            },
-            "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
-            "org.freedesktop.DBus.Properties", "Set",
+        sdbusplus::asio::setProperty(
+            *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
+            "/xyz/openbmc_project/user",
             "xyz.openbmc_project.User.AccountPolicy", "AccountUnlockTimeout",
-            dbus::utility::DbusVariantType(*unlockTimeout));
+            *unlockTimeout, [asyncResp](const boost::system::error_code& ec) {
+                if (ec)
+                {
+                    messages::internalError(asyncResp->res);
+                    return;
+                }
+                messages::success(asyncResp->res);
+            });
     }
     if (lockoutThreshold)
     {
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::asio::setProperty(
+            *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
+            "/xyz/openbmc_project/user",
+            "xyz.openbmc_project.User.AccountPolicy",
+            "MaxLoginAttemptBeforeLockout", *lockoutThreshold,
             [asyncResp](const boost::system::error_code& ec) {
             if (ec)
             {
@@ -1675,12 +1659,7 @@
                 return;
             }
             messages::success(asyncResp->res);
-            },
-            "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
-            "org.freedesktop.DBus.Properties", "Set",
-            "xyz.openbmc_project.User.AccountPolicy",
-            "MaxLoginAttemptBeforeLockout",
-            dbus::utility::DbusVariantType(*lockoutThreshold));
+            });
     }
 }