From 49cc263fdcfc9b279c399c0b03bfd7e9167e06c2 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Wed, 20 Mar 2024 12:49:15 -0700 Subject: Fix unused variable warning in LDAP It's not clear how this came to be the way it is, but tidy now warns that this variable is unused (which it is). Refactor the LDAP code to not use the variable, and to use concrete object_t and array_t Tested: Redfish service validator passes. Change-Id: I0c106d10594a396d506bf9865cb29d4a10a372a1 Signed-off-by: Ed Tanous --- redfish-core/lib/account_service.hpp | 47 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'redfish-core') diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index ab9048a435..23f1616964 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -321,27 +321,32 @@ inline void parseLDAPConfigData(nlohmann::json& jsonResponse, const LDAPConfigData& confData, const std::string& ldapType) { - std::string service = (ldapType == "LDAP") ? "LDAPService" - : "ActiveDirectoryService"; - - nlohmann::json& ldap = jsonResponse[ldapType]; - + nlohmann::json::object_t ldap; ldap["ServiceEnabled"] = confData.serviceEnabled; - ldap["ServiceAddresses"] = nlohmann::json::array({confData.uri}); - ldap["Authentication"]["AuthenticationType"] = + nlohmann::json::array_t serviceAddresses; + serviceAddresses.emplace_back(confData.uri); + ldap["ServiceAddresses"] = std::move(serviceAddresses); + + nlohmann::json::object_t authentication; + authentication["AuthenticationType"] = account_service::AuthenticationTypes::UsernameAndPassword; - ldap["Authentication"]["Username"] = confData.bindDN; - ldap["Authentication"]["Password"] = nullptr; - - ldap["LDAPService"]["SearchSettings"]["BaseDistinguishedNames"] = - nlohmann::json::array({confData.baseDN}); - ldap["LDAPService"]["SearchSettings"]["UsernameAttribute"] = - confData.userNameAttribute; - ldap["LDAPService"]["SearchSettings"]["GroupsAttribute"] = - confData.groupAttribute; - - nlohmann::json& roleMapArray = ldap["RemoteRoleMapping"]; - roleMapArray = nlohmann::json::array(); + authentication["Username"] = confData.bindDN; + authentication["Password"] = nullptr; + ldap["Authentication"] = std::move(authentication); + + nlohmann::json::object_t ldapService; + nlohmann::json::object_t searchSettings; + nlohmann::json::array_t baseDistinguishedNames; + baseDistinguishedNames.emplace_back(confData.baseDN); + + searchSettings["BaseDistinguishedNames"] = + std::move(baseDistinguishedNames); + searchSettings["UsernameAttribute"] = confData.userNameAttribute; + searchSettings["GroupsAttribute"] = confData.groupAttribute; + ldapService["SearchSettings"] = std::move(searchSettings); + ldap["LDAPService"] = std::move(ldapService); + + nlohmann::json::array_t roleMapArray; for (const auto& obj : confData.groupRoleList) { BMCWEB_LOG_DEBUG("Pushing the data groupName={}", obj.second.groupName); @@ -351,6 +356,10 @@ inline void parseLDAPConfigData(nlohmann::json& jsonResponse, remoteGroup["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege); roleMapArray.emplace_back(std::move(remoteGroup)); } + + ldap["RemoteRoleMapping"] = std::move(roleMapArray); + + jsonResponse[ldapType].update(ldap); } /** -- cgit v1.2.3