gitlab modules: minor refactor (#6384)

* gitlab modules: minor refactor

* add changelog frag

* Update plugins/module_utils/gitlab.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/module_utils/gitlab.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* update changelog frag

* remove extraneous bracket

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2023-05-09 05:40:52 +12:00 committed by GitHub
parent 165182cdbf
commit febe7a2fb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 85 deletions

View file

@ -10,6 +10,7 @@ __metaclass__ = type
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils.common.text.converters import to_native
from ansible.module_utils.six import integer_types, string_types
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
@ -121,3 +122,38 @@ def filter_returned_variables(gitlab_variables):
if key not in KNOWN:
item.pop(key)
return existing_variables
def vars_to_variables(vars, module):
# transform old vars to new variables structure
variables = list()
for item, value in vars.items():
if isinstance(value, (string_types, integer_types, float)):
variables.append(
{
"name": item,
"value": str(value),
"masked": False,
"protected": False,
"variable_type": "env_var",
}
)
elif isinstance(value, dict):
new_item = {
"name": item,
"value": value.get('value'),
"masked": value.get('masked'),
"protected": value.get('protected'),
"variable_type": value.get('variable_type'),
}
if value.get('environment_scope'):
new_item['environment_scope'] = value.get('environment_scope')
variables.append(new_item)
else:
module.fail_json(msg="value must be of type string, integer, float or dict")
return variables