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

refactor(gitlab modules): remove duplicate gitlab package check (#7486)

This commit is contained in:
Léo GATELLIER 2023-11-11 12:20:12 +01:00 committed by GitHub
parent 6b00b76f32
commit 4a74f46e56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 63 additions and 65 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- gitlab modules - remove duplicate ``gitlab`` package check (https://github.com/ansible-collections/community.general/pull/7486).

View file

@ -75,6 +75,8 @@ def ensure_gitlab_package(module):
def gitlab_authentication(module):
ensure_gitlab_package(module)
gitlab_url = module.params['api_url']
validate_certs = module.params['validate_certs']
ca_path = module.params['ca_path']
@ -84,8 +86,6 @@ def gitlab_authentication(module):
gitlab_oauth_token = module.params['api_oauth_token']
gitlab_job_token = module.params['api_job_token']
ensure_gitlab_package(module)
verify = ca_path if validate_certs and ca_path else validate_certs
try:

View file

@ -84,7 +84,7 @@ from ansible.module_utils.api import basic_auth_argument_spec
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, gitlab, ensure_gitlab_package
auth_argument_spec, gitlab_authentication, gitlab
)
@ -144,7 +144,9 @@ def main():
],
supports_check_mode=False
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
project = module.params['project']
branch = module.params['branch']
@ -156,7 +158,6 @@ def main():
module.fail_json(msg="community.general.gitlab_proteched_branch requires python-gitlab Python module >= 2.3.0 (installed version: [%s])."
" Please upgrade python-gitlab to version 2.3.0 or above." % gitlab_version)
gitlab_instance = gitlab_authentication(module)
this_gitlab = GitlabBranch(module=module, project=project, gitlab_instance=gitlab_instance)
this_branch = this_gitlab.get_branch(branch)

View file

@ -121,7 +121,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_project, gitlab_authentication, gitlab, ensure_gitlab_package
auth_argument_spec, find_project, gitlab_authentication, gitlab
)
@ -261,7 +261,9 @@ def main():
],
supports_check_mode=True,
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
state = module.params['state']
project_identifier = module.params['project']
@ -269,8 +271,6 @@ def main():
key_keyfile = module.params['key']
key_can_push = module.params['can_push']
gitlab_instance = gitlab_authentication(module)
gitlab_deploy_key = GitLabDeployKey(module, gitlab_instance)
project = find_project(gitlab_instance, project_identifier)

View file

@ -178,7 +178,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, ensure_gitlab_package
auth_argument_spec, find_group, gitlab_authentication, gitlab
)
@ -355,7 +355,9 @@ def main():
],
supports_check_mode=True,
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
group_name = module.params['name']
group_path = module.params['path']
@ -370,8 +372,6 @@ def main():
avatar_path = module.params['avatar_path']
force_delete = module.params['force_delete']
gitlab_instance = gitlab_authentication(module)
# Define default group_path based on group_name
if group_path is None:
group_path = group_name.replace(" ", "_")

View file

@ -160,7 +160,7 @@ from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, gitlab, ensure_gitlab_package
auth_argument_spec, gitlab_authentication, gitlab
)
@ -273,7 +273,9 @@ def main():
],
supports_check_mode=True,
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gl = gitlab_authentication(module)
access_level_int = {
'guest': gitlab.const.GUEST_ACCESS,
@ -291,9 +293,6 @@ def main():
if purge_users:
purge_users = [access_level_int[level] for level in purge_users]
# connect to gitlab server
gl = gitlab_authentication(module)
group = GitLabGroup(module, gl)
gitlab_group_id = group.get_group_id(gitlab_group)

View file

@ -207,7 +207,7 @@ group_variable:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.api import basic_auth_argument_spec
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, ensure_gitlab_package, filter_returned_variables, vars_to_variables
auth_argument_spec, gitlab_authentication, filter_returned_variables, vars_to_variables
)
@ -413,7 +413,9 @@ def main():
],
supports_check_mode=True
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
purge = module.params['purge']
var_list = module.params['vars']
@ -428,8 +430,6 @@ def main():
if any(x['value'] is None for x in variables):
module.fail_json(msg='value parameter is required in state present')
gitlab_instance = gitlab_authentication(module)
this_gitlab = GitlabGroupVariables(module=module, gitlab_instance=gitlab_instance)
changed, raw_return_value, before, after = native_python_main(this_gitlab, purge, variables, state, module)

View file

@ -171,7 +171,7 @@ from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, find_project, gitlab_authentication, ensure_gitlab_package
auth_argument_spec, find_project, gitlab_authentication
)
@ -325,7 +325,9 @@ def main():
],
supports_check_mode=True,
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
state = module.params['state']
project_identifier = module.params['project']
@ -342,8 +344,6 @@ def main():
enable_ssl_verification = module.params['hook_validate_certs']
hook_token = module.params['token']
gitlab_instance = gitlab_authentication(module)
gitlab_hook = GitLabHook(module, gitlab_instance)
project = find_project(gitlab_instance, project_identifier)

View file

@ -139,7 +139,7 @@ instance_variable:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.api import basic_auth_argument_spec
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, ensure_gitlab_package, filter_returned_variables
auth_argument_spec, gitlab_authentication, filter_returned_variables
)
@ -326,7 +326,9 @@ def main():
],
supports_check_mode=True
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
purge = module.params['purge']
state = module.params['state']
@ -337,8 +339,6 @@ def main():
if any(x['value'] is None for x in variables):
module.fail_json(msg='value parameter is required in state present')
gitlab_instance = gitlab_authentication(module)
this_gitlab = GitlabInstanceVariables(module=module, gitlab_instance=gitlab_instance)
changed, raw_return_value, before, after = native_python_main(this_gitlab, purge, variables, state, module)

View file

@ -152,7 +152,7 @@ from ansible.module_utils.common.text.converters import to_native, to_text
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, gitlab, ensure_gitlab_package, find_project
auth_argument_spec, gitlab_authentication, gitlab, find_project
)
@ -321,7 +321,9 @@ def main():
],
supports_check_mode=True
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
project = module.params['project']
source_branch = module.params['source_branch']
@ -341,8 +343,6 @@ def main():
module.fail_json(msg="community.general.gitlab_merge_request requires python-gitlab Python module >= 2.3.0 (installed version: [%s])."
" Please upgrade python-gitlab to version 2.3.0 or above." % gitlab_version)
gitlab_instance = gitlab_authentication(module)
this_project = find_project(gitlab_instance, project)
if this_project is None:
module.fail_json(msg="Failed to get the project: %s" % project)

View file

@ -340,7 +340,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, find_project, gitlab_authentication, gitlab, ensure_gitlab_package
auth_argument_spec, find_group, find_project, gitlab_authentication, gitlab
)
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
@ -558,7 +558,9 @@ def main():
],
supports_check_mode=True,
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
group_identifier = module.params['group']
project_name = module.params['name']
@ -596,8 +598,6 @@ def main():
security_and_compliance_access_level = module.params['security_and_compliance_access_level']
topics = module.params['topics']
gitlab_instance = gitlab_authentication(module)
# Set project_path to project_name if it is empty.
if project_path is None:
project_path = project_name.replace(" ", "_")

View file

@ -97,7 +97,7 @@ from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, find_project, ensure_gitlab_package
auth_argument_spec, gitlab_authentication, find_project
)
@ -159,13 +159,12 @@ state_strategy = {
def core(module):
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gl = gitlab_authentication(module)
gitlab_project = module.params['project']
state = module.params['state']
gl = gitlab_authentication(module)
project = find_project(gl, gitlab_project)
# project doesn't exist
if not project:

View file

@ -163,7 +163,7 @@ from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, gitlab, ensure_gitlab_package
auth_argument_spec, gitlab_authentication, gitlab
)
@ -279,7 +279,9 @@ def main():
],
supports_check_mode=True,
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gl = gitlab_authentication(module)
access_level_int = {
'guest': gitlab.const.GUEST_ACCESS,
@ -296,9 +298,6 @@ def main():
if purge_users:
purge_users = [access_level_int[level] for level in purge_users]
# connect to gitlab server
gl = gitlab_authentication(module)
project = GitLabProjectMembers(module, gl)
gitlab_project_id = project.get_project(gitlab_project)

View file

@ -221,13 +221,12 @@ project_variable:
sample: ['ACCESS_KEY_ID', 'SECRET_ACCESS_KEY']
'''
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.api import basic_auth_argument_spec
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, ensure_gitlab_package, filter_returned_variables, vars_to_variables,
HAS_GITLAB_PACKAGE, GITLAB_IMP_ERR
auth_argument_spec, gitlab_authentication, filter_returned_variables, vars_to_variables
)
@ -436,10 +435,9 @@ def main():
],
supports_check_mode=True
)
ensure_gitlab_package(module)
if not HAS_GITLAB_PACKAGE:
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
purge = module.params['purge']
var_list = module.params['vars']
@ -454,8 +452,6 @@ def main():
if any(x['value'] is None for x in variables):
module.fail_json(msg='value parameter is required for all variables in state present')
gitlab_instance = gitlab_authentication(module)
this_gitlab = GitlabProjectVariables(module=module, gitlab_instance=gitlab_instance)
change, raw_return_value, before, after = native_python_main(this_gitlab, purge, variables, state, module)

View file

@ -83,7 +83,7 @@ from ansible.module_utils.api import basic_auth_argument_spec
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, gitlab, ensure_gitlab_package
auth_argument_spec, gitlab_authentication, gitlab
)
@ -164,7 +164,9 @@ def main():
],
supports_check_mode=True
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
project = module.params['project']
name = module.params['name']
@ -177,7 +179,6 @@ def main():
module.fail_json(msg="community.general.gitlab_proteched_branch requires python-gitlab Python module >= 2.3.0 (installed version: [%s])."
" Please upgrade python-gitlab to version 2.3.0 or above." % gitlab_version)
gitlab_instance = gitlab_authentication(module)
this_gitlab = GitlabProtectedBranch(module=module, project=project, gitlab_instance=gitlab_instance)
p_branch = this_gitlab.protected_branch_exist(name=name)

View file

@ -220,7 +220,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, gitlab_authentication, gitlab, ensure_gitlab_package
auth_argument_spec, gitlab_authentication, gitlab
)
@ -417,7 +417,9 @@ def main():
],
supports_check_mode=True,
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
state = module.params['state']
runner_description = module.params['description']
@ -431,7 +433,6 @@ def main():
project = module.params['project']
group = module.params['group']
gitlab_instance = gitlab_authentication(module)
gitlab_project = None
gitlab_group = None

View file

@ -234,7 +234,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, ensure_gitlab_package
auth_argument_spec, find_group, gitlab_authentication, gitlab
)
@ -616,7 +616,9 @@ def main():
('state', 'present', ['name', 'email']),
)
)
ensure_gitlab_package(module)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
user_name = module.params['name']
state = module.params['state']
@ -635,8 +637,6 @@ def main():
user_identities = module.params['identities']
overwrite_identities = module.params['overwrite_identities']
gitlab_instance = gitlab_authentication(module)
gitlab_user = GitLabUser(module, gitlab_instance)
user_exists = gitlab_user.exists_user(user_username)
if user_exists: