mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-18 16:31:26 -07:00
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:
parent
165182cdbf
commit
febe7a2fb4
4 changed files with 43 additions and 85 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue