Skip to content

Commit 95134ef

Browse files
authored
[bugfix] Fix API endpoint to query local and remote users in ND4.0
1 parent b27a842 commit 95134ef

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

plugins/module_utils/mso.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,14 @@ def lookup_users(self, users, ignore_not_found_error=False):
10211021

10221022
ids = []
10231023
if self.platform == "nd":
1024-
remote_users = self.nd_request("/nexus/infra/api/aaa/v4/remoteusers", method="GET")
1025-
local_users = self.nd_request("/nexus/infra/api/aaa/v4/localusers", method="GET")
1024+
remote_users = self.nd_request("/nexus/infra/api/aaa/v4/remoteusers", method="GET", ignore_not_found_error=True)
1025+
local_users = self.nd_request("/nexus/infra/api/aaa/v4/localusers", method="GET", ignore_not_found_error=True)
1026+
1027+
# To handle the issue in ND 4.0 related to querying local and remote users, new API endpoints have been introduced.
1028+
# These endpoints should be removed once the official ND API endpoints become operational.
1029+
if remote_users == {} and local_users == {}:
1030+
remote_users = self.nd_request("/api/config/class/remoteusers", method="GET")
1031+
local_users = self.nd_request("/api/config/class/localusers", method="GET")
10261032

10271033
for user in users:
10281034
user_dict = dict()
@@ -1048,17 +1054,36 @@ def lookup_users(self, users, ignore_not_found_error=False):
10481054
ids.append(id)
10491055
return ids
10501056

1051-
def get_user_from_list_of_users(self, user_name, list_of_users, login_domain=""):
1052-
"""Get user from list of users"""
1053-
for user in list_of_users.get("items"):
1054-
if user.get("spec").get("loginID") == user_name and (login_domain == "" or user.get("spec").get("loginDomain") == login_domain):
1055-
return user.get("spec")
1057+
def get_user_from_list_of_users(self, user_name, users, login_domain=""):
1058+
"""Get user from the ND users API response object"""
1059+
if isinstance(users, dict):
1060+
for user in users.get("items"):
1061+
if (
1062+
user.get("spec")
1063+
and user.get("spec").get("loginID") == user_name
1064+
and ((login_domain == "" and user.get("spec").get("loginDomain") is None) or user.get("spec").get("loginDomain") == login_domain)
1065+
):
1066+
return user.get("spec")
1067+
else:
1068+
# Handling a list of user objects is a temporary workaround that should be removed.
1069+
# Once the ND official local and remote user API endpoints are operational.
1070+
for user in users:
1071+
if (user.get("loginid") == user_name or user.get("loginID") == user_name) and (
1072+
(login_domain == "" and user.get("logindomain") is None) or user.get("logindomain") == login_domain
1073+
):
1074+
return user
10561075
return None
10571076

10581077
def lookup_remote_users(self, remote_users, ignore_not_found_error=False):
10591078
ids = []
10601079
if self.platform == "nd":
1061-
remote_users_data = self.nd_request("/nexus/infra/api/aaa/v4/remoteusers", method="GET")
1080+
remote_users_data = self.nd_request("/nexus/infra/api/aaa/v4/remoteusers", method="GET", ignore_not_found_error=True)
1081+
1082+
# To handle the issue in ND 4.0 related to querying local and remote users, new API endpoints have been introduced.
1083+
# These endpoints should be removed once the official ND API endpoints become operational.
1084+
if remote_users_data == {}:
1085+
remote_users_data = self.nd_request("/api/config/class/remoteusers", method="GET")
1086+
10621087
for remote_user in remote_users:
10631088
user_dict = dict()
10641089
if self.platform == "nd":
@@ -1668,7 +1693,7 @@ def nd_request(self, path, method=None, data=None, file=None, qs=None, prefix=""
16681693
if ignore_not_found_error:
16691694
return {}
16701695
self.fail_json(msg="ND Error: Unknown error no error code in decoded payload".format(**payload), data=data, info=info, payload=payload)
1671-
else:
1696+
elif not ignore_not_found_error:
16721697
self.result["raw"] = info.get("raw")
16731698
# Connection error
16741699
msg = "Connection failed for {0}. {1}".format(info.get("url"), info.get("msg"))

0 commit comments

Comments
 (0)