Skip to content

Add env package for testable environment variable access - #3

Merged
JAORMX merged 1 commit into
mainfrom
add-env-package
Feb 2, 2026
Merged

JAORMX merged 1 commit into
mainfrom
add-env-package

Conversation

@JAORMX

@JAORMX JAORMX commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Graduate the env package from toolhive as the first Tier 1 package per THV-0032 RFC
  • Provides Reader interface for dependency injection and testing isolation
  • Includes OSReader implementation using standard library os package
  • Includes generated mock for testing

Test plan

  • task lint passes
  • task license-check passes
  • task test passes with race detection

Notes

This is the first package graduation to toolhive-core. The env package was chosen because:

  • Zero dependencies on ToolHive internals
  • Uses only standard library (os package)
  • Already well-tested
  • Simple, focused API surface

🤖 Generated with Claude Code

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]>
@JAORMX
JAORMX merged commit 8b56914 into main Feb 2, 2026
5 checks passed
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]>
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.

2 participants