mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 21:33:12 +00:00
Reformat everything.
This commit is contained in:
@@ -133,17 +133,17 @@ function_namespace:
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.scaleway import (
|
||||
SCALEWAY_REGIONS, scaleway_argument_spec, Scaleway,
|
||||
scaleway_waitable_resource_argument_spec, resource_attributes_should_be_changed,
|
||||
SecretVariables
|
||||
SCALEWAY_REGIONS,
|
||||
scaleway_argument_spec,
|
||||
Scaleway,
|
||||
scaleway_waitable_resource_argument_spec,
|
||||
resource_attributes_should_be_changed,
|
||||
SecretVariables,
|
||||
)
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
STABLE_STATES = (
|
||||
"ready",
|
||||
"absent"
|
||||
)
|
||||
STABLE_STATES = ("ready", "absent")
|
||||
|
||||
MUTABLE_ATTRIBUTES = (
|
||||
"description",
|
||||
@@ -158,7 +158,7 @@ def payload_from_wished_fn(wished_fn):
|
||||
"name": wished_fn["name"],
|
||||
"description": wished_fn["description"],
|
||||
"environment_variables": wished_fn["environment_variables"],
|
||||
"secret_environment_variables": SecretVariables.dict_to_list(wished_fn["secret_environment_variables"])
|
||||
"secret_environment_variables": SecretVariables.dict_to_list(wished_fn["secret_environment_variables"]),
|
||||
}
|
||||
|
||||
return payload
|
||||
@@ -181,7 +181,7 @@ def absent_strategy(api, wished_fn):
|
||||
api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES, force_wait=True)
|
||||
response = api.delete(path=f"{api.api_path}/{target_fn['id']}")
|
||||
if not response.ok:
|
||||
api.module.fail_json(msg=f'Error deleting function namespace [{response.status_code}: {response.json}]')
|
||||
api.module.fail_json(msg=f"Error deleting function namespace [{response.status_code}: {response.json}]")
|
||||
|
||||
api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES)
|
||||
return changed, response.json
|
||||
@@ -202,8 +202,7 @@ def present_strategy(api, wished_fn):
|
||||
|
||||
# Create function namespace
|
||||
api.warn(payload_fn)
|
||||
creation_response = api.post(path=api.api_path,
|
||||
data=payload_fn)
|
||||
creation_response = api.post(path=api.api_path, data=payload_fn)
|
||||
|
||||
if not creation_response.ok:
|
||||
msg = f"Error during function namespace creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})"
|
||||
@@ -215,13 +214,16 @@ def present_strategy(api, wished_fn):
|
||||
|
||||
target_fn = fn_lookup[wished_fn["name"]]
|
||||
decoded_target_fn = deepcopy(target_fn)
|
||||
decoded_target_fn["secret_environment_variables"] = SecretVariables.decode(decoded_target_fn["secret_environment_variables"],
|
||||
payload_fn["secret_environment_variables"])
|
||||
decoded_target_fn["secret_environment_variables"] = SecretVariables.decode(
|
||||
decoded_target_fn["secret_environment_variables"], payload_fn["secret_environment_variables"]
|
||||
)
|
||||
|
||||
patch_payload = resource_attributes_should_be_changed(target=decoded_target_fn,
|
||||
wished=payload_fn,
|
||||
verifiable_mutable_attributes=MUTABLE_ATTRIBUTES,
|
||||
mutable_attributes=MUTABLE_ATTRIBUTES)
|
||||
patch_payload = resource_attributes_should_be_changed(
|
||||
target=decoded_target_fn,
|
||||
wished=payload_fn,
|
||||
verifiable_mutable_attributes=MUTABLE_ATTRIBUTES,
|
||||
mutable_attributes=MUTABLE_ATTRIBUTES,
|
||||
)
|
||||
|
||||
if not patch_payload:
|
||||
return changed, target_fn
|
||||
@@ -230,21 +232,19 @@ def present_strategy(api, wished_fn):
|
||||
if api.module.check_mode:
|
||||
return changed, {"status": "Function namespace attributes would be changed."}
|
||||
|
||||
fn_patch_response = api.patch(path=f"{api.api_path}/{target_fn['id']}",
|
||||
data=patch_payload)
|
||||
fn_patch_response = api.patch(path=f"{api.api_path}/{target_fn['id']}", data=patch_payload)
|
||||
|
||||
if not fn_patch_response.ok:
|
||||
api.module.fail_json(msg=f"Error during function namespace attributes update: [{fn_patch_response.status_code}: {fn_patch_response.json['message']}]")
|
||||
api.module.fail_json(
|
||||
msg=f"Error during function namespace attributes update: [{fn_patch_response.status_code}: {fn_patch_response.json['message']}]"
|
||||
)
|
||||
|
||||
api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES)
|
||||
response = api.get(path=f"{api.api_path}/{target_fn['id']}")
|
||||
return changed, response.json
|
||||
|
||||
|
||||
state_strategy = {
|
||||
"present": present_strategy,
|
||||
"absent": absent_strategy
|
||||
}
|
||||
state_strategy = {"present": present_strategy, "absent": absent_strategy}
|
||||
|
||||
|
||||
def core(module):
|
||||
@@ -255,9 +255,9 @@ def core(module):
|
||||
"state": module.params["state"],
|
||||
"project_id": module.params["project_id"],
|
||||
"name": module.params["name"],
|
||||
"description": module.params['description'],
|
||||
"environment_variables": module.params['environment_variables'],
|
||||
"secret_environment_variables": module.params['secret_environment_variables']
|
||||
"description": module.params["description"],
|
||||
"environment_variables": module.params["environment_variables"],
|
||||
"secret_environment_variables": module.params["secret_environment_variables"],
|
||||
}
|
||||
|
||||
api = Scaleway(module=module)
|
||||
@@ -271,15 +271,17 @@ def core(module):
|
||||
def main():
|
||||
argument_spec = scaleway_argument_spec()
|
||||
argument_spec.update(scaleway_waitable_resource_argument_spec())
|
||||
argument_spec.update(dict(
|
||||
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||
project_id=dict(type='str', required=True),
|
||||
region=dict(type='str', required=True, choices=SCALEWAY_REGIONS),
|
||||
name=dict(type='str', required=True),
|
||||
description=dict(type='str', default=''),
|
||||
environment_variables=dict(type='dict', default={}),
|
||||
secret_environment_variables=dict(type='dict', default={}, no_log=True)
|
||||
))
|
||||
argument_spec.update(
|
||||
dict(
|
||||
state=dict(type="str", default="present", choices=["absent", "present"]),
|
||||
project_id=dict(type="str", required=True),
|
||||
region=dict(type="str", required=True, choices=SCALEWAY_REGIONS),
|
||||
name=dict(type="str", required=True),
|
||||
description=dict(type="str", default=""),
|
||||
environment_variables=dict(type="dict", default={}),
|
||||
secret_environment_variables=dict(type="dict", default={}, no_log=True),
|
||||
)
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
@@ -288,5 +290,5 @@ def main():
|
||||
core(module)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user