Skip to content

fix(pubsub): reuse GoogleAuth instance and deprecate credential options - #9721

Draft
quirogas wants to merge 1 commit into
fix/windy-eagle-auth-warningsfrom
fix/windy-eagle-pubsub-auth-reuse
Draft

quirogas wants to merge 1 commit into
fix/windy-eagle-auth-warningsfrom
fix/windy-eagle-pubsub-auth-reuse

Conversation

@quirogas

Copy link
Copy Markdown
Contributor

Description

Reuse the PubSub GoogleAuth instance across underlying GAPIC clients and JSDocs.

Impact

Prevents duplicate GoogleAuth instantiations and duplicate credential deprecation warnings in PubSub.

Changes

  • Reuse this.options.auth in PubSub constructor if provided, and pass this.options.auth ??= this.auth in getClientConfig() so PublisherClient, SubscriberClient, and SchemaServiceClient share the same GoogleAuth instance.
  • Sync GAPIC JWT properties (defaultServicePath, useJWTAccessWithScope, defaultScopes) onto this.auth.cachedCredential in getClientAsync_() and getSchemaClient() when getProjectId() has already cached a JWT client prior to GAPIC client initialization.
  • Add @deprecated notices to ClientConfig JSDoc properties keyFilename and credentials in handwritten/pubsub/src/pubsub.ts.

Testing

  • Added unit tests in handwritten/pubsub/test/pubsub.ts verifying options.auth reuse in new PubSub({auth}) and getClientAsync_().
  • Added unit tests in handwritten/pubsub/test/pubsub.ts verifying GAPIC JWT property synchronization on this.auth.cachedCredential in getClientAsync_() and getSchemaClient().

Alternatives

  • Leaving PubSub to create a separate GoogleAuth instance per underlying GAPIC client causes duplicate GoogleAuth constructor warnings when keyFilename or credentials is passed and reloads credentials unnecessarily.

@quirogas
quirogas added this pull request to stack #9722 October 23, 2026 23:55
@product-auto-label product-auto-label Bot added the api: pubsub Issues related to the Pub/Sub API. label Oct 23, 2026
@quirogas
quirogas force-pushed the fix/windy-eagle-pubsub-auth-reuse branch from c543d23 to 4a3617c Compare October 23, 2026 23:56

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the PubSub class to support reusing an existing GoogleAuth instance if provided in the options, and marks the keyFilename and credentials options as deprecated in the JSDoc. It also introduces logic to sync GAPIC JWT values on the cached credential when instantiating clients, ensuring existing properties are not overwritten. Corresponding unit tests have been added to verify these changes. There are no review comments, so I have no feedback to provide.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant