ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
833 stars 1.53k forks source link

[PR #8940/c814fd05 backport][stable-9] keycloak_userprofile: improve diff by deserializing fetched `kc.user.profile.config` and serializing it before sending #9002

Closed patchback[bot] closed 1 month ago

patchback[bot] commented 1 month ago

This is a backport of PR #8940 as merged into main (c814fd0530f00138f385ff25d18782729a7d5469).

SUMMARY

Keycloak returns a single JSON formatted string for the kc.user.profile.config which cant be diffed properly.

--- before
+++ after
@@ -1,7 +1,7 @@
 {
     "config": {
         "kc.user.profile.config": [
-            "{\"attributes\": [{\"name\": \"username\", \"displayName\": \"${username}\", \"validations\": {\"length\": {\"min\": 3, \"max\": 255}, \"username-prohibited-characters\": {}, \"up-username-not-idn-homograph\": {}}, \"annotations\": {}, \"permissions\": {\"view\": [\"********\", \"user\"], \"edit\": []}, \"multivalued\": false}, {\"name\": \"email\", \"displayName\": \"${email}\", \"validations\": {\"email\": {}, \"length\": {\"max\": 255}}, \"annotations\": {}, \"required\": {\"roles\": [\"user\"]}, \"permissions\": {\"view\": [\"********\", \"user\"], \"edit\": []}, \"multivalued\": false}], \"groups\": []}"
+            "{\"attributes\": [{\"name\": \"username\", \"displayName\": \"${username}\", \"validations\": {\"length\": {\"min\": 3, \"max\": 255}, \"username-prohibited-characters\": {}, \"up-username-not-idn-homograph\": {}}, \"annotations\": {}, \"permissions\": {\"view\": [\"********\", \"user\"], \"edit\": []}, \"multivalued\": false}, {\"name\": \"email\", \"displayName\": \"${email}\", \"validations\": {\"email\": {}, \"length\": {\"max\": 255}}, \"annotations\": {}, \"required\": {\"roles\": [\"user\"]}, \"permissions\": {\"view\": [\"********\", \"user\"], \"edit\": []}, \"multivalued\": false}], \"groups\": [{\"name\": \"user-metadata\", \"displayHeader\": \"User metadata\", \"displayDescription\": \"Attributes, which refer to user metadata\"}]}"
         ]
     },
     "id": "fd55b673-e34a-44b6-96f3-11531bead097",

changed: [kc1]

Deserializing the string after fetching the userprofile component and serializing only when sending it back to the Keycloak API would allow a finer grained diff.

--- before
+++ after
@@ -49,7 +49,13 @@
                         }
                     }
                 ],
-                "groups": []
+                "groups": [
+                    {
+                        "displayDescription": "Attributes, which refer to user metadata",
+                        "displayHeader": "User metadata",
+                        "name": "user-metadata"
+                    }
+                ]
             }
         ]
     },

changed: [kc1]
ISSUE TYPE
COMPONENT NAME

keycloak_userprofile

ansibullbot commented 1 month ago

cc @eikef @mattock @ndclt @thomasbach-dev @yeoldegrove click here for bot help