mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
[PR #7790/787fa462 backport][stable-8] fix(modules/gitlab_runner): Use correct argument to list all runners (#8032)
fix(modules/gitlab_runner): Use correct argument to list all runners (#7790)
* fix(modules/gitlab_runner): Use correct argument to list all runners
python-gitlab 4.0.0 removed support for the `as_list=False` parameter.
This functionality is now available as `iterator=True`.
Without this change, the module actually only retrieves the first
20 results, which can lead to non-idempotent behavior, such as
registering a runner again.
* Add changelog entry (#7790)
* gitlab_runner: Check python-gitlab version when listing runners
* gitlab: Add list_all_kwargs variable to module_utils
* refactor(gitlab modules): use list_all_kwargs where it helps (#7790)
I did not change every instance of all=True or all=False, only those
which could obviously benefit from simplifying:
* Code using `all=True` but then searching for any items that match a
condition (no need to collect the full list).
* Code that basically reimplements `all=True` with manual pagination.
(These could be changed to `all=True`, but `list_all_kwargs` also
sets per_page to 100, to gather data faster.)
* gitlab_instance_variable: Use list_all_kwargs
* Add new changelog entry for gitlab module changes (#7790)
(cherry picked from commit 787fa46217
)
Co-authored-by: Mike Wadsten <mikewadsten@gmail.com>
This commit is contained in:
parent
f8666061bc
commit
828968b0dd
11 changed files with 65 additions and 54 deletions
|
@ -230,7 +230,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.gitlab import (
|
||||
auth_argument_spec, find_group, gitlab_authentication, gitlab
|
||||
auth_argument_spec, find_group, gitlab_authentication, gitlab, list_all_kwargs
|
||||
)
|
||||
|
||||
|
||||
|
@ -345,9 +345,10 @@ class GitLabUser(object):
|
|||
@param sshkey_name Name of the ssh key
|
||||
'''
|
||||
def ssh_key_exists(self, user, sshkey_name):
|
||||
keyList = map(lambda k: k.title, user.keys.list(all=True))
|
||||
|
||||
return sshkey_name in keyList
|
||||
return any(
|
||||
k.title == sshkey_name
|
||||
for k in user.keys.list(**list_all_kwargs)
|
||||
)
|
||||
|
||||
'''
|
||||
@param user User object
|
||||
|
@ -515,10 +516,13 @@ class GitLabUser(object):
|
|||
@param username Username of the user
|
||||
'''
|
||||
def find_user(self, username):
|
||||
users = self._gitlab.users.list(search=username, all=True)
|
||||
for user in users:
|
||||
if (user.username == username):
|
||||
return user
|
||||
return next(
|
||||
(
|
||||
user for user in self._gitlab.users.list(search=username, **list_all_kwargs)
|
||||
if user.username == username
|
||||
),
|
||||
None
|
||||
)
|
||||
|
||||
'''
|
||||
@param username Username of the user
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue