From a15ec281697be05b0f170cb550e7e3bdfc86826e Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 22 Dec 2025 11:13:57 +0100 Subject: [PATCH] [PR #11285/a55884c9 backport][stable-12] Add support for missing validations in keycloak_userprofile (#11302) Add support for missing validations in keycloak_userprofile (#11285) * add missing validations-parameters as config options and add documentation for them; fixes https://github.com/ansible-collections/community.general/issues/9048 * fix parameter names * extend unit tests * support for camel casing for new validations and add changelog fragment * Fix fragment format * add 'version_added' documentation * Update changelogs/fragments/11285-extended-keycloak-user-profile-validations.yml mention fixed issue in fragment * fix ruff formatting --------- (cherry picked from commit a55884c921db714453db86cdd340b5c343028323) Co-authored-by: nwintering <33374766+nwintering@users.noreply.github.com> Co-authored-by: Felix Fontein --- ...nded-keycloak-user-profile-validations.yml | 3 + plugins/modules/keycloak_userprofile.py | 77 +++++++++++ .../modules/test_keycloak_userprofile.py | 125 ++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 changelogs/fragments/11285-extended-keycloak-user-profile-validations.yml diff --git a/changelogs/fragments/11285-extended-keycloak-user-profile-validations.yml b/changelogs/fragments/11285-extended-keycloak-user-profile-validations.yml new file mode 100644 index 0000000000..0a4b8f951a --- /dev/null +++ b/changelogs/fragments/11285-extended-keycloak-user-profile-validations.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - keycloak_userprofile - add support for additional user profile attribute-validations available in Keycloak (https://github.com/ansible-collections/community.general/issues/9048, https://github.com/ansible-collections/community.general/pull/11285). diff --git a/plugins/modules/keycloak_userprofile.py b/plugins/modules/keycloak_userprofile.py index 7664d77ea2..bb620b0aed 100644 --- a/plugins/modules/keycloak_userprofile.py +++ b/plugins/modules/keycloak_userprofile.py @@ -160,6 +160,50 @@ options: - Validation to ensure the attribute matches one of the provided options. type: dict + integer: + description: + - The integer validation for the attribute. + type: dict + version_added: 12.2.0 + + double: + description: + - The double validation for the attribute. + type: dict + version_added: 12.2.0 + + iso_date: + description: + - The iso-date validation for the attribute. + type: dict + aliases: + - isoDate + version_added: 12.2.0 + + local_date: + description: + - The local-date validation for the attribute. + type: dict + aliases: + - localDate + version_added: 12.2.0 + + multivalued: + description: + - The multivalued validation for the attribute. + type: dict + suboptions: + min: + description: + - The minimum amount of values of the attribute. + type: int + max: + description: + - The maximum amount of values of the attribute. + type: int + required: true + version_added: 12.2.0 + annotations: description: - Annotations for the attribute. @@ -341,6 +385,22 @@ EXAMPLES = r""" - user edit: [] multivalued: false + - name: testAttribute + displayName: ${testAttribute} + validations: + integer: + min: 0 + max: 255 + annotations: {} + required: + roles: + - user + permissions: + view: + - admin + - user + edit: [] + multivalued: false groups: - name: user-metadata displayHeader: User metadata @@ -488,6 +548,17 @@ def main(): "uri": dict(type="dict"), "pattern": dict(type="dict"), "options": dict(type="dict"), + "integer": dict(type="dict"), + "double": dict(type="dict"), + "iso_date": dict(type="dict", aliases=["isoDate"]), + "local_date": dict(type="dict", aliases=["localDate"]), + "multivalued": dict( + type="dict", + options={ + "min": dict(type="int", required=False), + "max": dict(type="int", required=True), + }, + ), }, ), "annotations": dict(type="dict"), @@ -610,6 +681,12 @@ def main(): attribute["validations"]["person-name-prohibited-characters"] = attribute[ "validations" ].pop("personNameProhibitedCharacters") + if "isoDate" in attribute["validations"]: + attribute["validations"]["iso-date"] = attribute["validations"].pop("isoDate") + if "localDate" in attribute["validations"]: + attribute["validations"]["local-date"] = attribute["validations"].pop( + "localDate" + ) changeset[camel(component_param)][config_param].append(kc_user_profile_config[0]) # usual camelCase parameters else: diff --git a/tests/unit/plugins/modules/test_keycloak_userprofile.py b/tests/unit/plugins/modules/test_keycloak_userprofile.py index 7032a2a18d..c6b66a5e0d 100644 --- a/tests/unit/plugins/modules/test_keycloak_userprofile.py +++ b/tests/unit/plugins/modules/test_keycloak_userprofile.py @@ -148,6 +148,31 @@ class TestKeycloakUserprofile(ModuleTestCase): "required": {"roles": ["user"]}, "validations": {"length": {"max": 255}, "person_name_prohibited_characters": {}}, }, + { + "annotations": {}, + "displayName": "${testAttr}", + "multivalued": False, + "name": "testAttr", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "integer": {"min": 0, "max": 255}, + "double": {}, + "iso_date": {}, + "local_date": {}, + }, + }, + { + "annotations": {}, + "displayName": "${testAttr2}", + "multivalued": True, + "name": "testAttr2", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "multivalued": {"min": 0, "max": 5}, + }, + }, ], "groups": [ { @@ -210,6 +235,31 @@ class TestKeycloakUserprofile(ModuleTestCase): "multivalued": False, "annotations": {}, }, + { + "annotations": {}, + "displayName": "${testAttr}", + "multivalued": False, + "name": "testAttr", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "integer": {"min": 0, "max": 255}, + "double": {}, + "iso_date": {}, + "local_date": {}, + }, + }, + { + "annotations": {}, + "displayName": "${testAttr2}", + "multivalued": True, + "name": "testAttr2", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "multivalued": {"min": 0, "max": 5}, + }, + }, ], "groups": [ { @@ -306,6 +356,31 @@ class TestKeycloakUserprofile(ModuleTestCase): "required": {"roles": ["user"]}, "validations": {"length": {"max": 255}, "person_name_prohibited_characters": {}}, }, + { + "annotations": {}, + "displayName": "${testAttr}", + "multivalued": False, + "name": "testAttr", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "integer": {"min": 0, "max": 255}, + "double": {}, + "iso_date": {}, + "local_date": {}, + }, + }, + { + "annotations": {}, + "displayName": "${testAttr2}", + "multivalued": True, + "name": "testAttr2", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "multivalued": {"min": 0, "max": 5}, + }, + }, ], "groups": [ { @@ -376,6 +451,31 @@ class TestKeycloakUserprofile(ModuleTestCase): "multivalued": False, "annotations": {}, }, + { + "annotations": {}, + "displayName": "${testAttr}", + "multivalued": False, + "name": "testAttr", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "integer": {"min": 0, "max": 255}, + "double": {}, + "iso_date": {}, + "local_date": {}, + }, + }, + { + "annotations": {}, + "displayName": "${testAttr2}", + "multivalued": True, + "name": "testAttr2", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "multivalued": {"min": 0, "max": 5}, + }, + }, ], "groups": [ { @@ -528,6 +628,31 @@ class TestKeycloakUserprofile(ModuleTestCase): "multivalued": False, "annotations": {}, }, + { + "annotations": {}, + "displayName": "${testAttr}", + "multivalued": False, + "name": "testAttr", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "integer": {"min": 0, "max": 255}, + "double": {}, + "iso_date": {}, + "local_date": {}, + }, + }, + { + "annotations": {}, + "displayName": "${testAttr2}", + "multivalued": True, + "name": "testAttr2", + "permissions": {"edit": ["admin", "user"], "view": ["admin", "user"]}, + "required": {"roles": ["user"]}, + "validations": { + "multivalued": {"min": 0, "max": 5}, + }, + }, ], "groups": [ {