Skip to content

Use DatabaseName for Keycloak Postgres JDBC URL#1328

Merged
aaronpowell merged 2 commits into
CommunityToolkit:mainfrom
ekomsctr:fix_keycloak_jdbcurl_databasename
May 22, 2026
Merged

Use DatabaseName for Keycloak Postgres JDBC URL#1328
aaronpowell merged 2 commits into
CommunityToolkit:mainfrom
ekomsctr:fix_keycloak_jdbcurl_databasename

Conversation

@ekomsctr

Copy link
Copy Markdown
Contributor

**Closes #1327 **

Updated KeycloakPostgresExtension to use the database resource's DatabaseName property instead of Name when building the JDBC connection string. This ensures the correct database name is used, especially when the resource name and actual database name differ.

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • New integration
    • Docs are written
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Breaking changes (?)

I don't really know if this is considered a breaking change, but i guess existing environments that persists the database somehow (i.e. deployed or persistent volumes) could have their connections broken if the database name is not updated to reflect the change?

ekomsctr added 2 commits May 19, 2026 20:32
Updated KeycloakPostgresExtension to use the database resource's DatabaseName property instead of Name when building the JDBC connection string. This ensures the correct database name is used, especially when the resource name and actual database name differ.
Adds a test to verify that Keycloak integration with a Postgres resource correctly applies environment variables when a custom database name is used. The test checks that KC_DB and KC_DB_URL are set as expected and that the database URL ends with the custom name.
Copilot AI review requested due to automatic review settings May 19, 2026 18:45
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.sh | bash -s -- 1328

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.ps1) } 1328"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a bug in KeycloakPostgresExtension where the JDBC connection string used the Aspire resource name instead of the actual Postgres database name, causing Keycloak to fail when connecting to a database whose name differs from its resource name.

Changes:

  • Replace database.Resource.Name with database.Resource.DatabaseName when building the JDBC URL.
  • Add an integration test verifying the JDBC URL ends with the custom database name.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/CommunityToolkit.Aspire.Hosting.Keycloak.Extensions/KeycloakPostgresExtension.cs Use DatabaseName instead of Name for the JDBC URL path segment.
tests/CommunityToolkit.Aspire.Hosting.Keycloak.Extensions.Tests/KeycloakWithPostgresIntegrationTest.cs New integration test asserting the JDBC URL uses the custom database name.

@ekomsctr

Copy link
Copy Markdown
Contributor Author

@ekomsctr please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

@aaronpowell aaronpowell enabled auto-merge (squash) May 22, 2026 06:26
@aaronpowell aaronpowell merged commit 19bb168 into CommunityToolkit:main May 22, 2026
122 of 131 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeycloakPostgresExtension.WithPostgresData does not respect custom database name and always use resource name

3 participants