mayope / keycloakmigration

Manage your Keycloak configuration with code.
https://mayope.net
MIT License
108 stars 22 forks source link

Preconditions for changesets #9

Closed mthiele closed 4 years ago

mthiele commented 4 years ago

I would like to propose an addition to the changeset specification to allow changes to be only executed if a certain criteria/precondition is met. Something similar can be found in Liquibase (https://docs.liquibase.com/concepts/advanced/preconditions.html). A simpler version would be sufficient.

My scenario: I want to create a user for end-to-end tests that should not be present in the migration for the keycloak that will run in production. Thus, something like this would suffice:

changes:
  - precondition: ${E2E} == 'true'
  - addUser:
      name: e2e
  - updateUser:
     ...
klg71 commented 4 years ago

I fear that such a preconditions evaluation:

changes:
  - precondition: ${E2E} == 'true'
  - addUser:
      name: e2e
  - updateUser:
     ...

Will take a while to implement. As far as i know there is no simple library that provides such features. My proposal would be to implement an enabled flag either per action or for the whole changeset. This enabled flag can than be set through parameter substitution allowing a dynamic toggle of changes.

id: initial-keycloak
author: klg71
realm: master
enabled: ${INTIAL_KEYCLOAK_ENABLED} # Either here
changes:
- addUser:
    actionEnabled:  ${INTIAL_KEYCLOAK_ENABLED} # or per action
    name: test
    enabled: true
    emailVerified: true
    attributes:
      test:
      - test
      - test2
...
klg71 commented 4 years ago

@mthiele can you review the proposed solution?

mthiele commented 4 years ago

Code and solution looks good to me. Please merge.

klg71 commented 4 years ago

Reopen because it is not released yet

klg71 commented 4 years ago

Released with version 0.1.31. Thanks for the issue @mthiele and code provided @sideisra! Will close this if no further requests occur.