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

442 lines
14 KiB
Python
Raw Normal View History

2020-03-09 10:11:07 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Adam Goossens <adam.goossens@gmail.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
2020-03-09 10:11:07 +01:00
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: keycloak_group
short_description: Allows administration of Keycloak groups via Keycloak API
description:
- This module allows you to add, remove or modify Keycloak groups via the Keycloak REST API.
It requires access to the REST API via OpenID Connect; the user connecting and the client being
used must have the requisite access rights. In a default Keycloak installation, admin-cli
and an admin user would work, as would a separate client definition with the scope tailored
to your needs and a user having the expected roles.
- The names of module options are snake_cased versions of the camelCase ones found in the
Keycloak API and its documentation at U(https://www.keycloak.org/docs-api/8.0/rest-api/index.html).
- Attributes are multi-valued in the Keycloak API. All attributes are lists of individual values and will
be returned that way by this module. You may pass single values for attributes when calling the module,
and this will be translated into a list suitable for the API.
- When updating a group, where possible provide the group ID to the module. This removes a lookup
to the API to translate the name into the group ID.
options:
state:
description:
- State of the group.
- On C(present), the group will be created if it does not yet exist, or updated with the parameters you provide.
- On C(absent), the group will be removed if it exists.
default: 'present'
type: str
choices:
- present
- absent
name:
type: str
description:
- Name of the group.
- This parameter is required only when creating or updating the group.
realm:
type: str
description:
- They Keycloak realm under which this group resides.
default: 'master'
id:
type: str
description:
- The unique identifier for this group.
- This parameter is not required for updating or deleting a group but
providing it will reduce the number of API calls required.
attributes:
type: dict
description:
- A dict of key/value pairs to set as custom attributes for the group.
- Values may be single values (e.g. a string) or a list of strings.
notes:
- Presently, the I(realmRoles), I(clientRoles) and I(access) attributes returned by the Keycloak API
are read-only for groups. This limitation will be removed in a later version of this module.
extends_documentation_fragment:
- community.general.keycloak
author:
- Adam Goossens (@adamgoossens)
'''
EXAMPLES = '''
Allow keycloak modules to take token as parameter for the auth. (#2250) * Allow keycloak_group.py to take token as parameter for the authentification * Fix some pep8 issues * Add changelog fragment * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Fix unit test and add new one for token as param * Fix identation * Check base_url format also if token is given * Update plugins/doc_fragments/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Felix Fontein <felix@fontein.de> * Allow keycloak_group.py to take token as parameter for the authentification * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Check if base_url is None before to check format * Fix unit test: rename base_url parameter to auth_keycloak_url * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Switch to modern syntax for the documentation (e.g. community.general.keycloak_client) * Add check either creds or token as argument of all keyloak_* modules * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Amin Vakil <info@aminvakil.com>
2021-04-20 13:20:46 +02:00
- name: Create a Keycloak group, authentication with credentials
community.general.keycloak_group:
2020-03-09 10:11:07 +01:00
name: my-new-kc-group
realm: MyCustomRealm
state: present
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
Allow keycloak modules to take token as parameter for the auth. (#2250) * Allow keycloak_group.py to take token as parameter for the authentification * Fix some pep8 issues * Add changelog fragment * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Fix unit test and add new one for token as param * Fix identation * Check base_url format also if token is given * Update plugins/doc_fragments/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Felix Fontein <felix@fontein.de> * Allow keycloak_group.py to take token as parameter for the authentification * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Check if base_url is None before to check format * Fix unit test: rename base_url parameter to auth_keycloak_url * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Switch to modern syntax for the documentation (e.g. community.general.keycloak_client) * Add check either creds or token as argument of all keyloak_* modules * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Amin Vakil <info@aminvakil.com>
2021-04-20 13:20:46 +02:00
- name: Create a Keycloak group, authentication with token
community.general.keycloak_group:
name: my-new-kc-group
realm: MyCustomRealm
state: present
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
token: TOKEN
delegate_to: localhost
2020-03-09 10:11:07 +01:00
- name: Delete a keycloak group
community.general.keycloak_group:
2020-03-09 10:11:07 +01:00
id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd'
state: absent
realm: MyCustomRealm
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
- name: Delete a Keycloak group based on name
community.general.keycloak_group:
2020-03-09 10:11:07 +01:00
name: my-group-for-deletion
state: absent
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
- name: Update the name of a Keycloak group
community.general.keycloak_group:
2020-03-09 10:11:07 +01:00
id: '9d59aa76-2755-48c6-b1af-beb70a82c3cd'
name: an-updated-kc-group-name
state: present
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
delegate_to: localhost
- name: Create a keycloak group with some custom attributes
community.general.keycloak_group:
2020-03-09 10:11:07 +01:00
auth_client_id: admin-cli
auth_keycloak_url: https://auth.example.com/auth
auth_realm: master
auth_username: USERNAME
auth_password: PASSWORD
name: my-new_group
attributes:
attrib1: value1
attrib2: value2
attrib3:
- with
- numerous
- individual
- list
- items
delegate_to: localhost
'''
RETURN = '''
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
msg:
description: Message as to what action was taken.
returned: always
type: str
end_state:
description: Representation of the group after module execution (sample is truncated).
returned: on success
type: complex
contains:
id:
description: GUID that identifies the group.
type: str
returned: always
sample: 23f38145-3195-462c-97e7-97041ccea73e
name:
description: Name of the group.
type: str
returned: always
sample: grp-test-123
attributes:
description: Attributes applied to this group.
type: dict
returned: always
sample:
attr1: ["val1", "val2", "val3"]
path:
description: URI path to the group.
type: str
returned: always
sample: /grp-test-123
realmRoles:
description: An array of the realm-level roles granted to this group.
type: list
returned: always
sample: []
subGroups:
description: A list of groups that are children of this group. These groups will have the same parameters as
documented here.
type: list
returned: always
clientRoles:
description: A list of client-level roles granted to this group.
type: list
returned: always
sample: []
access:
description: A dict describing the accesses you have to this group based on the credentials used.
type: dict
returned: always
sample:
manage: true
manageMembership: true
view: true
2020-03-09 10:11:07 +01:00
group:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
description:
- Representation of the group after module execution.
- Deprecated return value, it will be removed in community.general 6.0.0. Please use the return value I(end_state) instead.
2020-03-09 10:11:07 +01:00
returned: always
type: complex
contains:
id:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
description: GUID that identifies the group.
2020-03-09 10:11:07 +01:00
type: str
returned: always
sample: 23f38145-3195-462c-97e7-97041ccea73e
name:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
description: Name of the group.
2020-03-09 10:11:07 +01:00
type: str
returned: always
sample: grp-test-123
attributes:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
description: Attributes applied to this group.
2020-03-09 10:11:07 +01:00
type: dict
returned: always
sample:
attr1: ["val1", "val2", "val3"]
path:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
description: URI path to the group.
2020-03-09 10:11:07 +01:00
type: str
returned: always
sample: /grp-test-123
realmRoles:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
description: An array of the realm-level roles granted to this group.
2020-03-09 10:11:07 +01:00
type: list
returned: always
sample: []
subGroups:
description: A list of groups that are children of this group. These groups will have the same parameters as
documented here.
type: list
returned: always
clientRoles:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
description: A list of client-level roles granted to this group.
2020-03-09 10:11:07 +01:00
type: list
returned: always
sample: []
access:
description: A dict describing the accesses you have to this group based on the credentials used.
type: dict
returned: always
sample:
manage: true
manageMembership: true
view: true
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
2020-03-09 10:11:07 +01:00
'''
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
def main():
"""
Module execution
:return:
"""
argument_spec = keycloak_argument_spec()
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
2020-03-09 10:11:07 +01:00
meta_args = dict(
state=dict(default='present', choices=['present', 'absent']),
realm=dict(default='master'),
id=dict(type='str'),
name=dict(type='str'),
Allow keycloak modules to take token as parameter for the auth. (#2250) * Allow keycloak_group.py to take token as parameter for the authentification * Fix some pep8 issues * Add changelog fragment * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Fix unit test and add new one for token as param * Fix identation * Check base_url format also if token is given * Update plugins/doc_fragments/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Felix Fontein <felix@fontein.de> * Allow keycloak_group.py to take token as parameter for the authentification * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Check if base_url is None before to check format * Fix unit test: rename base_url parameter to auth_keycloak_url * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Switch to modern syntax for the documentation (e.g. community.general.keycloak_client) * Add check either creds or token as argument of all keyloak_* modules * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Amin Vakil <info@aminvakil.com>
2021-04-20 13:20:46 +02:00
attributes=dict(type='dict'),
2020-03-09 10:11:07 +01:00
)
argument_spec.update(meta_args)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True,
Allow keycloak modules to take token as parameter for the auth. (#2250) * Allow keycloak_group.py to take token as parameter for the authentification * Fix some pep8 issues * Add changelog fragment * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Fix unit test and add new one for token as param * Fix identation * Check base_url format also if token is given * Update plugins/doc_fragments/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Felix Fontein <felix@fontein.de> * Allow keycloak_group.py to take token as parameter for the authentification * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Check if base_url is None before to check format * Fix unit test: rename base_url parameter to auth_keycloak_url * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Switch to modern syntax for the documentation (e.g. community.general.keycloak_client) * Add check either creds or token as argument of all keyloak_* modules * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Amin Vakil <info@aminvakil.com>
2021-04-20 13:20:46 +02:00
required_one_of=([['id', 'name'],
['token', 'auth_realm', 'auth_username', 'auth_password']]),
required_together=([['auth_realm', 'auth_username', 'auth_password']]))
2020-03-09 10:11:07 +01:00
result = dict(changed=False, msg='', diff={}, group='')
# Obtain access token, initialize API
try:
Allow keycloak modules to take token as parameter for the auth. (#2250) * Allow keycloak_group.py to take token as parameter for the authentification * Fix some pep8 issues * Add changelog fragment * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Fix unit test and add new one for token as param * Fix identation * Check base_url format also if token is given * Update plugins/doc_fragments/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Felix Fontein <felix@fontein.de> * Allow keycloak_group.py to take token as parameter for the authentification * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Check if base_url is None before to check format * Fix unit test: rename base_url parameter to auth_keycloak_url * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Switch to modern syntax for the documentation (e.g. community.general.keycloak_client) * Add check either creds or token as argument of all keyloak_* modules * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Amin Vakil <info@aminvakil.com>
2021-04-20 13:20:46 +02:00
connection_header = get_token(module.params)
2020-03-09 10:11:07 +01:00
except KeycloakError as e:
module.fail_json(msg=str(e))
Allow keycloak modules to take token as parameter for the auth. (#2250) * Allow keycloak_group.py to take token as parameter for the authentification * Fix some pep8 issues * Add changelog fragment * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Fix unit test and add new one for token as param * Fix identation * Check base_url format also if token is given * Update plugins/doc_fragments/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Felix Fontein <felix@fontein.de> * Allow keycloak_group.py to take token as parameter for the authentification * Refactor get_token to pass module.params + Documentation * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Felix Fontein <felix@fontein.de> * Check if base_url is None before to check format * Fix unit test: rename base_url parameter to auth_keycloak_url * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update changelogs/fragments/2250-allow-keycloak-modules-to-take-token-as-param.yml Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/module_utils/identity/keycloak/keycloak.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_clienttemplate.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Update plugins/modules/identity/keycloak/keycloak_group.py Co-authored-by: Amin Vakil <info@aminvakil.com> * Switch to modern syntax for the documentation (e.g. community.general.keycloak_client) * Add check either creds or token as argument of all keyloak_* modules * Update plugins/modules/identity/keycloak/keycloak_client.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Amin Vakil <info@aminvakil.com>
2021-04-20 13:20:46 +02:00
2020-03-09 10:11:07 +01:00
kc = KeycloakAPI(module, connection_header)
realm = module.params.get('realm')
state = module.params.get('state')
gid = module.params.get('id')
name = module.params.get('name')
attributes = module.params.get('attributes')
# attributes in Keycloak have their values returned as lists
# via the API. attributes is a dict, so we'll transparently convert
# the values to lists.
if attributes is not None:
for key, val in module.params['attributes'].items():
module.params['attributes'][key] = [val] if not isinstance(val, list) else val
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# Filter and map the parameters names that apply to the group
2020-03-09 10:11:07 +01:00
group_params = [x for x in module.params
if x not in list(keycloak_argument_spec().keys()) + ['state', 'realm'] and
module.params.get(x) is not None]
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# See if it already exists in Keycloak
if gid is None:
before_group = kc.get_group_by_name(name, realm=realm)
else:
before_group = kc.get_group_by_groupid(gid, realm=realm)
if before_group is None:
before_group = {}
# Build a proposed changeset from parameters given to this module
2020-03-09 10:11:07 +01:00
changeset = {}
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
2020-03-09 10:11:07 +01:00
for param in group_params:
new_param_value = module.params.get(param)
old_value = before_group[param] if param in before_group else None
if new_param_value != old_value:
changeset[camel(param)] = new_param_value
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# Prepare the desired values using the existing values (non-existence results in a dict that is save to use as a basis)
desired_group = before_group.copy()
desired_group.update(changeset)
2020-03-09 10:11:07 +01:00
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# Cater for when it doesn't exist (an empty dict)
if not before_group:
2020-03-09 10:11:07 +01:00
if state == 'absent':
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# Do nothing and exit
2020-03-09 10:11:07 +01:00
if module._diff:
result['diff'] = dict(before='', after='')
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['changed'] = False
result['end_state'] = {}
result['group'] = result['end_state']
2020-03-09 10:11:07 +01:00
result['msg'] = 'Group does not exist; doing nothing.'
module.exit_json(**result)
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# Process a creation
2020-03-09 10:11:07 +01:00
result['changed'] = True
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
2020-03-09 10:11:07 +01:00
if name is None:
module.fail_json(msg='name must be specified when creating a new group')
if module._diff:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['diff'] = dict(before='', after=desired_group)
2020-03-09 10:11:07 +01:00
if module.check_mode:
module.exit_json(**result)
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# create it
kc.create_group(desired_group, realm=realm)
2020-03-09 10:11:07 +01:00
after_group = kc.get_group_by_name(name, realm)
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['end_state'] = after_group
result['group'] = result['end_state']
2020-03-09 10:11:07 +01:00
result['msg'] = 'Group {name} has been created with ID {id}'.format(name=after_group['name'],
id=after_group['id'])
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
module.exit_json(**result)
2020-03-09 10:11:07 +01:00
else:
if state == 'present':
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# Process an update
2020-03-09 10:11:07 +01:00
# no changes
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
if desired_group == before_group:
2020-03-09 10:11:07 +01:00
result['changed'] = False
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['end_state'] = desired_group
result['group'] = result['end_state']
2020-03-09 10:11:07 +01:00
result['msg'] = "No changes required to group {name}.".format(name=before_group['name'])
module.exit_json(**result)
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# doing an update
2020-03-09 10:11:07 +01:00
result['changed'] = True
if module._diff:
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['diff'] = dict(before=before_group, after=desired_group)
2020-03-09 10:11:07 +01:00
if module.check_mode:
module.exit_json(**result)
# do the update
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
kc.update_group(desired_group, realm=realm)
2020-03-09 10:11:07 +01:00
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
after_group = kc.get_group_by_groupid(desired_group['id'], realm=realm)
2020-03-09 10:11:07 +01:00
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['end_state'] = after_group
result['group'] = result['end_state']
2020-03-09 10:11:07 +01:00
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['msg'] = "Group {id} has been updated".format(id=after_group['id'])
2020-03-09 10:11:07 +01:00
module.exit_json(**result)
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
else:
# Process a deletion (because state was not 'present')
result['changed'] = True
2020-03-09 10:11:07 +01:00
if module._diff:
result['diff'] = dict(before=before_group, after='')
if module.check_mode:
module.exit_json(**result)
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
# delete it
2020-03-09 10:11:07 +01:00
gid = before_group['id']
kc.delete_group(groupid=gid, realm=realm)
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['end_state'] = {}
result['group'] = result['end_state']
2020-03-09 10:11:07 +01:00
Keycloak module cleanup and consistency (#3280) * Consistent Modules - Rename updated_?? to desired_?? in all the keycloak modules. * Consistent Modules - Rename the comments, and add whitespace so that all the modules are a lot more consistent between each other. * Consistent Modules - Remove final elif where a final else doesn't exist. This is to address the inconsistency between the other modules. Whilst I can see it being more descriptive, there should be a final "else:" to cater if the values is neither 'absent' or 'present'. * Consistent Modules - Use dict() instead of {} like most of the other keycloak modules. * Consistent Modules - Update keycloak authentication so that the if ordering is consistent for no-item. * Consistent Modules - Move the 'Filter and map' process to always occur before getting an existing item. * Consistent Modules - Be consistent with how to initialse before_?? and set it to dict() if it is None. * Consistent Modules - Add module.exit_?? in the locations as per the other modules. * Consistent Modules - Represent result['diff'] using dict(before=.., after=...) as per all the other modules. * Consistent Modules - Add / Move location of when result['end_state'] is getting defined. * Consistent modules - Add result['changed'] = False where we do nothing and exit because item exists. * Consistent Modules - Set the value result['changed'] to True earlier so it shows up when in checking mode only. * Consistent Modules - test for equality with a dict to assert there was no realm in the first place as per the other modules. * Consistent Modules - Address the spelling. * Consistent Modules - keycloak_group - Remove result['group'] as result['end_state'] is the consistent value used in the other modules. * Consistent Modules - Order the lines in the section, Do nothing and exit consistently. * Consistent Modules - Add result['end_state'] and still add deprecated `flow` return value. * Consistent Modules - Add missing return documentation for `msg`. * Consistent Modules - Tweak whitespace in the RETURN variable. * Consistent Modules - Add result['group'] in addition to deprecated result['group'] response. * Consistent Modules - Add return property, 'contains' to address test errors. * Consistent Modules - Rename updated_?? to desired_?? in new modules since initial PR. * Consistent Modules - Rename the comments, and add whitespace so that all the (recently added) modules are a lot more consistent between each other. * Consistent Modules - Make indentation consistent within the response document. * Consistent Modules - Use B(DEPRECATED) in a seperate line in the description. * Consistent Modules - Add a lot of full stops to sentences. * Consistent Modules - Use C(...) and I(...) formatting methods. * Consistent Modules - Use "on success" everywhere for end_state response documentation. * Consistent Modules - Update the documents for RETURN.proposed, RETURN.existing, RETURN.end_state to be the same. * Consistent Modules - Add fragment. * Remove period after short_description. * Update changelog fragment. * Consistent Modules - PRFeedback - Remove `module.exit_json(**result)` within the `Delete` section of the if statement. There's a exit_json(..) immediately after. * Consistent Modules - PRFeedback - Use `if not x_repr` instead of `if x_repr == dict()`. * keycloak_authentication - Add a sample of the output. * Replace `dict()` with `{}` for all the keycloak modules. * Add the requested deprecated notices * Update changelogs/fragments/3280-keycloak-module-cleanup-and-consistency.yml Co-authored-by: Pierre Dumuid <pierre@knowyourdata.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-10-22 07:57:18 +02:00
result['msg'] = "Group {name} has been deleted".format(name=before_group['name'])
2020-03-09 10:11:07 +01:00
module.exit_json(**result)
if __name__ == '__main__':
main()