Skip to content

feat(client): support ADC and quota project via AuthorizedSession - #9

Merged
dkaysin merged 6 commits into
mainfrom
feature/nojira-adc-quota-project-support
Jul 15, 2026
Merged

dkaysin merged 6 commits into
mainfrom
feature/nojira-adc-quota-project-support

Conversation

@dkaysin

@dkaysin dkaysin commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Makes RemoteConfigClient work with any Application Default Credentials — a service account, workload identity, or local user credentials from gcloud auth application-default login — instead of service accounts only.

Requests now go through google-auth's AuthorizedSession, which refreshes tokens and attaches the x-goog-user-project quota-project header automatically. This removes the need for callers to hand-roll an authenticated session just to reach the Remote Config REST API under user credentials.

Changes

  • ADC support. The constructor accepts the google-auth base Credentials type; service-account, workload-identity, and user credentials all work.
  • Quota project. The Remote Config REST API rejects user credentials that carry no quota project with 403 SERVICE_DISABLED. User credentials now default their quota project to project_id; a new optional quota_project_id param overrides it. Service-account / workload-identity credentials get no quota project unless they already carry one.
  • Timeouts. New optional timeout param (default 30s) applied to every request; previously requests were unbounded. Pass timeout=None to restore the old behavior.
  • Robustness. make_remote_config tolerates a missing etag header instead of raising KeyError.
  • Removed the now-unused private get_oauth_token helper and simplified make_headers (auth is handled by the session).

Public method signatures and return types are unchanged; the documented service-account usage is a drop-in.

Compatibility

  • Constructor gains only optional params — existing RemoteConfigClient(credentials, project_id) calls are unchanged.
  • Behavioral deltas: the 30s default timeout (opt out with timeout=None), and x-goog-user-project is now sent when credentials carry a quota project (standard behavior). Private helpers get_oauth_token / old make_headers(access_token, ...) are gone — not part of the exported API.
  • Minor version bump 0.1.23 → 0.2.0.

Tests

Adds tests/test_client.py (the client previously had none): quota-project resolution across credential types, GET success and version param, non-200 → UnexpectedError, rollback body, and timeout forwarding — all mocking AuthorizedSession, no network. Full suite: 24 passed, ruff clean.

dkaysin added 6 commits July 15, 2026 17:07
Route requests through google-auth's AuthorizedSession so any Application
Default Credentials work (service account, workload identity, or local user
credentials from `gcloud auth application-default login`), not just service
accounts. The session refreshes tokens and attaches the `x-goog-user-project`
quota-project header automatically.

The Remote Config REST API rejects user credentials with no quota project
(403 SERVICE_DISABLED); user credentials now default their quota project to
`project_id`. Add optional `quota_project_id` and `timeout` (default 30s)
constructor params. Broaden the accepted credential type to the google-auth
base `Credentials`. Public method signatures and return types are unchanged.
Add RemoteConfigClient tests: quota-project resolution for user, service
account, explicit, and preset-quota credentials; GET success and version
param; non-200 raising UnexpectedError; rollback body; and timeout
forwarding. All mock AuthorizedSession with no network access.
Show initializing the client with google.auth.default() alongside the
service-account example, explain the quota_project_id parameter and the
403 SERVICE_DISABLED case for user credentials, and broaden the credentials
requirement note beyond service accounts.
list_versions returns a ListVersionsResponse, not a tuple.
@dkaysin
dkaysin merged commit 67f42cd into main Jul 15, 2026
2 checks passed
@dkaysin
dkaysin deleted the feature/nojira-adc-quota-project-support branch September 23, 2026 14:31
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.

1 participant