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

Commit

Permalink
feat: accept google-gax instance as a parameter (#433)
Browse files Browse the repository at this point in the history
* 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

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* fix: use _gaxModule when accessing gax for bundling

PiperOrigin-RevId: 470911839

Source-Link: googleapis/googleapis@3527566

Source-Link: https://github.com/googleapis/googleapis-gen/commit/f16a1d224f00a630ea43d6a9a1a31f566f45cdea
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjE2YTFkMjI0ZjAwYTYzMGVhNDNkNmE5YTFhMzFmNTY2ZjQ1Y2RlYSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* chore: use gapic-generator-typescript v2.17.0

PiperOrigin-RevId: 474338479

Source-Link: googleapis/googleapis@d5d35e0

Source-Link: https://github.com/googleapis/googleapis-gen/commit/efcd3f93962a103f68f003e2a1eecde6fa216a27
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWZjZDNmOTM5NjJhMTAzZjY4ZjAwM2UyYTFlZWNkZTZmYTIxNmEyNyJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* test: use fully qualified request type name in tests

PiperOrigin-RevId: 475685359

Source-Link: googleapis/googleapis@7a12973

Source-Link: https://github.com/googleapis/googleapis-gen/commit/370c729e2ba062a167449c27882ba5f379c5c34d
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzcwYzcyOWUyYmEwNjJhMTY3NDQ5YzI3ODgyYmE1ZjM3OWM1YzM0ZCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* fix: owlbot post-processing for grafeas

* fix: add Grafeas import back

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Alexander Fenster <[email protected]>
  • Loading branch information
3 people authored Sep 22, 2022
1 parent 411bae6 commit 51e82fd
Show file tree
Hide file tree
Showing 7 changed files with 1,525 additions and 1,267 deletions.
4 changes: 2 additions & 2 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def patch(library: pathlib.Path):

# perform surgery inserting the Grafeas client.
s.replace(library / "src/v1/container_analysis_client.ts",
"""import \* as gax from \'google-gax\';""",
"""import * as gax from 'google-gax';
"""import type \* as gax from \'google-gax\';""",
"""import type * as gax from 'google-gax';
import {GrafeasClient} from '@google-cloud/grafeas';""")
s.replace(library / "src/v1/container_analysis_client.ts", "^}",
r"""
Expand Down
47 changes: 33 additions & 14 deletions src/v1/container_analysis_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
// ** All changes to this file may be overwritten. **

/* global window */
import * as gax from 'google-gax';
import type * as gax from 'google-gax';
import {GrafeasClient} from '@google-cloud/grafeas';
import {Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax';
import type {
Callback,
CallOptions,
Descriptors,
ClientOptions,
} from 'google-gax';

import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
Expand All @@ -29,7 +34,6 @@ import jsonProtos = require('../../protos/protos.json');
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './container_analysis_client_config.json';

const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -101,8 +105,18 @@ export class ContainerAnalysisClient {
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
* For more information, please check the
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
* @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
* need to avoid loading the default gRPC version and want to use the fallback
* HTTP implementation. Load only fallback version and pass it to the constructor:
* ```
* const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
* const client = new ContainerAnalysisClient({fallback: 'rest'}, gax);
* ```
*/
constructor(opts?: ClientOptions) {
constructor(
opts?: ClientOptions,
gaxInstance?: typeof gax | typeof gax.fallback
) {
// Ensure that options include all the required fields.
const staticMembers = this.constructor as typeof ContainerAnalysisClient;
const servicePath =
Expand All @@ -122,8 +136,13 @@ export class ContainerAnalysisClient {
opts['scopes'] = staticMembers.scopes;
}

// Load google-gax module synchronously if needed
if (!gaxInstance) {
gaxInstance = require('google-gax') as typeof gax;
}

// Choose either gRPC or proto-over-HTTP implementation of google-gax.
this._gaxModule = opts.fallback ? gax.fallback : gax;
this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;

// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
Expand Down Expand Up @@ -192,7 +211,7 @@ export class ContainerAnalysisClient {
this.innerApiCalls = {};

// Add a warn function to the client constructor so it can be easily tested.
this.warn = gax.warn;
this.warn = this._gaxModule.warn;
}

/**
Expand Down Expand Up @@ -412,8 +431,8 @@ export class ContainerAnalysisClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
resource: request.resource || '',
this._gaxModule.routingHeader.fromParams({
resource: request.resource ?? '',
});
this.initialize();
return this.innerApiCalls.setIamPolicy(request, options, callback);
Expand Down Expand Up @@ -506,8 +525,8 @@ export class ContainerAnalysisClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
resource: request.resource || '',
this._gaxModule.routingHeader.fromParams({
resource: request.resource ?? '',
});
this.initialize();
return this.innerApiCalls.getIamPolicy(request, options, callback);
Expand Down Expand Up @@ -601,8 +620,8 @@ export class ContainerAnalysisClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
resource: request.resource || '',
this._gaxModule.routingHeader.fromParams({
resource: request.resource ?? '',
});
this.initialize();
return this.innerApiCalls.testIamPermissions(request, options, callback);
Expand Down Expand Up @@ -701,8 +720,8 @@ export class ContainerAnalysisClient {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
parent: request.parent || '',
this._gaxModule.routingHeader.fromParams({
parent: request.parent ?? '',
});
this.initialize();
return this.innerApiCalls.getVulnerabilityOccurrencesSummary(
Expand Down
59 changes: 36 additions & 23 deletions src/v1beta1/container_analysis_v1_beta1_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
// ** All changes to this file may be overwritten. **

/* global window */
import * as gax from 'google-gax';
import {
import type * as gax from 'google-gax';
import type {
Callback,
CallOptions,
Descriptors,
ClientOptions,
PaginationCallback,
GaxCall,
} from 'google-gax';

import {Transform} from 'stream';
import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
Expand All @@ -36,7 +35,6 @@ import jsonProtos = require('../../protos/protos.json');
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './container_analysis_v1_beta1_client_config.json';

const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -108,8 +106,18 @@ export class ContainerAnalysisV1Beta1Client {
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
* For more information, please check the
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
* @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
* need to avoid loading the default gRPC version and want to use the fallback
* HTTP implementation. Load only fallback version and pass it to the constructor:
* ```
* const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
* const client = new ContainerAnalysisV1Beta1Client({fallback: 'rest'}, gax);
* ```
*/
constructor(opts?: ClientOptions) {
constructor(
opts?: ClientOptions,
gaxInstance?: typeof gax | typeof gax.fallback
) {
// Ensure that options include all the required fields.
const staticMembers = this
.constructor as typeof ContainerAnalysisV1Beta1Client;
Expand All @@ -130,8 +138,13 @@ export class ContainerAnalysisV1Beta1Client {
opts['scopes'] = staticMembers.scopes;
}

// Load google-gax module synchronously if needed
if (!gaxInstance) {
gaxInstance = require('google-gax') as typeof gax;
}

// Choose either gRPC or proto-over-HTTP implementation of google-gax.
this._gaxModule = opts.fallback ? gax.fallback : gax;
this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;

// Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
Expand Down Expand Up @@ -208,7 +221,7 @@ export class ContainerAnalysisV1Beta1Client {
this.innerApiCalls = {};

// Add a warn function to the client constructor so it can be easily tested.
this.warn = gax.warn;
this.warn = this._gaxModule.warn;
}

/**
Expand Down Expand Up @@ -430,8 +443,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
resource: request.resource || '',
this._gaxModule.routingHeader.fromParams({
resource: request.resource ?? '',
});
this.initialize();
return this.innerApiCalls.setIamPolicy(request, options, callback);
Expand Down Expand Up @@ -524,8 +537,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
resource: request.resource || '',
this._gaxModule.routingHeader.fromParams({
resource: request.resource ?? '',
});
this.initialize();
return this.innerApiCalls.getIamPolicy(request, options, callback);
Expand Down Expand Up @@ -619,8 +632,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
resource: request.resource || '',
this._gaxModule.routingHeader.fromParams({
resource: request.resource ?? '',
});
this.initialize();
return this.innerApiCalls.testIamPermissions(request, options, callback);
Expand Down Expand Up @@ -717,8 +730,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
name: request.name || '',
this._gaxModule.routingHeader.fromParams({
name: request.name ?? '',
});
this.initialize();
return this.innerApiCalls.getScanConfig(request, options, callback);
Expand Down Expand Up @@ -817,8 +830,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
name: request.name || '',
this._gaxModule.routingHeader.fromParams({
name: request.name ?? '',
});
this.initialize();
return this.innerApiCalls.updateScanConfig(request, options, callback);
Expand Down Expand Up @@ -919,8 +932,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
parent: request.parent || '',
this._gaxModule.routingHeader.fromParams({
parent: request.parent ?? '',
});
this.initialize();
return this.innerApiCalls.listScanConfigs(request, options, callback);
Expand Down Expand Up @@ -960,8 +973,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
parent: request.parent || '',
this._gaxModule.routingHeader.fromParams({
parent: request.parent ?? '',
});
const defaultCallSettings = this._defaults['listScanConfigs'];
const callSettings = defaultCallSettings.merge(options);
Expand Down Expand Up @@ -1010,8 +1023,8 @@ export class ContainerAnalysisV1Beta1Client {
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
gax.routingHeader.fromParams({
parent: request.parent || '',
this._gaxModule.routingHeader.fromParams({
parent: request.parent ?? '',
});
const defaultCallSettings = this._defaults['listScanConfigs'];
const callSettings = defaultCallSettings.merge(options);
Expand Down
Loading

0 comments on commit 51e82fd

Please sign in to comment.