diff --git a/packages/google-cloud-monitoring/src/v3/alert_policy_service_client.ts b/packages/google-cloud-monitoring/src/v3/alert_policy_service_client.ts index 55fed60328a..3d45295d634 100644 --- a/packages/google-cloud-monitoring/src/v3/alert_policy_service_client.ts +++ b/packages/google-cloud-monitoring/src/v3/alert_policy_service_client.ts @@ -52,8 +52,13 @@ export class AlertPolicyServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - alertPolicyServiceStub: Promise<{[name: string]: Function}>; + alertPolicyServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of AlertPolicyServiceClient. @@ -77,8 +82,6 @@ export class AlertPolicyServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -108,25 +111,28 @@ export class AlertPolicyServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof AlertPolicyServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -142,7 +148,7 @@ export class AlertPolicyServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -150,77 +156,79 @@ export class AlertPolicyServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderAlertPolicyPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}' ), - folderAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}/conditions/{condition}' ), - folderChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + folderChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannelDescriptors/{channel_descriptor}' ), - folderGroupPathTemplate: new gaxModule.PathTemplate( + folderGroupPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/groups/{group}' ), - folderNotificationChannelPathTemplate: new gaxModule.PathTemplate( + folderNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannels/{notification_channel}' ), - folderServicePathTemplate: new gaxModule.PathTemplate( + folderServicePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}' ), - folderServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + folderServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - folderUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + folderUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/uptimeCheckConfigs/{uptime_check_config}' ), - organizationAlertPolicyPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}' ), - organizationAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}/conditions/{condition}' ), - organizationChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannelDescriptors/{channel_descriptor}' ), - organizationGroupPathTemplate: new gaxModule.PathTemplate( + organizationGroupPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/groups/{group}' ), - organizationNotificationChannelPathTemplate: new gaxModule.PathTemplate( + organizationNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannels/{notification_channel}' ), - organizationServicePathTemplate: new gaxModule.PathTemplate( + organizationServicePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}' ), - organizationServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + organizationServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - organizationUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + organizationUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/uptimeCheckConfigs/{uptime_check_config}' ), - projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'), - projectAlertPolicyPathTemplate: new gaxModule.PathTemplate( + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}' ), - projectAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + projectAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}/conditions/{condition}' ), - projectChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + projectChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannelDescriptors/{channel_descriptor}' ), - projectGroupPathTemplate: new gaxModule.PathTemplate( + projectGroupPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/groups/{group}' ), - projectNotificationChannelPathTemplate: new gaxModule.PathTemplate( + projectNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannels/{notification_channel}' ), - projectServicePathTemplate: new gaxModule.PathTemplate( + projectServicePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}' ), - projectServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + projectServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - projectUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + projectUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/uptimeCheckConfigs/{uptime_check_config}' ), }; @@ -229,7 +237,7 @@ export class AlertPolicyServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - listAlertPolicies: new gaxModule.PageDescriptor( + listAlertPolicies: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'alertPolicies' @@ -237,7 +245,7 @@ export class AlertPolicyServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.monitoring.v3.AlertPolicyService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -248,17 +256,35 @@ export class AlertPolicyServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.alertPolicyServiceStub) { + return this.alertPolicyServiceStub; + } // Put together the "service stub" for // google.monitoring.v3.AlertPolicyService. - this.alertPolicyServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.alertPolicyServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.monitoring.v3.AlertPolicyService' ) : // tslint:disable-next-line no-any - (protos as any).google.monitoring.v3.AlertPolicyService, - opts + (this._protos as any).google.monitoring.v3.AlertPolicyService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -284,9 +310,9 @@ export class AlertPolicyServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -300,6 +326,8 @@ export class AlertPolicyServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.alertPolicyServiceStub; } /** @@ -427,6 +455,7 @@ export class AlertPolicyServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getAlertPolicy(request, options, callback); } createAlertPolicy( @@ -512,6 +541,7 @@ export class AlertPolicyServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.createAlertPolicy(request, options, callback); } deleteAlertPolicy( @@ -543,7 +573,7 @@ export class AlertPolicyServiceClient { * * projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID] * - * For more information, see [AlertPolicy][google.monitoring.v3.AlertPolicy]. + * For more information, see {@link google.monitoring.v3.AlertPolicy|AlertPolicy}. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. @@ -588,6 +618,7 @@ export class AlertPolicyServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteAlertPolicy(request, options, callback); } updateAlertPolicy( @@ -688,6 +719,7 @@ export class AlertPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'alert_policy.name': request.alertPolicy!.name || '', }); + this.initialize(); return this._innerApiCalls.updateAlertPolicy(request, options, callback); } @@ -723,7 +755,7 @@ export class AlertPolicyServiceClient { * Note that this field names the parent container in which the alerting * policies to be listed are stored. To retrieve a single alerting policy * by name, use the - * [GetAlertPolicy][google.monitoring.v3.AlertPolicyService.GetAlertPolicy] + * {@link google.monitoring.v3.AlertPolicyService.GetAlertPolicy|GetAlertPolicy} * operation, instead. * @param {string} request.filter * If provided, this field specifies the criteria that must be met by @@ -799,6 +831,7 @@ export class AlertPolicyServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listAlertPolicies(request, options, callback); } @@ -825,7 +858,7 @@ export class AlertPolicyServiceClient { * Note that this field names the parent container in which the alerting * policies to be listed are stored. To retrieve a single alerting policy * by name, use the - * [GetAlertPolicy][google.monitoring.v3.AlertPolicyService.GetAlertPolicy] + * {@link google.monitoring.v3.AlertPolicyService.GetAlertPolicy|GetAlertPolicy} * operation, instead. * @param {string} request.filter * If provided, this field specifies the criteria that must be met by @@ -865,6 +898,7 @@ export class AlertPolicyServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listAlertPolicies.createStream( this._innerApiCalls.listAlertPolicies as gax.GaxCall, request, @@ -2075,8 +2109,9 @@ export class AlertPolicyServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.alertPolicyServiceStub.then(stub => { + return this.alertPolicyServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-cloud-monitoring/src/v3/group_service_client.ts b/packages/google-cloud-monitoring/src/v3/group_service_client.ts index e1c372b0db1..80bfc5063d2 100644 --- a/packages/google-cloud-monitoring/src/v3/group_service_client.ts +++ b/packages/google-cloud-monitoring/src/v3/group_service_client.ts @@ -55,8 +55,13 @@ export class GroupServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - groupServiceStub: Promise<{[name: string]: Function}>; + groupServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of GroupServiceClient. @@ -80,8 +85,6 @@ export class GroupServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -111,25 +114,28 @@ export class GroupServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof GroupServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -145,7 +151,7 @@ export class GroupServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -153,77 +159,79 @@ export class GroupServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderAlertPolicyPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}' ), - folderAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}/conditions/{condition}' ), - folderChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + folderChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannelDescriptors/{channel_descriptor}' ), - folderGroupPathTemplate: new gaxModule.PathTemplate( + folderGroupPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/groups/{group}' ), - folderNotificationChannelPathTemplate: new gaxModule.PathTemplate( + folderNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannels/{notification_channel}' ), - folderServicePathTemplate: new gaxModule.PathTemplate( + folderServicePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}' ), - folderServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + folderServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - folderUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + folderUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/uptimeCheckConfigs/{uptime_check_config}' ), - organizationAlertPolicyPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}' ), - organizationAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}/conditions/{condition}' ), - organizationChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannelDescriptors/{channel_descriptor}' ), - organizationGroupPathTemplate: new gaxModule.PathTemplate( + organizationGroupPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/groups/{group}' ), - organizationNotificationChannelPathTemplate: new gaxModule.PathTemplate( + organizationNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannels/{notification_channel}' ), - organizationServicePathTemplate: new gaxModule.PathTemplate( + organizationServicePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}' ), - organizationServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + organizationServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - organizationUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + organizationUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/uptimeCheckConfigs/{uptime_check_config}' ), - projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'), - projectAlertPolicyPathTemplate: new gaxModule.PathTemplate( + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}' ), - projectAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + projectAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}/conditions/{condition}' ), - projectChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + projectChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannelDescriptors/{channel_descriptor}' ), - projectGroupPathTemplate: new gaxModule.PathTemplate( + projectGroupPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/groups/{group}' ), - projectNotificationChannelPathTemplate: new gaxModule.PathTemplate( + projectNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannels/{notification_channel}' ), - projectServicePathTemplate: new gaxModule.PathTemplate( + projectServicePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}' ), - projectServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + projectServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - projectUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + projectUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/uptimeCheckConfigs/{uptime_check_config}' ), }; @@ -232,12 +240,12 @@ export class GroupServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - listGroups: new gaxModule.PageDescriptor( + listGroups: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'group' ), - listGroupMembers: new gaxModule.PageDescriptor( + listGroupMembers: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'members' @@ -245,7 +253,7 @@ export class GroupServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.monitoring.v3.GroupService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -256,17 +264,35 @@ export class GroupServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.groupServiceStub) { + return this.groupServiceStub; + } // Put together the "service stub" for // google.monitoring.v3.GroupService. - this.groupServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.groupServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.monitoring.v3.GroupService' ) : // tslint:disable-next-line no-any - (protos as any).google.monitoring.v3.GroupService, - opts + (this._protos as any).google.monitoring.v3.GroupService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -293,9 +319,9 @@ export class GroupServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -309,6 +335,8 @@ export class GroupServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.groupServiceStub; } /** @@ -436,6 +464,7 @@ export class GroupServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getGroup(request, options, callback); } createGroup( @@ -514,6 +543,7 @@ export class GroupServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.createGroup(request, options, callback); } updateGroup( @@ -589,6 +619,7 @@ export class GroupServiceClient { ] = gax.routingHeader.fromParams({ 'group.name': request.group!.name || '', }); + this.initialize(); return this._innerApiCalls.updateGroup(request, options, callback); } deleteGroup( @@ -666,6 +697,7 @@ export class GroupServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteGroup(request, options, callback); } @@ -782,6 +814,7 @@ export class GroupServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listGroups(request, options, callback); } @@ -853,6 +886,7 @@ export class GroupServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listGroups.createStream( this._innerApiCalls.listGroups as gax.GaxCall, request, @@ -962,6 +996,7 @@ export class GroupServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listGroupMembers(request, options, callback); } @@ -1023,6 +1058,7 @@ export class GroupServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listGroupMembers.createStream( this._innerApiCalls.listGroupMembers as gax.GaxCall, request, @@ -2233,8 +2269,9 @@ export class GroupServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.groupServiceStub.then(stub => { + return this.groupServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-cloud-monitoring/src/v3/metric_service_client.ts b/packages/google-cloud-monitoring/src/v3/metric_service_client.ts index 5325f916ed2..44d265baa6e 100644 --- a/packages/google-cloud-monitoring/src/v3/metric_service_client.ts +++ b/packages/google-cloud-monitoring/src/v3/metric_service_client.ts @@ -45,8 +45,13 @@ export class MetricServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - metricServiceStub: Promise<{[name: string]: Function}>; + metricServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of MetricServiceClient. @@ -70,8 +75,6 @@ export class MetricServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -101,25 +104,28 @@ export class MetricServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof MetricServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -135,7 +141,7 @@ export class MetricServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -143,95 +149,97 @@ export class MetricServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderAlertPolicyPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}' ), - folderAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}/conditions/{condition}' ), - folderChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + folderChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannelDescriptors/{channel_descriptor}' ), - folderGroupPathTemplate: new gaxModule.PathTemplate( + folderGroupPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/groups/{group}' ), - folderMetricDescriptorPathTemplate: new gaxModule.PathTemplate( + folderMetricDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/metricDescriptors/{metric_descriptor=**}' ), - folderMonitoredResourceDescriptorPathTemplate: new gaxModule.PathTemplate( + folderMonitoredResourceDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/monitoredResourceDescriptors/{monitored_resource_descriptor}' ), - folderNotificationChannelPathTemplate: new gaxModule.PathTemplate( + folderNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannels/{notification_channel}' ), - folderServicePathTemplate: new gaxModule.PathTemplate( + folderServicePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}' ), - folderServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + folderServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - folderUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + folderUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/uptimeCheckConfigs/{uptime_check_config}' ), - organizationAlertPolicyPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}' ), - organizationAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}/conditions/{condition}' ), - organizationChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannelDescriptors/{channel_descriptor}' ), - organizationGroupPathTemplate: new gaxModule.PathTemplate( + organizationGroupPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/groups/{group}' ), - organizationMetricDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationMetricDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/metricDescriptors/{metric_descriptor=**}' ), - organizationMonitoredResourceDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationMonitoredResourceDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/monitoredResourceDescriptors/{monitored_resource_descriptor}' ), - organizationNotificationChannelPathTemplate: new gaxModule.PathTemplate( + organizationNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannels/{notification_channel}' ), - organizationServicePathTemplate: new gaxModule.PathTemplate( + organizationServicePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}' ), - organizationServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + organizationServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - organizationUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + organizationUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/uptimeCheckConfigs/{uptime_check_config}' ), - projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'), - projectAlertPolicyPathTemplate: new gaxModule.PathTemplate( + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}' ), - projectAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + projectAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}/conditions/{condition}' ), - projectChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + projectChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannelDescriptors/{channel_descriptor}' ), - projectGroupPathTemplate: new gaxModule.PathTemplate( + projectGroupPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/groups/{group}' ), - projectMetricDescriptorPathTemplate: new gaxModule.PathTemplate( + projectMetricDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/metricDescriptors/{metric_descriptor=**}' ), - projectMonitoredResourceDescriptorPathTemplate: new gaxModule.PathTemplate( + projectMonitoredResourceDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/monitoredResourceDescriptors/{monitored_resource_descriptor}' ), - projectNotificationChannelPathTemplate: new gaxModule.PathTemplate( + projectNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannels/{notification_channel}' ), - projectServicePathTemplate: new gaxModule.PathTemplate( + projectServicePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}' ), - projectServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + projectServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - projectUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + projectUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/uptimeCheckConfigs/{uptime_check_config}' ), }; @@ -240,17 +248,17 @@ export class MetricServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - listMonitoredResourceDescriptors: new gaxModule.PageDescriptor( + listMonitoredResourceDescriptors: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'resourceDescriptors' ), - listMetricDescriptors: new gaxModule.PageDescriptor( + listMetricDescriptors: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'metricDescriptors' ), - listTimeSeries: new gaxModule.PageDescriptor( + listTimeSeries: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'timeSeries' @@ -258,7 +266,7 @@ export class MetricServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.monitoring.v3.MetricService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -269,17 +277,35 @@ export class MetricServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.metricServiceStub) { + return this.metricServiceStub; + } // Put together the "service stub" for // google.monitoring.v3.MetricService. - this.metricServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.metricServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.monitoring.v3.MetricService' ) : // tslint:disable-next-line no-any - (protos as any).google.monitoring.v3.MetricService, - opts + (this._protos as any).google.monitoring.v3.MetricService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -308,9 +334,9 @@ export class MetricServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -324,6 +350,8 @@ export class MetricServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.metricServiceStub; } /** @@ -464,6 +492,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getMonitoredResourceDescriptor( request, options, @@ -545,6 +574,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getMetricDescriptor(request, options, callback); } createMetricDescriptor( @@ -632,6 +662,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.createMetricDescriptor( request, options, @@ -723,6 +754,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteMetricDescriptor( request, options, @@ -811,6 +843,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.createTimeSeries(request, options, callback); } @@ -910,6 +943,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listMonitoredResourceDescriptors( request, options, @@ -968,6 +1002,7 @@ export class MetricServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listMonitoredResourceDescriptors.createStream( this._innerApiCalls.listMonitoredResourceDescriptors as gax.GaxCall, request, @@ -1072,6 +1107,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listMetricDescriptors( request, options, @@ -1132,6 +1168,7 @@ export class MetricServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listMetricDescriptors.createStream( this._innerApiCalls.listMetricDescriptors as gax.GaxCall, request, @@ -1254,6 +1291,7 @@ export class MetricServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listTimeSeries(request, options, callback); } @@ -1328,6 +1366,7 @@ export class MetricServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listTimeSeries.createStream( this._innerApiCalls.listTimeSeries as gax.GaxCall, request, @@ -2820,8 +2859,9 @@ export class MetricServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.metricServiceStub.then(stub => { + return this.metricServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-cloud-monitoring/src/v3/notification_channel_service_client.ts b/packages/google-cloud-monitoring/src/v3/notification_channel_service_client.ts index e5e566a950f..5716c3f5b03 100644 --- a/packages/google-cloud-monitoring/src/v3/notification_channel_service_client.ts +++ b/packages/google-cloud-monitoring/src/v3/notification_channel_service_client.ts @@ -45,8 +45,13 @@ export class NotificationChannelServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - notificationChannelServiceStub: Promise<{[name: string]: Function}>; + notificationChannelServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of NotificationChannelServiceClient. @@ -70,8 +75,6 @@ export class NotificationChannelServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -102,26 +105,29 @@ export class NotificationChannelServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this .constructor as typeof NotificationChannelServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -137,7 +143,7 @@ export class NotificationChannelServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -145,77 +151,79 @@ export class NotificationChannelServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderAlertPolicyPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}' ), - folderAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}/conditions/{condition}' ), - folderChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + folderChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannelDescriptors/{channel_descriptor}' ), - folderGroupPathTemplate: new gaxModule.PathTemplate( + folderGroupPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/groups/{group}' ), - folderNotificationChannelPathTemplate: new gaxModule.PathTemplate( + folderNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannels/{notification_channel}' ), - folderServicePathTemplate: new gaxModule.PathTemplate( + folderServicePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}' ), - folderServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + folderServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - folderUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + folderUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/uptimeCheckConfigs/{uptime_check_config}' ), - organizationAlertPolicyPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}' ), - organizationAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}/conditions/{condition}' ), - organizationChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannelDescriptors/{channel_descriptor}' ), - organizationGroupPathTemplate: new gaxModule.PathTemplate( + organizationGroupPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/groups/{group}' ), - organizationNotificationChannelPathTemplate: new gaxModule.PathTemplate( + organizationNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannels/{notification_channel}' ), - organizationServicePathTemplate: new gaxModule.PathTemplate( + organizationServicePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}' ), - organizationServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + organizationServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - organizationUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + organizationUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/uptimeCheckConfigs/{uptime_check_config}' ), - projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'), - projectAlertPolicyPathTemplate: new gaxModule.PathTemplate( + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}' ), - projectAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + projectAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}/conditions/{condition}' ), - projectChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + projectChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannelDescriptors/{channel_descriptor}' ), - projectGroupPathTemplate: new gaxModule.PathTemplate( + projectGroupPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/groups/{group}' ), - projectNotificationChannelPathTemplate: new gaxModule.PathTemplate( + projectNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannels/{notification_channel}' ), - projectServicePathTemplate: new gaxModule.PathTemplate( + projectServicePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}' ), - projectServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + projectServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - projectUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + projectUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/uptimeCheckConfigs/{uptime_check_config}' ), }; @@ -224,12 +232,12 @@ export class NotificationChannelServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - listNotificationChannelDescriptors: new gaxModule.PageDescriptor( + listNotificationChannelDescriptors: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'channelDescriptors' ), - listNotificationChannels: new gaxModule.PageDescriptor( + listNotificationChannels: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'notificationChannels' @@ -237,7 +245,7 @@ export class NotificationChannelServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.monitoring.v3.NotificationChannelService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -248,17 +256,35 @@ export class NotificationChannelServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.notificationChannelServiceStub) { + return this.notificationChannelServiceStub; + } // Put together the "service stub" for // google.monitoring.v3.NotificationChannelService. - this.notificationChannelServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.notificationChannelServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.monitoring.v3.NotificationChannelService' ) : // tslint:disable-next-line no-any - (protos as any).google.monitoring.v3.NotificationChannelService, - opts + (this._protos as any).google.monitoring.v3.NotificationChannelService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -289,9 +315,9 @@ export class NotificationChannelServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -305,6 +331,8 @@ export class NotificationChannelServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.notificationChannelServiceStub; } /** @@ -442,6 +470,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getNotificationChannelDescriptor( request, options, @@ -532,6 +561,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getNotificationChannel( request, options, @@ -626,6 +656,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.createNotificationChannel( request, options, @@ -716,6 +747,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ 'notification_channel.name': request.notificationChannel!.name || '', }); + this.initialize(); return this._innerApiCalls.updateNotificationChannel( request, options, @@ -807,6 +839,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteNotificationChannel( request, options, @@ -892,6 +925,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.sendNotificationChannelVerificationCode( request, options, @@ -1008,6 +1042,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getNotificationChannelVerificationCode( request, options, @@ -1102,6 +1137,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.verifyNotificationChannel( request, options, @@ -1142,7 +1178,7 @@ export class NotificationChannelServiceClient { * * Note that this names the parent container in which to look for the * descriptors; to retrieve a single descriptor by name, use the - * [GetNotificationChannelDescriptor][google.monitoring.v3.NotificationChannelService.GetNotificationChannelDescriptor] + * {@link google.monitoring.v3.NotificationChannelService.GetNotificationChannelDescriptor|GetNotificationChannelDescriptor} * operation, instead. * @param {number} request.pageSize * The maximum number of results to return in a single response. If @@ -1207,6 +1243,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listNotificationChannelDescriptors( request, options, @@ -1237,7 +1274,7 @@ export class NotificationChannelServiceClient { * * Note that this names the parent container in which to look for the * descriptors; to retrieve a single descriptor by name, use the - * [GetNotificationChannelDescriptor][google.monitoring.v3.NotificationChannelService.GetNotificationChannelDescriptor] + * {@link google.monitoring.v3.NotificationChannelService.GetNotificationChannelDescriptor|GetNotificationChannelDescriptor} * operation, instead. * @param {number} request.pageSize * The maximum number of results to return in a single response. If @@ -1266,6 +1303,7 @@ export class NotificationChannelServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listNotificationChannelDescriptors.createStream( this._innerApiCalls.listNotificationChannelDescriptors as gax.GaxCall, request, @@ -1305,7 +1343,7 @@ export class NotificationChannelServiceClient { * in which to look for the notification channels; it does not name a * specific channel. To query a specific channel by REST resource name, use * the - * [`GetNotificationChannel`][google.monitoring.v3.NotificationChannelService.GetNotificationChannel] + * {@link google.monitoring.v3.NotificationChannelService.GetNotificationChannel|`GetNotificationChannel`} * operation. * @param {string} request.filter * If provided, this field specifies the criteria that must be met by @@ -1383,6 +1421,7 @@ export class NotificationChannelServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.listNotificationChannels( request, options, @@ -1414,7 +1453,7 @@ export class NotificationChannelServiceClient { * in which to look for the notification channels; it does not name a * specific channel. To query a specific channel by REST resource name, use * the - * [`GetNotificationChannel`][google.monitoring.v3.NotificationChannelService.GetNotificationChannel] + * {@link google.monitoring.v3.NotificationChannelService.GetNotificationChannel|`GetNotificationChannel`} * operation. * @param {string} request.filter * If provided, this field specifies the criteria that must be met by @@ -1456,6 +1495,7 @@ export class NotificationChannelServiceClient { name: request.name || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listNotificationChannels.createStream( this._innerApiCalls.listNotificationChannels as gax.GaxCall, request, @@ -2666,8 +2706,9 @@ export class NotificationChannelServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.notificationChannelServiceStub.then(stub => { + return this.notificationChannelServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-cloud-monitoring/src/v3/service_monitoring_service_client.ts b/packages/google-cloud-monitoring/src/v3/service_monitoring_service_client.ts index 4516ab43d7b..ecee7592a36 100644 --- a/packages/google-cloud-monitoring/src/v3/service_monitoring_service_client.ts +++ b/packages/google-cloud-monitoring/src/v3/service_monitoring_service_client.ts @@ -47,8 +47,13 @@ export class ServiceMonitoringServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - serviceMonitoringServiceStub: Promise<{[name: string]: Function}>; + serviceMonitoringServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of ServiceMonitoringServiceClient. @@ -72,8 +77,6 @@ export class ServiceMonitoringServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -104,26 +107,29 @@ export class ServiceMonitoringServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this .constructor as typeof ServiceMonitoringServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -139,7 +145,7 @@ export class ServiceMonitoringServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -147,77 +153,79 @@ export class ServiceMonitoringServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderAlertPolicyPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}' ), - folderAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}/conditions/{condition}' ), - folderChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + folderChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannelDescriptors/{channel_descriptor}' ), - folderGroupPathTemplate: new gaxModule.PathTemplate( + folderGroupPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/groups/{group}' ), - folderNotificationChannelPathTemplate: new gaxModule.PathTemplate( + folderNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannels/{notification_channel}' ), - folderServicePathTemplate: new gaxModule.PathTemplate( + folderServicePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}' ), - folderServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + folderServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - folderUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + folderUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/uptimeCheckConfigs/{uptime_check_config}' ), - organizationAlertPolicyPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}' ), - organizationAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}/conditions/{condition}' ), - organizationChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannelDescriptors/{channel_descriptor}' ), - organizationGroupPathTemplate: new gaxModule.PathTemplate( + organizationGroupPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/groups/{group}' ), - organizationNotificationChannelPathTemplate: new gaxModule.PathTemplate( + organizationNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannels/{notification_channel}' ), - organizationServicePathTemplate: new gaxModule.PathTemplate( + organizationServicePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}' ), - organizationServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + organizationServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - organizationUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + organizationUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/uptimeCheckConfigs/{uptime_check_config}' ), - projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'), - projectAlertPolicyPathTemplate: new gaxModule.PathTemplate( + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}' ), - projectAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + projectAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}/conditions/{condition}' ), - projectChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + projectChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannelDescriptors/{channel_descriptor}' ), - projectGroupPathTemplate: new gaxModule.PathTemplate( + projectGroupPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/groups/{group}' ), - projectNotificationChannelPathTemplate: new gaxModule.PathTemplate( + projectNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannels/{notification_channel}' ), - projectServicePathTemplate: new gaxModule.PathTemplate( + projectServicePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}' ), - projectServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + projectServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - projectUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + projectUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/uptimeCheckConfigs/{uptime_check_config}' ), }; @@ -226,12 +234,12 @@ export class ServiceMonitoringServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - listServices: new gaxModule.PageDescriptor( + listServices: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'services' ), - listServiceLevelObjectives: new gaxModule.PageDescriptor( + listServiceLevelObjectives: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'serviceLevelObjectives' @@ -239,7 +247,7 @@ export class ServiceMonitoringServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.monitoring.v3.ServiceMonitoringService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -250,17 +258,35 @@ export class ServiceMonitoringServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.serviceMonitoringServiceStub) { + return this.serviceMonitoringServiceStub; + } // Put together the "service stub" for // google.monitoring.v3.ServiceMonitoringService. - this.serviceMonitoringServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.serviceMonitoringServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.monitoring.v3.ServiceMonitoringService' ) : // tslint:disable-next-line no-any - (protos as any).google.monitoring.v3.ServiceMonitoringService, - opts + (this._protos as any).google.monitoring.v3.ServiceMonitoringService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -291,9 +317,9 @@ export class ServiceMonitoringServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -307,6 +333,8 @@ export class ServiceMonitoringServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.serviceMonitoringServiceStub; } /** @@ -438,6 +466,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.createService(request, options, callback); } getService( @@ -510,6 +539,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getService(request, options, callback); } updateService( @@ -584,6 +614,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ 'service.name': request.service!.name || '', }); + this.initialize(); return this._innerApiCalls.updateService(request, options, callback); } deleteService( @@ -656,6 +687,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteService(request, options, callback); } createServiceLevelObjective( @@ -745,6 +777,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.createServiceLevelObjective( request, options, @@ -836,6 +869,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getServiceLevelObjective( request, options, @@ -923,6 +957,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ 'service_level_objective.name': request.serviceLevelObjective!.name || '', }); + this.initialize(); return this._innerApiCalls.updateServiceLevelObjective( request, options, @@ -1009,6 +1044,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteServiceLevelObjective( request, options, @@ -1121,6 +1157,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.listServices(request, options, callback); } @@ -1184,6 +1221,7 @@ export class ServiceMonitoringServiceClient { parent: request.parent || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listServices.createStream( this._innerApiCalls.listServices as gax.GaxCall, request, @@ -1286,6 +1324,7 @@ export class ServiceMonitoringServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.listServiceLevelObjectives( request, options, @@ -1344,6 +1383,7 @@ export class ServiceMonitoringServiceClient { parent: request.parent || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listServiceLevelObjectives.createStream( this._innerApiCalls.listServiceLevelObjectives as gax.GaxCall, request, @@ -2554,8 +2594,9 @@ export class ServiceMonitoringServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.serviceMonitoringServiceStub.then(stub => { + return this.serviceMonitoringServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-cloud-monitoring/src/v3/uptime_check_service_client.ts b/packages/google-cloud-monitoring/src/v3/uptime_check_service_client.ts index 98febf66092..d0aa99442a1 100644 --- a/packages/google-cloud-monitoring/src/v3/uptime_check_service_client.ts +++ b/packages/google-cloud-monitoring/src/v3/uptime_check_service_client.ts @@ -51,8 +51,13 @@ export class UptimeCheckServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - uptimeCheckServiceStub: Promise<{[name: string]: Function}>; + uptimeCheckServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of UptimeCheckServiceClient. @@ -76,8 +81,6 @@ export class UptimeCheckServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -107,25 +110,28 @@ export class UptimeCheckServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof UptimeCheckServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = gaxGrpc.auth as gax.GoogleAuth; + this.auth = this._gaxGrpc.auth as gax.GoogleAuth; // Determine the client header string. - const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -141,7 +147,7 @@ export class UptimeCheckServiceClient { 'protos', 'protos.json' ); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath ); @@ -149,77 +155,79 @@ export class UptimeCheckServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - folderAlertPolicyPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}' ), - folderAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + folderAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/alertPolicies/{alert_policy}/conditions/{condition}' ), - folderChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + folderChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannelDescriptors/{channel_descriptor}' ), - folderGroupPathTemplate: new gaxModule.PathTemplate( + folderGroupPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/groups/{group}' ), - folderNotificationChannelPathTemplate: new gaxModule.PathTemplate( + folderNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/notificationChannels/{notification_channel}' ), - folderServicePathTemplate: new gaxModule.PathTemplate( + folderServicePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}' ), - folderServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + folderServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - folderUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + folderUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'folders/{folder}/uptimeCheckConfigs/{uptime_check_config}' ), - organizationAlertPolicyPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}' ), - organizationAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + organizationAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/alertPolicies/{alert_policy}/conditions/{condition}' ), - organizationChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + organizationChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannelDescriptors/{channel_descriptor}' ), - organizationGroupPathTemplate: new gaxModule.PathTemplate( + organizationGroupPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/groups/{group}' ), - organizationNotificationChannelPathTemplate: new gaxModule.PathTemplate( + organizationNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/notificationChannels/{notification_channel}' ), - organizationServicePathTemplate: new gaxModule.PathTemplate( + organizationServicePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}' ), - organizationServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + organizationServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - organizationUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + organizationUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'organizations/{organization}/uptimeCheckConfigs/{uptime_check_config}' ), - projectPathTemplate: new gaxModule.PathTemplate('projects/{project}'), - projectAlertPolicyPathTemplate: new gaxModule.PathTemplate( + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectAlertPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}' ), - projectAlertPolicyConditionPathTemplate: new gaxModule.PathTemplate( + projectAlertPolicyConditionPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/alertPolicies/{alert_policy}/conditions/{condition}' ), - projectChannelDescriptorPathTemplate: new gaxModule.PathTemplate( + projectChannelDescriptorPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannelDescriptors/{channel_descriptor}' ), - projectGroupPathTemplate: new gaxModule.PathTemplate( + projectGroupPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/groups/{group}' ), - projectNotificationChannelPathTemplate: new gaxModule.PathTemplate( + projectNotificationChannelPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/notificationChannels/{notification_channel}' ), - projectServicePathTemplate: new gaxModule.PathTemplate( + projectServicePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}' ), - projectServiceServiceLevelObjectivePathTemplate: new gaxModule.PathTemplate( + projectServiceServiceLevelObjectivePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/services/{service}/serviceLevelObjectives/{service_level_objective}' ), - projectUptimeCheckConfigPathTemplate: new gaxModule.PathTemplate( + projectUptimeCheckConfigPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/uptimeCheckConfigs/{uptime_check_config}' ), }; @@ -228,12 +236,12 @@ export class UptimeCheckServiceClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - listUptimeCheckConfigs: new gaxModule.PageDescriptor( + listUptimeCheckConfigs: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'uptimeCheckConfigs' ), - listUptimeCheckIps: new gaxModule.PageDescriptor( + listUptimeCheckIps: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', 'uptimeCheckIps' @@ -241,7 +249,7 @@ export class UptimeCheckServiceClient { }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.monitoring.v3.UptimeCheckService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, @@ -252,17 +260,35 @@ export class UptimeCheckServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.uptimeCheckServiceStub) { + return this.uptimeCheckServiceStub; + } // Put together the "service stub" for // google.monitoring.v3.UptimeCheckService. - this.uptimeCheckServiceStub = gaxGrpc.createStub( - opts.fallback - ? (protos as protobuf.Root).lookupService( + this.uptimeCheckServiceStub = this._gaxGrpc.createStub( + this._opts.fallback + ? (this._protos as protobuf.Root).lookupService( 'google.monitoring.v3.UptimeCheckService' ) : // tslint:disable-next-line no-any - (protos as any).google.monitoring.v3.UptimeCheckService, - opts + (this._protos as any).google.monitoring.v3.UptimeCheckService, + this._opts ) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides @@ -289,9 +315,9 @@ export class UptimeCheckServiceClient { } ); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -305,6 +331,8 @@ export class UptimeCheckServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.uptimeCheckServiceStub; } /** @@ -432,6 +460,7 @@ export class UptimeCheckServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.getUptimeCheckConfig(request, options, callback); } createUptimeCheckConfig( @@ -515,6 +544,7 @@ export class UptimeCheckServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.createUptimeCheckConfig( request, options, @@ -617,6 +647,7 @@ export class UptimeCheckServiceClient { ] = gax.routingHeader.fromParams({ 'uptime_check_config.name': request.uptimeCheckConfig!.name || '', }); + this.initialize(); return this._innerApiCalls.updateUptimeCheckConfig( request, options, @@ -704,6 +735,7 @@ export class UptimeCheckServiceClient { ] = gax.routingHeader.fromParams({ name: request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteUptimeCheckConfig( request, options, @@ -803,6 +835,7 @@ export class UptimeCheckServiceClient { ] = gax.routingHeader.fromParams({ parent: request.parent || '', }); + this.initialize(); return this._innerApiCalls.listUptimeCheckConfigs( request, options, @@ -856,6 +889,7 @@ export class UptimeCheckServiceClient { parent: request.parent || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listUptimeCheckConfigs.createStream( this._innerApiCalls.listUptimeCheckConfigs as gax.GaxCall, request, @@ -945,6 +979,7 @@ export class UptimeCheckServiceClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.listUptimeCheckIps(request, options, callback); } @@ -986,6 +1021,7 @@ export class UptimeCheckServiceClient { request = request || {}; options = options || {}; const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listUptimeCheckIps.createStream( this._innerApiCalls.listUptimeCheckIps as gax.GaxCall, request, @@ -2196,8 +2232,9 @@ export class UptimeCheckServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.uptimeCheckServiceStub.then(stub => { + return this.uptimeCheckServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-cloud-monitoring/synth.metadata b/packages/google-cloud-monitoring/synth.metadata index 7ff83528b8b..2b34cb458bd 100644 --- a/packages/google-cloud-monitoring/synth.metadata +++ b/packages/google-cloud-monitoring/synth.metadata @@ -1,12 +1,13 @@ { - "updateTime": "2020-02-11T08:09:54.291652Z", + "updateTime": "2020-03-05T23:11:12.932334Z", "sources": [ { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "5006247aa157e59118833658084345ee59af7c09", - "internalRef": "294383128" + "sha": "f0b581b5bdf803e45201ecdb3688b60e381628a8", + "internalRef": "299181282", + "log": "f0b581b5bdf803e45201ecdb3688b60e381628a8\nfix: recommendationengine/v1beta1 update some comments\n\nPiperOrigin-RevId: 299181282\n\n10e9a0a833dc85ff8f05b2c67ebe5ac785fe04ff\nbuild: add generated BUILD file for Routes Preferred API\n\nPiperOrigin-RevId: 299164808\n\n86738c956a8238d7c77f729be78b0ed887a6c913\npublish v1p1beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299152383\n\n73d9f2ad4591de45c2e1f352bc99d70cbd2a6d95\npublish v1: update with absolute address in comments\n\nPiperOrigin-RevId: 299147194\n\nd2158f24cb77b0b0ccfe68af784c6a628705e3c6\npublish v1beta2: update with absolute address in comments\n\nPiperOrigin-RevId: 299147086\n\n7fca61292c11b4cd5b352cee1a50bf88819dd63b\npublish v1p2beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299146903\n\n583b7321624736e2c490e328f4b1957335779295\npublish v1p3beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299146674\n\n638253bf86d1ce1c314108a089b7351440c2f0bf\nfix: add java_multiple_files option for automl text_sentiment.proto\n\nPiperOrigin-RevId: 298971070\n\n373d655703bf914fb8b0b1cc4071d772bac0e0d1\nUpdate Recs AI Beta public bazel file\n\nPiperOrigin-RevId: 298961623\n\ndcc5d00fc8a8d8b56f16194d7c682027b2c66a3b\nfix: add java_multiple_files option for automl classification.proto\n\nPiperOrigin-RevId: 298953301\n\na3f791827266f3496a6a5201d58adc4bb265c2a3\nchore: automl/v1 publish annotations and retry config\n\nPiperOrigin-RevId: 298942178\n\n01c681586d8d6dbd60155289b587aee678530bd9\nMark return_immediately in PullRequest deprecated.\n\nPiperOrigin-RevId: 298893281\n\nc9f5e9c4bfed54bbd09227e990e7bded5f90f31c\nRemove out of date documentation for predicate support on the Storage API\n\nPiperOrigin-RevId: 298883309\n\nfd5b3b8238d783b04692a113ffe07c0363f5de0f\ngenerate webrisk v1 proto\n\nPiperOrigin-RevId: 298847934\n\n541b1ded4abadcc38e8178680b0677f65594ea6f\nUpdate cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 298686266\n\nc0d171acecb4f5b0bfd2c4ca34fc54716574e300\n Updated to include the Notification v1 API.\n\nPiperOrigin-RevId: 298652775\n\n2346a9186c0bff2c9cc439f2459d558068637e05\nAdd Service Directory v1beta1 protos and configs\n\nPiperOrigin-RevId: 298625638\n\na78ed801b82a5c6d9c5368e24b1412212e541bb7\nPublishing v3 protos and configs.\n\nPiperOrigin-RevId: 298607357\n\n4a180bfff8a21645b3a935c2756e8d6ab18a74e0\nautoml/v1beta1 publish proto updates\n\nPiperOrigin-RevId: 298484782\n\n6de6e938b7df1cd62396563a067334abeedb9676\nchore: use the latest gapic-generator and protoc-java-resource-name-plugin in Bazel workspace.\n\nPiperOrigin-RevId: 298474513\n\n244ab2b83a82076a1fa7be63b7e0671af73f5c02\nAdds service config definition for bigqueryreservation v1\n\nPiperOrigin-RevId: 298455048\n\n83c6f84035ee0f80eaa44d8b688a010461cc4080\nUpdate google/api/auth.proto to make AuthProvider to have JwtLocation\n\nPiperOrigin-RevId: 297918498\n\ne9e90a787703ec5d388902e2cb796aaed3a385b4\nDialogflow weekly v2/v2beta1 library update:\n - adding get validation result\n - adding field mask override control for output audio config\nImportant updates are also posted at:\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 297671458\n\n1a2b05cc3541a5f7714529c665aecc3ea042c646\nAdding .yaml and .json config files.\n\nPiperOrigin-RevId: 297570622\n\ndfe1cf7be44dee31d78f78e485d8c95430981d6e\nPublish `QueryOptions` proto.\n\nIntroduced a `query_options` input in `ExecuteSqlRequest`.\n\nPiperOrigin-RevId: 297497710\n\ndafc905f71e5d46f500b41ed715aad585be062c3\npubsub: revert pull init_rpc_timeout & max_rpc_timeout back to 25 seconds and reset multiplier to 1.0\n\nPiperOrigin-RevId: 297486523\n\nf077632ba7fee588922d9e8717ee272039be126d\nfirestore: add update_transform\n\nPiperOrigin-RevId: 297405063\n\n0aba1900ffef672ec5f0da677cf590ee5686e13b\ncluster: use square brace for cross-reference\n\nPiperOrigin-RevId: 297204568\n\n5dac2da18f6325cbaed54603c43f0667ecd50247\nRestore retry params in gapic config because securitycenter has non-standard default retry params.\nRestore a few retry codes for some idempotent methods.\n\nPiperOrigin-RevId: 297196720\n\n1eb61455530252bba8b2c8d4bc9832960e5a56f6\npubsub: v1 replace IAM HTTP rules\n\nPiperOrigin-RevId: 297188590\n\n80b2d25f8d43d9d47024ff06ead7f7166548a7ba\nDialogflow weekly v2/v2beta1 library update:\n - updates to mega agent api\n - adding field mask override control for output audio config\nImportant updates are also posted at:\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 297187629\n\n0b1876b35e98f560f9c9ca9797955f020238a092\nUse an older version of protoc-docs-plugin that is compatible with the specified gapic-generator and protobuf versions.\n\nprotoc-docs-plugin >=0.4.0 (see commit https://github.com/googleapis/protoc-docs-plugin/commit/979f03ede6678c487337f3d7e88bae58df5207af) is incompatible with protobuf 3.9.1.\n\nPiperOrigin-RevId: 296986742\n\n1e47e676cddbbd8d93f19ba0665af15b5532417e\nFix: Restore a method signature for UpdateCluster\n\nPiperOrigin-RevId: 296901854\n\n7f910bcc4fc4704947ccfd3ceed015d16b9e00c2\nUpdate Dataproc v1beta2 client.\n\nPiperOrigin-RevId: 296451205\n\nde287524405a3dce124d301634731584fc0432d7\nFix: Reinstate method signatures that had been missed off some RPCs\nFix: Correct resource types for two fields\n\nPiperOrigin-RevId: 296435091\n\ne5bc9566ae057fb4c92f8b7e047f1c8958235b53\nDeprecate the endpoint_uris field, as it is unused.\n\nPiperOrigin-RevId: 296357191\n\n8c12e2b4dca94e12bff9f538bdac29524ff7ef7a\nUpdate Dataproc v1 client.\n\nPiperOrigin-RevId: 296336662\n\n17567c4a1ef0a9b50faa87024d66f8acbb561089\nRemoving erroneous comment, a la https://github.com/googleapis/java-speech/pull/103\n\nPiperOrigin-RevId: 296332968\n\n3eaaaf8626ce5b0c0bc7eee05e143beffa373b01\nAdd BUILD.bazel for v1 secretmanager.googleapis.com\n\nPiperOrigin-RevId: 296274723\n\ne76149c3d992337f85eeb45643106aacae7ede82\nMove securitycenter v1 to use generate from annotations.\n\nPiperOrigin-RevId: 296266862\n\n203740c78ac69ee07c3bf6be7408048751f618f8\nAdd StackdriverLoggingConfig field to Cloud Tasks v2 API.\n\nPiperOrigin-RevId: 296256388\n\ne4117d5e9ed8bbca28da4a60a94947ca51cb2083\nCreate a Bazel BUILD file for the google.actions.type export.\n\nPiperOrigin-RevId: 296212567\n\na9639a0a9854fd6e1be08bba1ac3897f4f16cb2f\nAdd secretmanager.googleapis.com v1 protos\n\nPiperOrigin-RevId: 295983266\n\nce4f4c21d9dd2bfab18873a80449b9d9851efde8\nasset: v1p1beta1 remove SearchResources and SearchIamPolicies\n\nPiperOrigin-RevId: 295861722\n\ncb61d6c2d070b589980c779b68ffca617f789116\nasset: v1p1beta1 remove SearchResources and SearchIamPolicies\n\nPiperOrigin-RevId: 295855449\n\nab2685d8d3a0e191dc8aef83df36773c07cb3d06\nfix: Dataproc v1 - AutoscalingPolicy annotation\n\nThis adds the second resource name pattern to the\nAutoscalingPolicy resource.\n\nCommitter: @lukesneeringer\nPiperOrigin-RevId: 295738415\n\n8a1020bf6828f6e3c84c3014f2c51cb62b739140\nUpdate cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 295286165\n\n5cfa105206e77670369e4b2225597386aba32985\nAdd service control related proto build rule.\n\nPiperOrigin-RevId: 295262088\n\nee4dddf805072004ab19ac94df2ce669046eec26\nmonitoring v3: Add prefix \"https://cloud.google.com/\" into the link for global access\ncl 295167522, get ride of synth.py hacks\n\nPiperOrigin-RevId: 295238095\n\nd9835e922ea79eed8497db270d2f9f85099a519c\nUpdate some minor docs changes about user event proto\n\nPiperOrigin-RevId: 295185610\n\n5f311e416e69c170243de722023b22f3df89ec1c\nfix: use correct PHP package name in gapic configuration\n\nPiperOrigin-RevId: 295161330\n\n6cdd74dcdb071694da6a6b5a206e3a320b62dd11\npubsub: v1 add client config annotations and retry config\n\nPiperOrigin-RevId: 295158776\n\n5169f46d9f792e2934d9fa25c36d0515b4fd0024\nAdded cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 295026522\n\n56b55aa8818cd0a532a7d779f6ef337ba809ccbd\nFix: Resource annotations for CreateTimeSeriesRequest and ListTimeSeriesRequest should refer to valid resources. TimeSeries is not a named resource.\n\nPiperOrigin-RevId: 294931650\n\n0646bc775203077226c2c34d3e4d50cc4ec53660\nRemove unnecessary languages from bigquery-related artman configuration files.\n\nPiperOrigin-RevId: 294809380\n\n8b78aa04382e3d4147112ad6d344666771bb1909\nUpdate backend.proto for schemes and protocol\n\nPiperOrigin-RevId: 294788800\n\n80b8f8b3de2359831295e24e5238641a38d8488f\nAdds artman config files for bigquerystorage endpoints v1beta2, v1alpha2, v1\n\nPiperOrigin-RevId: 294763931\n\n2c17ac33b226194041155bb5340c3f34733f1b3a\nAdd parameter to sample generated for UpdateInstance. Related to https://github.com/googleapis/python-redis/issues/4\n\nPiperOrigin-RevId: 294734008\n\nd5e8a8953f2acdfe96fb15e85eb2f33739623957\nMove bigquery datatransfer to gapic v2.\n\nPiperOrigin-RevId: 294703703\n\nefd36705972cfcd7d00ab4c6dfa1135bafacd4ae\nfix: Add two annotations that we missed.\n\nPiperOrigin-RevId: 294664231\n\n8a36b928873ff9c05b43859b9d4ea14cd205df57\nFix: Define the \"bigquery.googleapis.com/Table\" resource in the BigQuery Storage API (v1beta2).\n\nPiperOrigin-RevId: 294459768\n\nc7a3caa2c40c49f034a3c11079dd90eb24987047\nFix: Define the \"bigquery.googleapis.com/Table\" resource in the BigQuery Storage API (v1).\n\nPiperOrigin-RevId: 294456889\n\n" } }, { diff --git a/packages/google-cloud-monitoring/test/gapic-alert_policy_service-v3.ts b/packages/google-cloud-monitoring/test/gapic-alert_policy_service-v3.ts index 90f52dc3920..bc7b80f2d37 100644 --- a/packages/google-cloud-monitoring/test/gapic-alert_policy_service-v3.ts +++ b/packages/google-cloud-monitoring/test/gapic-alert_policy_service-v3.ts @@ -83,12 +83,30 @@ describe('v3.AlertPolicyServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.alertPolicyServiceStub, undefined); + await client.initialize(); + assert(client.alertPolicyServiceStub); + }); + it('has close method', () => { + const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('getAlertPolicy', () => { it('invokes getAlertPolicy without error', done => { const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetAlertPolicyRequest = {}; request.name = ''; @@ -112,6 +130,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetAlertPolicyRequest = {}; request.name = ''; @@ -137,6 +157,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateAlertPolicyRequest = {}; request.name = ''; @@ -160,6 +182,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateAlertPolicyRequest = {}; request.name = ''; @@ -185,6 +209,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteAlertPolicyRequest = {}; request.name = ''; @@ -208,6 +234,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteAlertPolicyRequest = {}; request.name = ''; @@ -233,6 +261,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateAlertPolicyRequest = {}; request.alertPolicy = {}; @@ -257,6 +287,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateAlertPolicyRequest = {}; request.alertPolicy = {}; @@ -283,6 +315,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListAlertPoliciesRequest = {}; request.name = ''; @@ -310,6 +344,8 @@ describe('v3.AlertPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListAlertPoliciesRequest = {}; request.name = ''; diff --git a/packages/google-cloud-monitoring/test/gapic-group_service-v3.ts b/packages/google-cloud-monitoring/test/gapic-group_service-v3.ts index 89a5260adff..941a1a75376 100644 --- a/packages/google-cloud-monitoring/test/gapic-group_service-v3.ts +++ b/packages/google-cloud-monitoring/test/gapic-group_service-v3.ts @@ -81,12 +81,30 @@ describe('v3.GroupServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new groupserviceModule.v3.GroupServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.groupServiceStub, undefined); + await client.initialize(); + assert(client.groupServiceStub); + }); + it('has close method', () => { + const client = new groupserviceModule.v3.GroupServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('getGroup', () => { it('invokes getGroup without error', done => { const client = new groupserviceModule.v3.GroupServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetGroupRequest = {}; request.name = ''; @@ -110,6 +128,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetGroupRequest = {}; request.name = ''; @@ -135,6 +155,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateGroupRequest = {}; request.name = ''; @@ -158,6 +180,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateGroupRequest = {}; request.name = ''; @@ -183,6 +207,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateGroupRequest = {}; request.group = {}; @@ -207,6 +233,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateGroupRequest = {}; request.group = {}; @@ -233,6 +261,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteGroupRequest = {}; request.name = ''; @@ -256,6 +286,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteGroupRequest = {}; request.name = ''; @@ -281,6 +313,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListGroupsRequest = {}; request.name = ''; @@ -308,6 +342,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListGroupsRequest = {}; request.name = ''; @@ -340,6 +376,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListGroupMembersRequest = {}; request.name = ''; @@ -367,6 +405,8 @@ describe('v3.GroupServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListGroupMembersRequest = {}; request.name = ''; diff --git a/packages/google-cloud-monitoring/test/gapic-metric_service-v3.ts b/packages/google-cloud-monitoring/test/gapic-metric_service-v3.ts index b707732b17d..6490176488a 100644 --- a/packages/google-cloud-monitoring/test/gapic-metric_service-v3.ts +++ b/packages/google-cloud-monitoring/test/gapic-metric_service-v3.ts @@ -81,12 +81,30 @@ describe('v3.MetricServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new metricserviceModule.v3.MetricServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.metricServiceStub, undefined); + await client.initialize(); + assert(client.metricServiceStub); + }); + it('has close method', () => { + const client = new metricserviceModule.v3.MetricServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('getMonitoredResourceDescriptor', () => { it('invokes getMonitoredResourceDescriptor without error', done => { const client = new metricserviceModule.v3.MetricServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetMonitoredResourceDescriptorRequest = {}; request.name = ''; @@ -113,6 +131,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetMonitoredResourceDescriptorRequest = {}; request.name = ''; @@ -141,6 +161,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetMetricDescriptorRequest = {}; request.name = ''; @@ -164,6 +186,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetMetricDescriptorRequest = {}; request.name = ''; @@ -189,6 +213,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateMetricDescriptorRequest = {}; request.name = ''; @@ -212,6 +238,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateMetricDescriptorRequest = {}; request.name = ''; @@ -237,6 +265,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteMetricDescriptorRequest = {}; request.name = ''; @@ -260,6 +290,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteMetricDescriptorRequest = {}; request.name = ''; @@ -285,6 +317,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateTimeSeriesRequest = {}; request.name = ''; @@ -308,6 +342,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateTimeSeriesRequest = {}; request.name = ''; @@ -333,6 +369,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListMonitoredResourceDescriptorsRequest = {}; request.name = ''; @@ -363,6 +401,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListMonitoredResourceDescriptorsRequest = {}; request.name = ''; @@ -395,6 +435,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListMetricDescriptorsRequest = {}; request.name = ''; @@ -422,6 +464,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListMetricDescriptorsRequest = {}; request.name = ''; @@ -454,6 +498,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListTimeSeriesRequest = {}; request.name = ''; @@ -481,6 +527,8 @@ describe('v3.MetricServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListTimeSeriesRequest = {}; request.name = ''; diff --git a/packages/google-cloud-monitoring/test/gapic-notification_channel_service-v3.ts b/packages/google-cloud-monitoring/test/gapic-notification_channel_service-v3.ts index ed4961d6a40..85398175164 100644 --- a/packages/google-cloud-monitoring/test/gapic-notification_channel_service-v3.ts +++ b/packages/google-cloud-monitoring/test/gapic-notification_channel_service-v3.ts @@ -88,6 +88,26 @@ describe('v3.NotificationChannelServiceClient', () => { ); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.notificationChannelServiceStub, undefined); + await client.initialize(); + assert(client.notificationChannelServiceStub); + }); + it('has close method', () => { + const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.close(); + }); describe('getNotificationChannelDescriptor', () => { it('invokes getNotificationChannelDescriptor without error', done => { const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient( @@ -96,6 +116,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetNotificationChannelDescriptorRequest = {}; request.name = ''; @@ -124,6 +146,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetNotificationChannelDescriptorRequest = {}; request.name = ''; @@ -154,6 +178,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetNotificationChannelRequest = {}; request.name = ''; @@ -179,6 +205,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetNotificationChannelRequest = {}; request.name = ''; @@ -206,6 +234,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateNotificationChannelRequest = {}; request.name = ''; @@ -231,6 +261,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateNotificationChannelRequest = {}; request.name = ''; @@ -261,6 +293,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateNotificationChannelRequest = {}; request.notificationChannel = {}; @@ -287,6 +321,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateNotificationChannelRequest = {}; request.notificationChannel = {}; @@ -318,6 +354,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteNotificationChannelRequest = {}; request.name = ''; @@ -343,6 +381,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteNotificationChannelRequest = {}; request.name = ''; @@ -373,6 +413,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ISendNotificationChannelVerificationCodeRequest = {}; request.name = ''; @@ -401,6 +443,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ISendNotificationChannelVerificationCodeRequest = {}; request.name = ''; @@ -431,6 +475,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetNotificationChannelVerificationCodeRequest = {}; request.name = ''; @@ -459,6 +505,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetNotificationChannelVerificationCodeRequest = {}; request.name = ''; @@ -489,6 +537,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IVerifyNotificationChannelRequest = {}; request.name = ''; @@ -514,6 +564,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IVerifyNotificationChannelRequest = {}; request.name = ''; @@ -544,6 +596,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListNotificationChannelDescriptorsRequest = {}; request.name = ''; @@ -576,6 +630,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListNotificationChannelDescriptorsRequest = {}; request.name = ''; @@ -610,6 +666,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListNotificationChannelsRequest = {}; request.name = ''; @@ -642,6 +700,8 @@ describe('v3.NotificationChannelServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListNotificationChannelsRequest = {}; request.name = ''; diff --git a/packages/google-cloud-monitoring/test/gapic-service_monitoring_service-v3.ts b/packages/google-cloud-monitoring/test/gapic-service_monitoring_service-v3.ts index d6b905d5bc0..f72b50dbf60 100644 --- a/packages/google-cloud-monitoring/test/gapic-service_monitoring_service-v3.ts +++ b/packages/google-cloud-monitoring/test/gapic-service_monitoring_service-v3.ts @@ -88,6 +88,26 @@ describe('v3.ServiceMonitoringServiceClient', () => { ); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.serviceMonitoringServiceStub, undefined); + await client.initialize(); + assert(client.serviceMonitoringServiceStub); + }); + it('has close method', () => { + const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.close(); + }); describe('createService', () => { it('invokes createService without error', done => { const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient( @@ -96,6 +116,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateServiceRequest = {}; request.parent = ''; @@ -121,6 +143,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateServiceRequest = {}; request.parent = ''; @@ -148,6 +172,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetServiceRequest = {}; request.name = ''; @@ -173,6 +199,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetServiceRequest = {}; request.name = ''; @@ -200,6 +228,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateServiceRequest = {}; request.service = {}; @@ -226,6 +256,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateServiceRequest = {}; request.service = {}; @@ -254,6 +286,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteServiceRequest = {}; request.name = ''; @@ -279,6 +313,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteServiceRequest = {}; request.name = ''; @@ -306,6 +342,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateServiceLevelObjectiveRequest = {}; request.parent = ''; @@ -331,6 +369,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateServiceLevelObjectiveRequest = {}; request.parent = ''; @@ -361,6 +401,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetServiceLevelObjectiveRequest = {}; request.name = ''; @@ -386,6 +428,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetServiceLevelObjectiveRequest = {}; request.name = ''; @@ -416,6 +460,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateServiceLevelObjectiveRequest = {}; request.serviceLevelObjective = {}; @@ -442,6 +488,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateServiceLevelObjectiveRequest = {}; request.serviceLevelObjective = {}; @@ -473,6 +521,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteServiceLevelObjectiveRequest = {}; request.name = ''; @@ -498,6 +548,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteServiceLevelObjectiveRequest = {}; request.name = ''; @@ -528,6 +580,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListServicesRequest = {}; request.parent = ''; @@ -557,6 +611,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListServicesRequest = {}; request.parent = ''; @@ -591,6 +647,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListServiceLevelObjectivesRequest = {}; request.parent = ''; @@ -623,6 +681,8 @@ describe('v3.ServiceMonitoringServiceClient', () => { projectId: 'bogus', } ); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListServiceLevelObjectivesRequest = {}; request.parent = ''; diff --git a/packages/google-cloud-monitoring/test/gapic-uptime_check_service-v3.ts b/packages/google-cloud-monitoring/test/gapic-uptime_check_service-v3.ts index 3266e39ebe8..ae479840769 100644 --- a/packages/google-cloud-monitoring/test/gapic-uptime_check_service-v3.ts +++ b/packages/google-cloud-monitoring/test/gapic-uptime_check_service-v3.ts @@ -83,12 +83,30 @@ describe('v3.UptimeCheckServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.uptimeCheckServiceStub, undefined); + await client.initialize(); + assert(client.uptimeCheckServiceStub); + }); + it('has close method', () => { + const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); describe('getUptimeCheckConfig', () => { it('invokes getUptimeCheckConfig without error', done => { const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetUptimeCheckConfigRequest = {}; request.name = ''; @@ -112,6 +130,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IGetUptimeCheckConfigRequest = {}; request.name = ''; @@ -137,6 +157,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateUptimeCheckConfigRequest = {}; request.parent = ''; @@ -160,6 +182,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.ICreateUptimeCheckConfigRequest = {}; request.parent = ''; @@ -188,6 +212,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateUptimeCheckConfigRequest = {}; request.uptimeCheckConfig = {}; @@ -212,6 +238,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IUpdateUptimeCheckConfigRequest = {}; request.uptimeCheckConfig = {}; @@ -241,6 +269,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteUptimeCheckConfigRequest = {}; request.name = ''; @@ -264,6 +294,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IDeleteUptimeCheckConfigRequest = {}; request.name = ''; @@ -292,6 +324,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListUptimeCheckConfigsRequest = {}; request.parent = ''; @@ -319,6 +353,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListUptimeCheckConfigsRequest = {}; request.parent = ''; @@ -351,6 +387,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListUptimeCheckIpsRequest = {}; // Mock response @@ -377,6 +415,8 @@ describe('v3.UptimeCheckServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.monitoring.v3.IListUptimeCheckIpsRequest = {}; // Mock response