Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to configure Gaxios options for common AuthClients #1621

Closed
benasher44 opened this issue Jul 26, 2023 · 4 comments · Fixed by #1663
Closed

Unable to configure Gaxios options for common AuthClients #1621

benasher44 opened this issue Jul 26, 2023 · 4 comments · Fixed by #1663
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@benasher44
Copy link

Is your feature request related to a problem? Please describe.
For OAuth2Client for example, there's no way to configure the agent to make use of keep alive.

Describe the solution you'd like
Ideally, the constructor for all AuthClient sub-classes accept options that would be passed to gaxios, which would allow setting the agent

Describe alternatives you've considered
I think one could maybe overwrite the transporter ivar with one that is sub-classes to set an agent, but that feels bad.

Additional context
Nearly all of the API wrappers in https://github.com/googleapis/google-api-nodejs-client use a similar constructor pattern, wherein all of the constructor options are a subset of gaxios options.

@benasher44 benasher44 added priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jul 26, 2023
@benasher44 benasher44 changed the title Unable to configure Gaxios options for common clients Unable to configure Gaxios options for common AuthClients Jul 26, 2023
@benasher44
Copy link
Author

For some reason, the JWT class does this, but OAuth2Client doesn't. I think this also means that if JWT isn't overriding everything and you set gaxios options, behavior will be inconsistent, when calling non-overridden methods.

@benasher44
Copy link
Author

Oh never mind; it looks like I had the types for JWT's constructor wrong. It doesn't accept gaxios options.

@danielbankhead danielbankhead self-assigned this Aug 7, 2023
@danielbankhead
Copy link
Member

Hey @benasher44,

Today, we offer a few options for setting keepAlive:

  • 1: On a per-request basis

    const agent = new https.Agent({keepAlive: true});
    // use the agent as an Axios config param to make the request
    const res = await client.request({url, agent});

  • 2: You can assign your own Transporter to the AuthClient

    export interface Transporter {
    request<T>(opts: GaxiosOptions): GaxiosPromise<T>;
    }

    export abstract class AuthClient
    extends EventEmitter
    implements CredentialsClient
    {
    /**
    * The quota project ID. The quota project can be used by client libraries for the billing purpose.
    * See {@link https://cloud.google.com/docs/quota| Working with quotas}
    */
    quotaProjectId?: string;
    transporter: Transporter = new DefaultTransporter();

Describe the solution you'd like
Ideally, the constructor for all AuthClient sub-classes accept options that would be passed to gaxios, which would allow setting the agent

This is a worthwhile feature request, we'll explore this as an option.

@danielbankhead
Copy link
Member

Exposing this as a new option via:

Now all AuthClients can accept a gaxios, custom transporter instance, or set default properties for the transporter.

Additionally, it can be set for any AuthClient that would be instantiated via:

new GoogleAuth({
  clientOptions: {
    transporterOptions: {} // `GaxiosOptions`
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants