@@ -1021,8 +1021,14 @@ def lookup_users(self, users, ignore_not_found_error=False):
1021
1021
1022
1022
ids = []
1023
1023
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" )
1026
1032
1027
1033
for user in users :
1028
1034
user_dict = dict ()
@@ -1048,17 +1054,36 @@ def lookup_users(self, users, ignore_not_found_error=False):
1048
1054
ids .append (id )
1049
1055
return ids
1050
1056
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
1056
1075
return None
1057
1076
1058
1077
def lookup_remote_users (self , remote_users , ignore_not_found_error = False ):
1059
1078
ids = []
1060
1079
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
+
1062
1087
for remote_user in remote_users :
1063
1088
user_dict = dict ()
1064
1089
if self .platform == "nd" :
@@ -1668,7 +1693,7 @@ def nd_request(self, path, method=None, data=None, file=None, qs=None, prefix=""
1668
1693
if ignore_not_found_error :
1669
1694
return {}
1670
1695
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 :
1672
1697
self .result ["raw" ] = info .get ("raw" )
1673
1698
# Connection error
1674
1699
msg = "Connection failed for {0}. {1}" .format (info .get ("url" ), info .get ("msg" ))
0 commit comments