community.general icon indicating copy to clipboard operation
community.general copied to clipboard

New Module: Keycloak User Rolemapping

Open bratwurzt opened this issue 2 years ago • 11 comments

SUMMARY

Add keycloak_user_rolemapping module to provide management of direct assignment of client/realm roles to users. Also provides user role mapping for service-account users.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

keycloak_user_rolemapping

ADDITIONAL INFORMATION

Example:

- name: Map a client role to a user, authentication with credentials
  community.general.keycloak_user_rolemapping:
    realm: MyCustomRealm
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    state: present
    client_id: client1
    user_id: user1Id
    roles:
      - name: role_name1
        id: role_id1
      - name: role_name2
        id: role_id2
  delegate_to: localhost

- name: Map a client role to a service account user for a client, authentication with credentials
  community.general.keycloak_user_rolemapping:
    realm: MyCustomRealm
    auth_client_id: admin-cli
    auth_keycloak_url: https://auth.example.com/auth
    auth_realm: master
    auth_username: USERNAME
    auth_password: PASSWORD
    state: present
    client_id: client1
    service_account_user_client_id: clientIdOfServiceAccount
    roles:
      - name: role_name1
        id: role_id1
      - name: role_name2
        id: role_id2
  delegate_to: localhost

bratwurzt avatar Jun 28 '22 12:06 bratwurzt

@bratwurzt this PR contains the following merge commits:

  • https://github.com/ansible-collections/community.general/commit/2b2ba7e349d7f65026041a4728dd88dfbe9df6b1

Please rebase your branch to remove these commits.

click here for bot help

ansibullbot avatar Jun 28 '22 12:06 ansibullbot

The test ansible-test sanity --test pep8 [explain] failed with 5 errors:

plugins/module_utils/identity/keycloak/keycloak.py:574:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:647:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:668:5: E303: too many blank lines (2)
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:71:73: W291: trailing whitespace
tests/unit/plugins/modules/identity/keycloak/test_keycloak_client_rolemapping.py:59:161: E501: line too long (174 > 160 characters)

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got ['Dušan Marković']
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

The test ansible-test sanity --test pep8 [explain] failed with 5 errors:

plugins/module_utils/identity/keycloak/keycloak.py:574:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:647:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:668:5: E303: too many blank lines (2)
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:71:73: W291: trailing whitespace
tests/unit/plugins/modules/identity/keycloak/test_keycloak_client_rolemapping.py:59:161: E501: line too long (174 > 160 characters)

The test ansible-test sanity --test pep8 [explain] failed with 5 errors:

plugins/module_utils/identity/keycloak/keycloak.py:574:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:647:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:668:5: E303: too many blank lines (2)
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:71:73: W291: trailing whitespace
tests/unit/plugins/modules/identity/keycloak/test_keycloak_client_rolemapping.py:59:161: E501: line too long (174 > 160 characters)

The test ansible-test sanity --test pep8 [explain] failed with 5 errors:

plugins/module_utils/identity/keycloak/keycloak.py:574:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:647:5: E303: too many blank lines (2)
plugins/module_utils/identity/keycloak/keycloak.py:668:5: E303: too many blank lines (2)
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:71:73: W291: trailing whitespace
tests/unit/plugins/modules/identity/keycloak/test_keycloak_client_rolemapping.py:59:161: E501: line too long (174 > 160 characters)

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got ['Dušan Marković']
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got ['Dušan Marković']
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got ['Dušan Marković']
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

click here for bot help

ansibullbot avatar Jun 28 '22 12:06 ansibullbot

@bratwurzt This PR was evaluated as a potentially problematic PR for the following reasons:

  • More than 50 changed files.

Such PR can only be merged by human. Contact a Core team member to review this PR on IRC: #ansible-devel on Libera.chat IRC

click here for bot help

ansibullbot avatar Jun 29 '22 12:06 ansibullbot

@bratwurzt this PR contains the following merge commits:

  • https://github.com/ansible-collections/community.general/commit/bb23ad0386bef1568c3ab788a0dbfeec75f79658

Please rebase your branch to remove these commits.

click here for bot help

ansibullbot avatar Jun 29 '22 12:06 ansibullbot

cc @Gaetan2907 @eikef @ndclt click here for bot help

ansibullbot avatar Jun 29 '22 12:06 ansibullbot

The test botmeta failed with 1 error:

.github/BOTMETA.yml:0:0: Entry plugins/modules/identity/keycloak/keycloak_role_composites.py was not used

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/module_utils/identity/keycloak/keycloak.py:696:41: undefined-variable: Undefined variable 'cid'

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:792:47: E127: continuation line over-indented for visual indent
plugins/module_utils/identity/keycloak/keycloak.py:810:43: E127: continuation line over-indented for visual indent

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:792:47: E127: continuation line over-indented for visual indent
plugins/module_utils/identity/keycloak/keycloak.py:810:43: E127: continuation line over-indented for visual indent

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:792:47: E127: continuation line over-indented for visual indent
plugins/module_utils/identity/keycloak/keycloak.py:810:43: E127: continuation line over-indented for visual indent

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/module_utils/identity/keycloak/keycloak.py:696:41: undefined-variable: Undefined variable 'cid'

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:792:47: E127: continuation line over-indented for visual indent
plugins/module_utils/identity/keycloak/keycloak.py:810:43: E127: continuation line over-indented for visual indent

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/module_utils/identity/keycloak/keycloak.py:696:41: undefined-variable: Undefined variable 'cid'

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: parameter-documented-multiple-times: Argument 'auth_username' in argument_spec with aliases 'username' is documented multiple times, namely as 'auth_username', 'username'

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/module_utils/identity/keycloak/keycloak.py:696:41: undefined-variable: Undefined variable 'cid'

click here for bot help

ansibullbot avatar Jun 29 '22 15:06 ansibullbot

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

github-actions[bot] avatar Jun 30 '22 08:06 github-actions[bot]

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:259:161: E501: line too long (167 > 160 characters)

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:259:161: E501: line too long (167 > 160 characters)

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:259:161: E501: line too long (167 > 160 characters)

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:259:161: E501: line too long (167 > 160 characters)

click here for bot help

ansibullbot avatar Jun 30 '22 08:06 ansibullbot

Could anyone help out on parameter naming? I'm quite bad at that.

bratwurzt avatar Jul 01 '22 07:07 bratwurzt

@bratwurzt this PR contains the following merge commits:

  • https://github.com/ansible-collections/community.general/commit/2c6d066fe13ef519f709e9b77da89cfeca884298

Please rebase your branch to remove these commits.

click here for bot help

ansibullbot avatar Aug 02 '22 11:08 ansibullbot

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:809:21: E117: over-indented
plugins/module_utils/identity/keycloak/keycloak.py:827:21: E117: over-indented

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:809:21: E117: over-indented
plugins/module_utils/identity/keycloak/keycloak.py:827:21: E117: over-indented

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:809:21: E117: over-indented
plugins/module_utils/identity/keycloak/keycloak.py:827:21: E117: over-indented

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

plugins/module_utils/identity/keycloak/keycloak.py:809:21: E117: over-indented
plugins/module_utils/identity/keycloak/keycloak.py:827:21: E117: over-indented

click here for bot help

ansibullbot avatar Aug 02 '22 12:08 ansibullbot

The test licenses failed with 8 errors:

tests/integration/targets/keycloak_user_rolemapping/aliases:0:0: found copyright line with "Copyright:". Please remove the colon.
tests/integration/targets/keycloak_user_rolemapping/aliases:0:0: found no copyright notice
tests/integration/targets/keycloak_user_rolemapping/tasks/main.yml:0:0: found copyright line with "Copyright:". Please remove the colon.
tests/integration/targets/keycloak_user_rolemapping/tasks/main.yml:0:0: found no copyright notice
tests/integration/targets/keycloak_user_rolemapping/vars/main.yml:0:0: found copyright line with "Copyright:". Please remove the colon.
tests/integration/targets/keycloak_user_rolemapping/vars/main.yml:0:0: found no copyright notice
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: found copyright line with "Copyright:". Please remove the colon.
plugins/modules/identity/keycloak/keycloak_user_rolemapping.py:0:0: found no copyright notice

click here for bot help

ansibullbot avatar Sep 18 '22 09:09 ansibullbot

Backport to stable-5: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-5/2cac3ae879172c59149637a80c4597b1a2e156de/pr-4898

Backported as https://github.com/ansible-collections/community.general/pull/5324

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

patchback[bot] avatar Oct 01 '22 16:10 patchback[bot]

@bratwurzt thanks a lot for your contribution, and sorry that it took so long to get it merged!

felixfontein avatar Oct 01 '22 16:10 felixfontein

@bratwurzt thanks a lot for your contribution, and sorry that it took so long to get it merged!

No worries, glad I could contribute.

bratwurzt avatar Oct 28 '22 11:10 bratwurzt