diff options
author | Ninad Palsule <ninadpalsule@us.ibm.com> | 2023-05-17 22:04:52 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-05-18 19:02:45 +0300 |
commit | 97e90da3b83470f7e7be2061df9940379a2c01af (patch) | |
tree | 265362d5b0dca1224ddfc4a07ff52558b90b67a0 /redfish-core/lib/account_service.hpp | |
parent | 00ef5dc6d410ab83302529f23919b3d91a35b5e3 (diff) | |
download | bmcweb-97e90da3b83470f7e7be2061df9940379a2c01af.tar.xz |
Move long lambda in separate function
The GetAllGroups lambda is very long and need to add somemore stuff for
hostconsole work hence moving it in the separate function.
Tested: Created user.
+ curl -k -X POST https://${bmc}/redfish/v1/AccountService/Accounts \
-d '{"UserName": "user99", "Password": "0penBmc0", "RoleId": "Operator"}'
{
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The resource has been created successfully.",
"MessageArgs": [],
"MessageId": "Base.1.13.0.Created",
"MessageSeverity": "OK",
"Resolution": "None."
}
]
}
Change-Id: If62fa803217e43bdecca7965d16c98d852f0b5be
Signed-off-by: Ninad Palsule <ninadpalsule@us.ibm.com>
Diffstat (limited to 'redfish-core/lib/account_service.hpp')
-rw-r--r-- | redfish-core/lib/account_service.hpp | 110 |
1 files changed, 64 insertions, 46 deletions
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index 8a68aaeee0..b4c920557e 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -1594,6 +1594,68 @@ inline void handleAccountCollectionGet( "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); } +inline void processAfterCreateUser( + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& username, const std::string& password, + const boost::system::error_code& ec, sdbusplus::message_t& m) +{ + if (ec) + { + userErrorMessageHandler(m.get_error(), asyncResp, username, ""); + return; + } + + if (pamUpdatePassword(username, password) != PAM_SUCCESS) + { + // At this point we have a user that's been + // created, but the password set + // failed.Something is wrong, so delete the user + // that we've already created + sdbusplus::message::object_path tempObjPath(rootUserDbusPath); + tempObjPath /= username; + const std::string userPath(tempObjPath); + + crow::connections::systemBus->async_method_call( + [asyncResp, password](const boost::system::error_code& ec3) { + if (ec3) + { + messages::internalError(asyncResp->res); + return; + } + + // If password is invalid + messages::propertyValueFormatError(asyncResp->res, password, + "Password"); + }, + "xyz.openbmc_project.User.Manager", userPath, + "xyz.openbmc_project.Object.Delete", "Delete"); + + BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; + return; + } + + messages::created(asyncResp->res); + asyncResp->res.addHeader("Location", + "/redfish/v1/AccountService/Accounts/" + username); +} + +inline void processAfterGetAllGroups( + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& username, const std::string& password, + const std::optional<std::string>& roleId, std::optional<bool> enabled, + const std::vector<std::string>& allGroupsList) + +{ + crow::connections::systemBus->async_method_call( + [asyncResp, username, password](const boost::system::error_code& ec2, + sdbusplus::message_t& m) { + processAfterCreateUser(asyncResp, username, password, ec2, m); + }, + "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", + "xyz.openbmc_project.User.Manager", "CreateUser", username, + allGroupsList, *roleId, *enabled); +} + inline void handleAccountCollectionPost( App& app, const crow::Request& req, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) @@ -1642,52 +1704,8 @@ inline void handleAccountCollectionPost( return; } - crow::connections::systemBus->async_method_call( - [asyncResp, username, password]( - const boost::system::error_code& ec2, sdbusplus::message_t& m) { - if (ec2) - { - userErrorMessageHandler(m.get_error(), asyncResp, username, ""); - return; - } - - if (pamUpdatePassword(username, password) != PAM_SUCCESS) - { - // At this point we have a user that's been - // created, but the password set - // failed.Something is wrong, so delete the user - // that we've already created - sdbusplus::message::object_path tempObjPath(rootUserDbusPath); - tempObjPath /= username; - const std::string userPath(tempObjPath); - - crow::connections::systemBus->async_method_call( - [asyncResp, - password](const boost::system::error_code& ec3) { - if (ec3) - { - messages::internalError(asyncResp->res); - return; - } - - // If password is invalid - messages::propertyValueFormatError(asyncResp->res, password, - "Password"); - }, - "xyz.openbmc_project.User.Manager", userPath, - "xyz.openbmc_project.Object.Delete", "Delete"); - - BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; - return; - } - - messages::created(asyncResp->res); - asyncResp->res.addHeader( - "Location", "/redfish/v1/AccountService/Accounts/" + username); - }, - "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", - "xyz.openbmc_project.User.Manager", "CreateUser", username, - allGroupsList, *roleId, *enabled); + processAfterGetAllGroups(asyncResp, username, password, roleId, enabled, + allGroupsList); }); } |