Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keycloak_userprofile: fix empty response by removing parent filter when fetching userprofile component #8923

Conversation

fgruenbauer
Copy link
Contributor

SUMMARY

The module filters the components by parent=parent_id (and type). The same variable parent_id is also used as the realm argument for the get_components call.

realm_userprofiles = kc.get_components(urlencode(dict(type=provider_type, parent=parent_id)), parent_id)

def get_components(self, filter=None, realm='master'):

The parent filter expects the ID of the parent realm (usually a uuid) whereas the realm argument requires the name of a realm ('master' for example). So unless the ID and the name of realm are identical the returned list is empty.

--- before
+++ after
@@ -1 +1,9 @@
-{}
+{
+    "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\": {}
[...]

Since the components are already filtered by realm with realm=parent_id, i think the filter parent=parent_id can be removed.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION
  1. create a realm
  2. run module normally (keycloak seems to return an empty list if the default profile has not been updated, creating a user profile should work)
  3. rerun in check or normal mode -> should always show empty before dict and update not working

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) labels Sep 25, 2024
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch labels Sep 25, 2024
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

…nse-when-fetching-userprofile.yml

Co-authored-by: Felix Fontein <felix@fontein.de>
@felixfontein
Copy link
Collaborator

If nobody objects I'll merge this in a week.

@felixfontein felixfontein merged commit 83080cc into ansible-collections:main Oct 2, 2024
150 checks passed
Copy link

patchback bot commented Oct 2, 2024

Backport to stable-8: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 83080cc on top of patchback/backports/stable-8/83080cc0054b62c0c4624e66ce4501cf14fc0b21/pr-8923

Backporting merged PR #8923 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/ansible-collections/community.general.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-8/83080cc0054b62c0c4624e66ce4501cf14fc0b21/pr-8923 upstream/stable-8
  4. Now, cherry-pick PR keycloak_userprofile: fix empty response by removing parent filter when fetching userprofile component #8923 contents into that branch:
    $ git cherry-pick -x 83080cc0054b62c0c4624e66ce4501cf14fc0b21
    If it'll yell at you with something like fatal: Commit 83080cc0054b62c0c4624e66ce4501cf14fc0b21 is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 83080cc0054b62c0c4624e66ce4501cf14fc0b21
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR keycloak_userprofile: fix empty response by removing parent filter when fetching userprofile component #8923 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-8/83080cc0054b62c0c4624e66ce4501cf14fc0b21/pr-8923
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Oct 2, 2024
Copy link

patchback bot commented Oct 2, 2024

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/83080cc0054b62c0c4624e66ce4501cf14fc0b21/pr-8923

Backported as #8960

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein
Copy link
Collaborator

@fgruenbauer thanks for your contribution!

patchback bot pushed a commit that referenced this pull request Oct 2, 2024
…when fetching userprofile component (#8923)

* remove parent filter when fetching userprofile component

* add changelog fragment

* Update changelogs/fragments/8923-keycloak_userprofile-fix-empty-response-when-fetching-userprofile.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 83080cc)
felixfontein pushed a commit that referenced this pull request Oct 2, 2024
…y response by removing `parent` filter when fetching userprofile component (#8960)

keycloak_userprofile: fix empty response by removing `parent` filter when fetching userprofile component (#8923)

* remove parent filter when fetching userprofile component

* add changelog fragment

* Update changelogs/fragments/8923-keycloak_userprofile-fix-empty-response-when-fetching-userprofile.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 83080cc)

Co-authored-by: fgruenbauer <gruenbauer@b1-systems.de>
Massl123 pushed a commit to Massl123/community.general that referenced this pull request Feb 7, 2025
…when fetching userprofile component (ansible-collections#8923)

* remove parent filter when fetching userprofile component

* add changelog fragment

* Update changelogs/fragments/8923-keycloak_userprofile-fix-empty-response-when-fetching-userprofile.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch bug This issue/PR relates to a bug module module plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants