1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #6568/27fe14bf backport][stable-6] Fix get_user_by_username in keycloak library (#6582)

Fix get_user_by_username in keycloak library (#6568)

* Fix get_user_by_username in keycloak library for keycloak_user_rolemapping module

* Add changelog fragment for keycloak.py bug fix

(cherry picked from commit 27fe14bfc1)

Co-authored-by: Philippe Gauthier <philippe.gauthier@inspq.qc.ca>
This commit is contained in:
patchback[bot] 2023-05-29 15:58:56 +02:00 committed by GitHub
parent af78b2068a
commit 6cb044ac13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- keycloak module utils - the function ``get_user_by_username`` now return the user representation or ``None`` as stated in the documentation (https://github.com/ansible-collections/community.general/pull/6758).

View file

@ -747,8 +747,15 @@ class KeycloakAPI(object):
users_url = URL_USERS.format(url=self.baseurl, realm=realm)
users_url += '?username=%s&exact=true' % username
try:
return json.loads(to_native(open_url(users_url, method='GET', headers=self.restheaders, timeout=self.connection_timeout,
validate_certs=self.validate_certs).read()))
userrep = None
users = json.loads(to_native(open_url(users_url, method='GET', headers=self.restheaders, timeout=self.connection_timeout,
validate_certs=self.validate_certs).read()))
for user in users:
if user['username'] == username:
userrep = user
break
return userrep
except ValueError as e:
self.module.fail_json(msg='API returned incorrect JSON when trying to obtain the user for realm %s and username %s: %s'
% (realm, username, str(e)))