Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 819ed55

Browse files
fix: allow passing gax instance to client constructor (#78)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 470911839 Source-Link: googleapis/googleapis@3527566 Source-Link: https://github.com/googleapis/googleapis-gen/commit/f16a1d224f00a630ea43d6a9a1a31f566f45cdea Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjE2YTFkMjI0ZjAwYTYzMGVhNDNkNmE5YTFhMzFmNTY2ZjQ1Y2RlYSJ9 feat: accept google-gax instance as a parameter Please see the documentation of the client constructor for details. PiperOrigin-RevId: 470332808 Source-Link: googleapis/googleapis@d4a2367 Source-Link: https://github.com/googleapis/googleapis-gen/commit/e97a1ac204ead4fe7341f91e72db7c6ac6016341 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTk3YTFhYzIwNGVhZDRmZTczNDFmOTFlNzJkYjdjNmFjNjAxNjM0MSJ9
1 parent 863d928 commit 819ed55

3 files changed

Lines changed: 90 additions & 45 deletions

File tree

src/v1/identity_aware_proxy_admin_service_client.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
// ** All changes to this file may be overwritten. **
1818

1919
/* global window */
20-
import * as gax from 'google-gax';
21-
import {
20+
import type * as gax from 'google-gax';
21+
import type {
2222
Callback,
2323
CallOptions,
2424
Descriptors,
2525
ClientOptions,
2626
PaginationCallback,
2727
GaxCall,
2828
} from 'google-gax';
29-
3029
import {Transform} from 'stream';
3130
import * as protos from '../../protos/protos';
3231
import jsonProtos = require('../../protos/protos.json');
@@ -36,7 +35,6 @@ import jsonProtos = require('../../protos/protos.json');
3635
* This file defines retry strategy and timeouts for all API methods in this library.
3736
*/
3837
import * as gapicConfig from './identity_aware_proxy_admin_service_client_config.json';
39-
4038
const version = require('../../../package.json').version;
4139

4240
/**
@@ -96,8 +94,18 @@ export class IdentityAwareProxyAdminServiceClient {
9694
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
9795
* For more information, please check the
9896
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
97+
* @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
98+
* need to avoid loading the default gRPC version and want to use the fallback
99+
* HTTP implementation. Load only fallback version and pass it to the constructor:
100+
* ```
101+
* const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
102+
* const client = new IdentityAwareProxyAdminServiceClient({fallback: 'rest'}, gax);
103+
* ```
99104
*/
100-
constructor(opts?: ClientOptions) {
105+
constructor(
106+
opts?: ClientOptions,
107+
gaxInstance?: typeof gax | typeof gax.fallback
108+
) {
101109
// Ensure that options include all the required fields.
102110
const staticMembers = this
103111
.constructor as typeof IdentityAwareProxyAdminServiceClient;
@@ -118,8 +126,13 @@ export class IdentityAwareProxyAdminServiceClient {
118126
opts['scopes'] = staticMembers.scopes;
119127
}
120128

129+
// Load google-gax module synchronously if needed
130+
if (!gaxInstance) {
131+
gaxInstance = require('google-gax') as typeof gax;
132+
}
133+
121134
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
122-
this._gaxModule = opts.fallback ? gax.fallback : gax;
135+
this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
123136

124137
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
125138
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
@@ -199,7 +212,7 @@ export class IdentityAwareProxyAdminServiceClient {
199212
this.innerApiCalls = {};
200213

201214
// Add a warn function to the client constructor so it can be easily tested.
202-
this.warn = gax.warn;
215+
this.warn = this._gaxModule.warn;
203216
}
204217

205218
/**
@@ -421,7 +434,7 @@ export class IdentityAwareProxyAdminServiceClient {
421434
options.otherArgs = options.otherArgs || {};
422435
options.otherArgs.headers = options.otherArgs.headers || {};
423436
options.otherArgs.headers['x-goog-request-params'] =
424-
gax.routingHeader.fromParams({
437+
this._gaxModule.routingHeader.fromParams({
425438
resource: request.resource || '',
426439
});
427440
this.initialize();
@@ -511,7 +524,7 @@ export class IdentityAwareProxyAdminServiceClient {
511524
options.otherArgs = options.otherArgs || {};
512525
options.otherArgs.headers = options.otherArgs.headers || {};
513526
options.otherArgs.headers['x-goog-request-params'] =
514-
gax.routingHeader.fromParams({
527+
this._gaxModule.routingHeader.fromParams({
515528
resource: request.resource || '',
516529
});
517530
this.initialize();
@@ -603,7 +616,7 @@ export class IdentityAwareProxyAdminServiceClient {
603616
options.otherArgs = options.otherArgs || {};
604617
options.otherArgs.headers = options.otherArgs.headers || {};
605618
options.otherArgs.headers['x-goog-request-params'] =
606-
gax.routingHeader.fromParams({
619+
this._gaxModule.routingHeader.fromParams({
607620
resource: request.resource || '',
608621
});
609622
this.initialize();
@@ -688,7 +701,7 @@ export class IdentityAwareProxyAdminServiceClient {
688701
options.otherArgs = options.otherArgs || {};
689702
options.otherArgs.headers = options.otherArgs.headers || {};
690703
options.otherArgs.headers['x-goog-request-params'] =
691-
gax.routingHeader.fromParams({
704+
this._gaxModule.routingHeader.fromParams({
692705
name: request.name || '',
693706
});
694707
this.initialize();
@@ -780,7 +793,7 @@ export class IdentityAwareProxyAdminServiceClient {
780793
options.otherArgs = options.otherArgs || {};
781794
options.otherArgs.headers = options.otherArgs.headers || {};
782795
options.otherArgs.headers['x-goog-request-params'] =
783-
gax.routingHeader.fromParams({
796+
this._gaxModule.routingHeader.fromParams({
784797
'iap_settings.name': request.iapSettings!.name || '',
785798
});
786799
this.initialize();
@@ -881,7 +894,7 @@ export class IdentityAwareProxyAdminServiceClient {
881894
options.otherArgs = options.otherArgs || {};
882895
options.otherArgs.headers = options.otherArgs.headers || {};
883896
options.otherArgs.headers['x-goog-request-params'] =
884-
gax.routingHeader.fromParams({
897+
this._gaxModule.routingHeader.fromParams({
885898
parent: request.parent || '',
886899
});
887900
this.initialize();
@@ -968,7 +981,7 @@ export class IdentityAwareProxyAdminServiceClient {
968981
options.otherArgs = options.otherArgs || {};
969982
options.otherArgs.headers = options.otherArgs.headers || {};
970983
options.otherArgs.headers['x-goog-request-params'] =
971-
gax.routingHeader.fromParams({
984+
this._gaxModule.routingHeader.fromParams({
972985
name: request.name || '',
973986
});
974987
this.initialize();
@@ -1061,7 +1074,7 @@ export class IdentityAwareProxyAdminServiceClient {
10611074
options.otherArgs = options.otherArgs || {};
10621075
options.otherArgs.headers = options.otherArgs.headers || {};
10631076
options.otherArgs.headers['x-goog-request-params'] =
1064-
gax.routingHeader.fromParams({
1077+
this._gaxModule.routingHeader.fromParams({
10651078
name: request.name || '',
10661079
});
10671080
this.initialize();
@@ -1156,7 +1169,7 @@ export class IdentityAwareProxyAdminServiceClient {
11561169
options.otherArgs = options.otherArgs || {};
11571170
options.otherArgs.headers = options.otherArgs.headers || {};
11581171
options.otherArgs.headers['x-goog-request-params'] =
1159-
gax.routingHeader.fromParams({
1172+
this._gaxModule.routingHeader.fromParams({
11601173
'tunnel_dest_group.name': request.tunnelDestGroup!.name || '',
11611174
});
11621175
this.initialize();
@@ -1268,7 +1281,7 @@ export class IdentityAwareProxyAdminServiceClient {
12681281
options.otherArgs = options.otherArgs || {};
12691282
options.otherArgs.headers = options.otherArgs.headers || {};
12701283
options.otherArgs.headers['x-goog-request-params'] =
1271-
gax.routingHeader.fromParams({
1284+
this._gaxModule.routingHeader.fromParams({
12721285
parent: request.parent || '',
12731286
});
12741287
this.initialize();
@@ -1317,7 +1330,7 @@ export class IdentityAwareProxyAdminServiceClient {
13171330
options.otherArgs = options.otherArgs || {};
13181331
options.otherArgs.headers = options.otherArgs.headers || {};
13191332
options.otherArgs.headers['x-goog-request-params'] =
1320-
gax.routingHeader.fromParams({
1333+
this._gaxModule.routingHeader.fromParams({
13211334
parent: request.parent || '',
13221335
});
13231336
const defaultCallSettings = this._defaults['listTunnelDestGroups'];
@@ -1375,7 +1388,7 @@ export class IdentityAwareProxyAdminServiceClient {
13751388
options.otherArgs = options.otherArgs || {};
13761389
options.otherArgs.headers = options.otherArgs.headers || {};
13771390
options.otherArgs.headers['x-goog-request-params'] =
1378-
gax.routingHeader.fromParams({
1391+
this._gaxModule.routingHeader.fromParams({
13791392
parent: request.parent || '',
13801393
});
13811394
const defaultCallSettings = this._defaults['listTunnelDestGroups'];

src/v1/identity_aware_proxy_o_auth_service_client.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
// ** All changes to this file may be overwritten. **
1818

1919
/* global window */
20-
import * as gax from 'google-gax';
21-
import {
20+
import type * as gax from 'google-gax';
21+
import type {
2222
Callback,
2323
CallOptions,
2424
Descriptors,
2525
ClientOptions,
2626
PaginationCallback,
2727
GaxCall,
2828
} from 'google-gax';
29-
3029
import {Transform} from 'stream';
3130
import * as protos from '../../protos/protos';
3231
import jsonProtos = require('../../protos/protos.json');
@@ -36,7 +35,6 @@ import jsonProtos = require('../../protos/protos.json');
3635
* This file defines retry strategy and timeouts for all API methods in this library.
3736
*/
3837
import * as gapicConfig from './identity_aware_proxy_o_auth_service_client_config.json';
39-
4038
const version = require('../../../package.json').version;
4139

4240
/**
@@ -98,8 +96,18 @@ export class IdentityAwareProxyOAuthServiceClient {
9896
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
9997
* For more information, please check the
10098
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
99+
* @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
100+
* need to avoid loading the default gRPC version and want to use the fallback
101+
* HTTP implementation. Load only fallback version and pass it to the constructor:
102+
* ```
103+
* const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
104+
* const client = new IdentityAwareProxyOAuthServiceClient({fallback: 'rest'}, gax);
105+
* ```
101106
*/
102-
constructor(opts?: ClientOptions) {
107+
constructor(
108+
opts?: ClientOptions,
109+
gaxInstance?: typeof gax | typeof gax.fallback
110+
) {
103111
// Ensure that options include all the required fields.
104112
const staticMembers = this
105113
.constructor as typeof IdentityAwareProxyOAuthServiceClient;
@@ -120,8 +128,13 @@ export class IdentityAwareProxyOAuthServiceClient {
120128
opts['scopes'] = staticMembers.scopes;
121129
}
122130

131+
// Load google-gax module synchronously if needed
132+
if (!gaxInstance) {
133+
gaxInstance = require('google-gax') as typeof gax;
134+
}
135+
123136
// Choose either gRPC or proto-over-HTTP implementation of google-gax.
124-
this._gaxModule = opts.fallback ? gax.fallback : gax;
137+
this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
125138

126139
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
127140
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
@@ -201,7 +214,7 @@ export class IdentityAwareProxyOAuthServiceClient {
201214
this.innerApiCalls = {};
202215

203216
// Add a warn function to the client constructor so it can be easily tested.
204-
this.warn = gax.warn;
217+
this.warn = this._gaxModule.warn;
205218
}
206219

207220
/**
@@ -407,7 +420,7 @@ export class IdentityAwareProxyOAuthServiceClient {
407420
options.otherArgs = options.otherArgs || {};
408421
options.otherArgs.headers = options.otherArgs.headers || {};
409422
options.otherArgs.headers['x-goog-request-params'] =
410-
gax.routingHeader.fromParams({
423+
this._gaxModule.routingHeader.fromParams({
411424
parent: request.parent || '',
412425
});
413426
this.initialize();
@@ -500,7 +513,7 @@ export class IdentityAwareProxyOAuthServiceClient {
500513
options.otherArgs = options.otherArgs || {};
501514
options.otherArgs.headers = options.otherArgs.headers || {};
502515
options.otherArgs.headers['x-goog-request-params'] =
503-
gax.routingHeader.fromParams({
516+
this._gaxModule.routingHeader.fromParams({
504517
parent: request.parent || '',
505518
});
506519
this.initialize();
@@ -584,7 +597,7 @@ export class IdentityAwareProxyOAuthServiceClient {
584597
options.otherArgs = options.otherArgs || {};
585598
options.otherArgs.headers = options.otherArgs.headers || {};
586599
options.otherArgs.headers['x-goog-request-params'] =
587-
gax.routingHeader.fromParams({
600+
this._gaxModule.routingHeader.fromParams({
588601
name: request.name || '',
589602
});
590603
this.initialize();
@@ -688,7 +701,7 @@ export class IdentityAwareProxyOAuthServiceClient {
688701
options.otherArgs = options.otherArgs || {};
689702
options.otherArgs.headers = options.otherArgs.headers || {};
690703
options.otherArgs.headers['x-goog-request-params'] =
691-
gax.routingHeader.fromParams({
704+
this._gaxModule.routingHeader.fromParams({
692705
parent: request.parent || '',
693706
});
694707
this.initialize();
@@ -792,7 +805,7 @@ export class IdentityAwareProxyOAuthServiceClient {
792805
options.otherArgs = options.otherArgs || {};
793806
options.otherArgs.headers = options.otherArgs.headers || {};
794807
options.otherArgs.headers['x-goog-request-params'] =
795-
gax.routingHeader.fromParams({
808+
this._gaxModule.routingHeader.fromParams({
796809
name: request.name || '',
797810
});
798811
this.initialize();
@@ -896,7 +909,7 @@ export class IdentityAwareProxyOAuthServiceClient {
896909
options.otherArgs = options.otherArgs || {};
897910
options.otherArgs.headers = options.otherArgs.headers || {};
898911
options.otherArgs.headers['x-goog-request-params'] =
899-
gax.routingHeader.fromParams({
912+
this._gaxModule.routingHeader.fromParams({
900913
name: request.name || '',
901914
});
902915
this.initialize();
@@ -1001,7 +1014,7 @@ export class IdentityAwareProxyOAuthServiceClient {
10011014
options.otherArgs = options.otherArgs || {};
10021015
options.otherArgs.headers = options.otherArgs.headers || {};
10031016
options.otherArgs.headers['x-goog-request-params'] =
1004-
gax.routingHeader.fromParams({
1017+
this._gaxModule.routingHeader.fromParams({
10051018
name: request.name || '',
10061019
});
10071020
this.initialize();
@@ -1113,7 +1126,7 @@ export class IdentityAwareProxyOAuthServiceClient {
11131126
options.otherArgs = options.otherArgs || {};
11141127
options.otherArgs.headers = options.otherArgs.headers || {};
11151128
options.otherArgs.headers['x-goog-request-params'] =
1116-
gax.routingHeader.fromParams({
1129+
this._gaxModule.routingHeader.fromParams({
11171130
parent: request.parent || '',
11181131
});
11191132
this.initialize();
@@ -1164,7 +1177,7 @@ export class IdentityAwareProxyOAuthServiceClient {
11641177
options.otherArgs = options.otherArgs || {};
11651178
options.otherArgs.headers = options.otherArgs.headers || {};
11661179
options.otherArgs.headers['x-goog-request-params'] =
1167-
gax.routingHeader.fromParams({
1180+
this._gaxModule.routingHeader.fromParams({
11681181
parent: request.parent || '',
11691182
});
11701183
const defaultCallSettings = this._defaults['listIdentityAwareProxyClients'];
@@ -1220,7 +1233,7 @@ export class IdentityAwareProxyOAuthServiceClient {
12201233
options.otherArgs = options.otherArgs || {};
12211234
options.otherArgs.headers = options.otherArgs.headers || {};
12221235
options.otherArgs.headers['x-goog-request-params'] =
1223-
gax.routingHeader.fromParams({
1236+
this._gaxModule.routingHeader.fromParams({
12241237
parent: request.parent || '',
12251238
});
12261239
const defaultCallSettings = this._defaults['listIdentityAwareProxyClients'];

0 commit comments

Comments
 (0)