mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-19 02:11:32 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -265,8 +265,13 @@ end_state:
|
|||
}
|
||||
"""
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.identity.keycloak.keycloak import KeycloakAPI, camel, \
|
||||
keycloak_argument_spec, get_token, KeycloakError
|
||||
from ansible_collections.community.general.plugins.module_utils.identity.keycloak.keycloak import (
|
||||
KeycloakAPI,
|
||||
camel,
|
||||
keycloak_argument_spec,
|
||||
get_token,
|
||||
KeycloakError,
|
||||
)
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
|
|
@ -279,39 +284,43 @@ def main():
|
|||
argument_spec = keycloak_argument_spec()
|
||||
|
||||
protmapper_spec = dict(
|
||||
consentRequired=dict(type='bool'),
|
||||
consentText=dict(type='str'),
|
||||
id=dict(type='str'),
|
||||
name=dict(type='str'),
|
||||
protocol=dict(type='str', choices=['openid-connect', 'saml', 'docker-v2']),
|
||||
protocolMapper=dict(type='str'),
|
||||
config=dict(type='dict'),
|
||||
consentRequired=dict(type="bool"),
|
||||
consentText=dict(type="str"),
|
||||
id=dict(type="str"),
|
||||
name=dict(type="str"),
|
||||
protocol=dict(type="str", choices=["openid-connect", "saml", "docker-v2"]),
|
||||
protocolMapper=dict(type="str"),
|
||||
config=dict(type="dict"),
|
||||
)
|
||||
|
||||
meta_args = dict(
|
||||
realm=dict(type='str', default='master'),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
|
||||
id=dict(type='str'),
|
||||
name=dict(type='str'),
|
||||
description=dict(type='str'),
|
||||
protocol=dict(type='str', choices=['openid-connect', 'saml', 'docker-v2']),
|
||||
attributes=dict(type='dict'),
|
||||
full_scope_allowed=dict(type='bool'),
|
||||
protocol_mappers=dict(type='list', elements='dict', options=protmapper_spec),
|
||||
realm=dict(type="str", default="master"),
|
||||
state=dict(default="present", choices=["present", "absent"]),
|
||||
id=dict(type="str"),
|
||||
name=dict(type="str"),
|
||||
description=dict(type="str"),
|
||||
protocol=dict(type="str", choices=["openid-connect", "saml", "docker-v2"]),
|
||||
attributes=dict(type="dict"),
|
||||
full_scope_allowed=dict(type="bool"),
|
||||
protocol_mappers=dict(type="list", elements="dict", options=protmapper_spec),
|
||||
)
|
||||
|
||||
argument_spec.update(meta_args)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=([['id', 'name'],
|
||||
['token', 'auth_realm', 'auth_username', 'auth_password', 'auth_client_id', 'auth_client_secret']]),
|
||||
required_together=([['auth_username', 'auth_password']]),
|
||||
required_by={'refresh_token': 'auth_realm'},
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_one_of=(
|
||||
[
|
||||
["id", "name"],
|
||||
["token", "auth_realm", "auth_username", "auth_password", "auth_client_id", "auth_client_secret"],
|
||||
]
|
||||
),
|
||||
required_together=([["auth_username", "auth_password"]]),
|
||||
required_by={"refresh_token": "auth_realm"},
|
||||
)
|
||||
|
||||
result = dict(changed=False, msg='', diff={}, proposed={}, existing={}, end_state={})
|
||||
result = dict(changed=False, msg="", diff={}, proposed={}, existing={}, end_state={})
|
||||
|
||||
# Obtain access token, initialize API
|
||||
try:
|
||||
|
|
@ -321,28 +330,41 @@ def main():
|
|||
|
||||
kc = KeycloakAPI(module, connection_header)
|
||||
|
||||
realm = module.params.get('realm')
|
||||
state = module.params.get('state')
|
||||
cid = module.params.get('id')
|
||||
realm = module.params.get("realm")
|
||||
state = module.params.get("state")
|
||||
cid = module.params.get("id")
|
||||
|
||||
# Filter and map the parameters names that apply to the client template
|
||||
clientt_params = [x for x in module.params
|
||||
if x not in ['state', 'auth_keycloak_url', 'auth_client_id', 'auth_realm',
|
||||
'auth_client_secret', 'auth_username', 'auth_password',
|
||||
'validate_certs', 'realm'] and module.params.get(x) is not None]
|
||||
clientt_params = [
|
||||
x
|
||||
for x in module.params
|
||||
if x
|
||||
not in [
|
||||
"state",
|
||||
"auth_keycloak_url",
|
||||
"auth_client_id",
|
||||
"auth_realm",
|
||||
"auth_client_secret",
|
||||
"auth_username",
|
||||
"auth_password",
|
||||
"validate_certs",
|
||||
"realm",
|
||||
]
|
||||
and module.params.get(x) is not None
|
||||
]
|
||||
|
||||
# See if it already exists in Keycloak
|
||||
if cid is None:
|
||||
before_clientt = kc.get_client_template_by_name(module.params.get('name'), realm=realm)
|
||||
before_clientt = kc.get_client_template_by_name(module.params.get("name"), realm=realm)
|
||||
if before_clientt is not None:
|
||||
cid = before_clientt['id']
|
||||
cid = before_clientt["id"]
|
||||
else:
|
||||
before_clientt = kc.get_client_template_by_id(cid, realm=realm)
|
||||
|
||||
if before_clientt is None:
|
||||
before_clientt = {}
|
||||
|
||||
result['existing'] = before_clientt
|
||||
result["existing"] = before_clientt
|
||||
|
||||
# Build a proposed changeset from parameters given to this module
|
||||
changeset = {}
|
||||
|
|
@ -361,50 +383,49 @@ def main():
|
|||
desired_clientt = before_clientt.copy()
|
||||
desired_clientt.update(changeset)
|
||||
|
||||
result['proposed'] = changeset
|
||||
result["proposed"] = changeset
|
||||
|
||||
# Cater for when it doesn't exist (an empty dict)
|
||||
if not before_clientt:
|
||||
if state == 'absent':
|
||||
if state == "absent":
|
||||
# Do nothing and exit
|
||||
if module._diff:
|
||||
result['diff'] = dict(before='', after='')
|
||||
result['changed'] = False
|
||||
result['end_state'] = {}
|
||||
result['msg'] = 'Client template does not exist, doing nothing.'
|
||||
result["diff"] = dict(before="", after="")
|
||||
result["changed"] = False
|
||||
result["end_state"] = {}
|
||||
result["msg"] = "Client template does not exist, doing nothing."
|
||||
module.exit_json(**result)
|
||||
|
||||
# Process a creation
|
||||
result['changed'] = True
|
||||
result["changed"] = True
|
||||
|
||||
if 'name' not in desired_clientt:
|
||||
module.fail_json(msg='name needs to be specified when creating a new client')
|
||||
if "name" not in desired_clientt:
|
||||
module.fail_json(msg="name needs to be specified when creating a new client")
|
||||
|
||||
if module._diff:
|
||||
result['diff'] = dict(before='', after=desired_clientt)
|
||||
result["diff"] = dict(before="", after=desired_clientt)
|
||||
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
|
||||
# create it
|
||||
kc.create_client_template(desired_clientt, realm=realm)
|
||||
after_clientt = kc.get_client_template_by_name(desired_clientt['name'], realm=realm)
|
||||
after_clientt = kc.get_client_template_by_name(desired_clientt["name"], realm=realm)
|
||||
|
||||
result['end_state'] = after_clientt
|
||||
result["end_state"] = after_clientt
|
||||
|
||||
result['msg'] = f"Client template {desired_clientt['name']} has been created."
|
||||
result["msg"] = f"Client template {desired_clientt['name']} has been created."
|
||||
module.exit_json(**result)
|
||||
|
||||
else:
|
||||
if state == 'present':
|
||||
if state == "present":
|
||||
# Process an update
|
||||
|
||||
result['changed'] = True
|
||||
result["changed"] = True
|
||||
if module.check_mode:
|
||||
# We can only compare the current client template with the proposed updates we have
|
||||
if module._diff:
|
||||
result['diff'] = dict(before=before_clientt,
|
||||
after=desired_clientt)
|
||||
result["diff"] = dict(before=before_clientt, after=desired_clientt)
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
|
@ -413,36 +434,36 @@ def main():
|
|||
|
||||
after_clientt = kc.get_client_template_by_id(cid, realm=realm)
|
||||
if before_clientt == after_clientt:
|
||||
result['changed'] = False
|
||||
result["changed"] = False
|
||||
|
||||
result['end_state'] = after_clientt
|
||||
result["end_state"] = after_clientt
|
||||
|
||||
if module._diff:
|
||||
result['diff'] = dict(before=before_clientt, after=after_clientt)
|
||||
result["diff"] = dict(before=before_clientt, after=after_clientt)
|
||||
|
||||
result['msg'] = f"Client template {desired_clientt['name']} has been updated."
|
||||
result["msg"] = f"Client template {desired_clientt['name']} has been updated."
|
||||
module.exit_json(**result)
|
||||
|
||||
else:
|
||||
# Process a deletion (because state was not 'present')
|
||||
result['changed'] = True
|
||||
result["changed"] = True
|
||||
|
||||
if module._diff:
|
||||
result['diff'] = dict(before=before_clientt, after='')
|
||||
result["diff"] = dict(before=before_clientt, after="")
|
||||
|
||||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
|
||||
# delete it
|
||||
kc.delete_client_template(cid, realm=realm)
|
||||
result['proposed'] = {}
|
||||
result["proposed"] = {}
|
||||
|
||||
result['end_state'] = {}
|
||||
result["end_state"] = {}
|
||||
|
||||
result['msg'] = f"Client template {before_clientt['name']} has been deleted."
|
||||
result["msg"] = f"Client template {before_clientt['name']} has been deleted."
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue