Repository navigation
Add env package for testable environment variable access - #3
Merged
Merged
Conversation
Graduate the env package from toolhive to toolhive-core as the first Tier 1 package per THV-0032 RFC. This package provides: - Reader interface for environment variable access - OSReader implementation using the standard os package - Mock implementation for testing The package has zero dependencies on ToolHive internals and uses only the standard library, making it ideal for the first graduation. Co-Authored-By: Claude Opus 4.5 <[email protected]>
jhrozek
approved these changes
Feb 2, 2026
11 tasks
reyortiz3
added a commit
that referenced
this pull request
Sep 2, 2026
Follow-up from PR #265 review (ChrisJBurns): oauth2.TokenSource.Token() takes no context, so a caller-provided context was previously ignored entirely once past construction — canceling or timing out a connection attempt would not cancel a stalled token refresh. Add a tokenWithContext helper that races Token() against ctx.Done() so the caller unblocks promptly on cancellation (the underlying call itself can't be aborted through this interface, so it keeps running in the background until it completes on its own). Also apply the redis package's context.Background()-for-construction fix (PR #265, finding #3) to postgres/gcpiam.go, which had the same latent bug: gcpCloudSQLIAMBeforeConnect built its token source from the pool-construction context instead of a background one, so a canceled construction context could poison every later refresh. Co-Authored-By: Claude Sonnet 5 <[email protected]>
reyortiz3
added a commit
that referenced
this pull request
Sep 3, 2026
) * postgres: add Azure AD and GCP Cloud SQL IAM dynamic-auth backends Adds two dynamic-auth backends alongside the existing AWS RDS IAM one, plus generalizes the backend-dispatch plumbing to support three (and future) backends cleanly instead of a single hardcoded check. - DynamicAuthAzureAD: Entra ID (formerly Azure AD) tokens for Azure Database for PostgreSQL, via azidentity.DefaultAzureCredential's normal resolution chain (env vars, workload identity, managed identity, Azure CLI). Construction is credential-free (lazy resolution deferred to GetToken), so it's unit-tested the same way the AWS backend is. - DynamicAuthGCPCloudSQLIAM: OAuth2 tokens for GCP Cloud SQL IAM database authentication, minted from ambient Application Default Credentials. This is the direct-TCP token-swap path, not the Cloud SQL Go connector (cloudsqlconn) — it requires the instance to have a reachable IP and does not get Cloud SQL's automatic mTLS tunnel; that's a deliberately separate, larger piece of work (a DialFunc-based extension point, not a BeforeConnect password swap), tracked in #261 as a follow-up. Unlike AWS/Azure, google.DefaultTokenSource resolves credentials eagerly rather than lazily, so its outcome is environment-dependent — this backend has no invocation-level unit test, and the comment at the bottom of azuread_test.go explains why, rather than silently omitting it. - Config.Validate, NewAuthToken, and NewDynamicAuthFunc's per-backend dispatch is generalized via singleDynamicAuthBackend/ countDynamicAuthBackends, which also newly rejects a config with more than one backend set (previously unreachable with only one backend to choose from). Closes #261. * postgres,redis: honor per-call context cancellation in GCP token refresh Follow-up from PR #265 review (ChrisJBurns): oauth2.TokenSource.Token() takes no context, so a caller-provided context was previously ignored entirely once past construction — canceling or timing out a connection attempt would not cancel a stalled token refresh. Add a tokenWithContext helper that races Token() against ctx.Done() so the caller unblocks promptly on cancellation (the underlying call itself can't be aborted through this interface, so it keeps running in the background until it completes on its own). Also apply the redis package's context.Background()-for-construction fix (PR #265, finding #3) to postgres/gcpiam.go, which had the same latent bug: gcpCloudSQLIAMBeforeConnect built its token source from the pool-construction context instead of a background one, so a canceled construction context could poison every later refresh. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
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.
Summary
envpackage from toolhive as the first Tier 1 package per THV-0032 RFCReaderinterface for dependency injection and testing isolationOSReaderimplementation using standard libraryospackageTest plan
task lintpassestask license-checkpassestask testpasses with race detectionNotes
This is the first package graduation to toolhive-core. The
envpackage was chosen because:ospackage)🤖 Generated with Claude Code