gitlab modules: do not crash if python-gitlab isn't there (#8158)

Do not crash if python-gitlab isn't there.
This commit is contained in:
Felix Fontein 2024-03-29 19:10:42 +01:00 committed by GitHub
parent b2b8fc30bf
commit b463571902
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 30 deletions

View file

@ -81,16 +81,23 @@ def find_group(gitlab_instance, identifier):
return group
def ensure_gitlab_package(module):
def ensure_gitlab_package(module, min_version=None):
if not HAS_GITLAB_PACKAGE:
module.fail_json(
msg=missing_required_lib("python-gitlab", url='https://python-gitlab.readthedocs.io/en/stable/'),
exception=GITLAB_IMP_ERR
)
gitlab_version = gitlab.__version__
if min_version is not None and LooseVersion(gitlab_version) < LooseVersion(min_version):
module.fail_json(
msg="This module requires python-gitlab Python module >= %s "
"(installed version: %s). Please upgrade python-gitlab to version %s or above."
% (min_version, gitlab_version, min_version)
)
def gitlab_authentication(module):
ensure_gitlab_package(module)
def gitlab_authentication(module, min_version=None):
ensure_gitlab_package(module, min_version=min_version)
gitlab_url = module.params['api_url']
validate_certs = module.params['validate_certs']