feat(Keycloak): Support admin bootstrapping for version 26 onwards#1400
Merged
HofmeisterAn merged 1 commit intotestcontainers:developfrom Mar 14, 2025
Merged
Conversation
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
54b9c9b to
6b5a5dc
Compare
Collaborator
HofmeisterAn
left a comment
There was a problem hiding this comment.
Why don't you simply use the following approach? If the environment variables are not supported by one of the version, they will be ignored.
diff --git a/src/Testcontainers.Keycloak/KeycloakBuilder.cs b/src/Testcontainers.Keycloak/KeycloakBuilder.cs
index 1f255cd..5116e15 100644
--- a/src/Testcontainers.Keycloak/KeycloakBuilder.cs
+++ b/src/Testcontainers.Keycloak/KeycloakBuilder.cs
@@ -44,6 +44,9 @@ public sealed class KeycloakBuilder : ContainerBuilder<KeycloakBuilder, Keycloak
public KeycloakBuilder WithUsername(string username)
{
return Merge(DockerResourceConfiguration, new KeycloakConfiguration(username: username))
+ .WithEnvironment("KC_BOOTSTRAP_ADMIN_USERNAME", username)
+ // From version 26 onwards, the environment variables are obsolete:
+ // https://www.keycloak.org/docs/26.0.0/upgrading/#admin-bootstrapping-and-recovery.
.WithEnvironment("KEYCLOAK_ADMIN", username);
}
@@ -55,6 +58,9 @@ public sealed class KeycloakBuilder : ContainerBuilder<KeycloakBuilder, Keycloak
public KeycloakBuilder WithPassword(string password)
{
return Merge(DockerResourceConfiguration, new KeycloakConfiguration(password: password))
+ .WithEnvironment("KC_BOOTSTRAP_ADMIN_PASSWORD", password)
+ // From version 26 onwards, the environment variables are obsolete:
+ // https://www.keycloak.org/docs/26.0.0/upgrading/#admin-bootstrapping-and-recovery.
.WithEnvironment("KEYCLOAK_ADMIN_PASSWORD", password);
}
Contributor
Author
|
I'm fine with that, if you are. |
Collaborator
|
As long as it works, I prefer this approach for its simplicity. I assume that if the deprecated environment variables are removed, Keycloak will simply ignore them. |
- Added private fields for username and password in KeycloakBuilder. - Modified Build method to handle environment variables based on Keycloak version. - Simplified wait strategy logic. - Introduced KeycloakV26Configuration for testing with Keycloak version 26.
6b5a5dc to
cccacf9
Compare
Contributor
Author
|
Done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
From https://www.keycloak.org/docs/26.0.0/upgrading/#admin-bootstrapping-and-recovery
Why is it important?
Keep up to date with Keycloak.
Related issues