diff --git a/packages/google-api-servicecontrol/samples/generated/v1/quota_controller.allocate_quota.js b/packages/google-api-servicecontrol/samples/generated/v1/quota_controller.allocate_quota.js index 8b493cf9b19..554e011613d 100644 --- a/packages/google-api-servicecontrol/samples/generated/v1/quota_controller.allocate_quota.js +++ b/packages/google-api-servicecontrol/samples/generated/v1/quota_controller.allocate_quota.js @@ -1,16 +1,21 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + 'use strict'; diff --git a/packages/google-api-servicecontrol/samples/generated/v1/service_controller.check.js b/packages/google-api-servicecontrol/samples/generated/v1/service_controller.check.js index d011fb9bf8d..84c1b362973 100644 --- a/packages/google-api-servicecontrol/samples/generated/v1/service_controller.check.js +++ b/packages/google-api-servicecontrol/samples/generated/v1/service_controller.check.js @@ -1,16 +1,21 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + 'use strict'; diff --git a/packages/google-api-servicecontrol/samples/generated/v1/service_controller.report.js b/packages/google-api-servicecontrol/samples/generated/v1/service_controller.report.js index 670446deca5..40ce69511f5 100644 --- a/packages/google-api-servicecontrol/samples/generated/v1/service_controller.report.js +++ b/packages/google-api-servicecontrol/samples/generated/v1/service_controller.report.js @@ -1,16 +1,21 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + 'use strict'; diff --git a/packages/google-api-servicecontrol/samples/generated/v1/snippet_metadata.google.api.servicecontrol.v1.json b/packages/google-api-servicecontrol/samples/generated/v1/snippet_metadata.google.api.servicecontrol.v1.json new file mode 100644 index 00000000000..8b1d2613bea --- /dev/null +++ b/packages/google-api-servicecontrol/samples/generated/v1/snippet_metadata.google.api.servicecontrol.v1.json @@ -0,0 +1,159 @@ +{ + "clientLibrary": { + "name": "nodejs-servicecontrol", + "version": "0.1.0", + "language": "TYPESCRIPT", + "apis": [ + { + "id": "google.api.servicecontrol.v1", + "version": "v1" + } + ] + }, + "snippets": [ + { + "regionTag": "servicecontrol_v1_generated_QuotaController_AllocateQuota_async", + "title": "QuotaController allocateQuota Sample", + "origin": "API_DEFINITION", + "description": " Attempts to allocate quota for the specified consumer. It should be called before the operation is executed. This method requires the `servicemanagement.services.quota` permission on the specified service. For more information, see [Cloud IAM](https://cloud.google.com/iam). **NOTE:** The client **must** fail-open on server errors `INTERNAL`, `UNKNOWN`, `DEADLINE_EXCEEDED`, and `UNAVAILABLE`. To ensure system reliability, the server may inject these errors to prohibit any hard dependency on the quota functionality.", + "canonical": true, + "file": "quota_controller.allocate_quota.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 61, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "AllocateQuota", + "fullName": "google.api.servicecontrol.v1.QuotaController.AllocateQuota", + "async": true, + "parameters": [ + { + "name": "service_name", + "type": "TYPE_STRING" + }, + { + "name": "allocate_operation", + "type": ".google.api.servicecontrol.v1.QuotaOperation" + }, + { + "name": "service_config_id", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.api.servicecontrol.v1.AllocateQuotaResponse", + "client": { + "shortName": "QuotaControllerClient", + "fullName": "google.api.servicecontrol.v1.QuotaControllerClient" + }, + "method": { + "shortName": "AllocateQuota", + "fullName": "google.api.servicecontrol.v1.QuotaController.AllocateQuota", + "service": { + "shortName": "QuotaController", + "fullName": "google.api.servicecontrol.v1.QuotaController" + } + } + } + }, + { + "regionTag": "servicecontrol_v1_generated_ServiceController_Check_async", + "title": "QuotaController check Sample", + "origin": "API_DEFINITION", + "description": " Checks whether an operation on a service should be allowed to proceed based on the configuration of the service and related policies. It must be called before the operation is executed. If feasible, the client should cache the check results and reuse them for 60 seconds. In case of any server errors, the client should rely on the cached results for much longer time to avoid outage. WARNING: There is general 60s delay for the configuration and policy propagation, therefore callers MUST NOT depend on the `Check` method having the latest policy information. NOTE: the [CheckRequest][google.api.servicecontrol.v1.CheckRequest] has the size limit (wire-format byte size) of 1MB. This method requires the `servicemanagement.services.check` permission on the specified service. For more information, see [Cloud IAM](https://cloud.google.com/iam).", + "canonical": true, + "file": "service_controller.check.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 64, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "Check", + "fullName": "google.api.servicecontrol.v1.ServiceController.Check", + "async": true, + "parameters": [ + { + "name": "service_name", + "type": "TYPE_STRING" + }, + { + "name": "operation", + "type": ".google.api.servicecontrol.v1.Operation" + }, + { + "name": "service_config_id", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.api.servicecontrol.v1.CheckResponse", + "client": { + "shortName": "ServiceControllerClient", + "fullName": "google.api.servicecontrol.v1.ServiceControllerClient" + }, + "method": { + "shortName": "Check", + "fullName": "google.api.servicecontrol.v1.ServiceController.Check", + "service": { + "shortName": "ServiceController", + "fullName": "google.api.servicecontrol.v1.ServiceController" + } + } + } + }, + { + "regionTag": "servicecontrol_v1_generated_ServiceController_Report_async", + "title": "QuotaController report Sample", + "origin": "API_DEFINITION", + "description": " Reports operation results to Google Service Control, such as logs and metrics. It should be called after an operation is completed. If feasible, the client should aggregate reporting data for up to 5 seconds to reduce API traffic. Limiting aggregation to 5 seconds is to reduce data loss during client crashes. Clients should carefully choose the aggregation time window to avoid data loss risk more than 0.01% for business and compliance reasons. NOTE: the [ReportRequest][google.api.servicecontrol.v1.ReportRequest] has the size limit (wire-format byte size) of 1MB. This method requires the `servicemanagement.services.report` permission on the specified service. For more information, see [Google Cloud IAM](https://cloud.google.com/iam).", + "canonical": true, + "file": "service_controller.report.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 72, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "Report", + "fullName": "google.api.servicecontrol.v1.ServiceController.Report", + "async": true, + "parameters": [ + { + "name": "service_name", + "type": "TYPE_STRING" + }, + { + "name": "operations", + "type": "TYPE_MESSAGE[]" + }, + { + "name": "service_config_id", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.api.servicecontrol.v1.ReportResponse", + "client": { + "shortName": "ServiceControllerClient", + "fullName": "google.api.servicecontrol.v1.ServiceControllerClient" + }, + "method": { + "shortName": "Report", + "fullName": "google.api.servicecontrol.v1.ServiceController.Report", + "service": { + "shortName": "ServiceController", + "fullName": "google.api.servicecontrol.v1.ServiceController" + } + } + } + } + ] +} diff --git a/packages/google-api-servicecontrol/src/v1/quota_controller_client.ts b/packages/google-api-servicecontrol/src/v1/quota_controller_client.ts index 27e36f511e4..ca876457640 100644 --- a/packages/google-api-servicecontrol/src/v1/quota_controller_client.ts +++ b/packages/google-api-servicecontrol/src/v1/quota_controller_client.ts @@ -405,9 +405,8 @@ export class QuotaControllerClient { * @returns {Promise} A promise that resolves when the client is closed. */ close(): Promise { - this.initialize(); - if (!this._terminated) { - return this.quotaControllerStub!.then(stub => { + if (this.quotaControllerStub && !this._terminated) { + return this.quotaControllerStub.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-api-servicecontrol/src/v1/service_controller_client.ts b/packages/google-api-servicecontrol/src/v1/service_controller_client.ts index 98ce3470d5d..5d6e626f358 100644 --- a/packages/google-api-servicecontrol/src/v1/service_controller_client.ts +++ b/packages/google-api-servicecontrol/src/v1/service_controller_client.ts @@ -527,9 +527,8 @@ export class ServiceControllerClient { * @returns {Promise} A promise that resolves when the client is closed. */ close(): Promise { - this.initialize(); - if (!this._terminated) { - return this.serviceControllerStub!.then(stub => { + if (this.serviceControllerStub && !this._terminated) { + return this.serviceControllerStub.then(stub => { this._terminated = true; stub.close(); }); diff --git a/packages/google-api-servicecontrol/test/gapic_quota_controller_v1.ts b/packages/google-api-servicecontrol/test/gapic_quota_controller_v1.ts index b43c3478a28..15072bf5fd0 100644 --- a/packages/google-api-servicecontrol/test/gapic_quota_controller_v1.ts +++ b/packages/google-api-servicecontrol/test/gapic_quota_controller_v1.ts @@ -90,12 +90,27 @@ describe('v1.QuotaControllerClient', () => { assert(client.quotaControllerStub); }); - it('has close method', () => { + it('has close method for the initialized client', done => { const client = new quotacontrollerModule.v1.QuotaControllerClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); - client.close(); + client.initialize(); + assert(client.quotaControllerStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new quotacontrollerModule.v1.QuotaControllerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.quotaControllerStub, undefined); + client.close().then(() => { + done(); + }); }); it('has getProjectId method', async () => { @@ -241,5 +256,21 @@ describe('v1.QuotaControllerClient', () => { .calledWith(request, expectedOptions, undefined) ); }); + + it('invokes allocateQuota with closed client', async () => { + const client = new quotacontrollerModule.v1.QuotaControllerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.api.servicecontrol.v1.AllocateQuotaRequest() + ); + request.serviceName = ''; + const expectedHeaderRequestParams = 'service_name='; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.allocateQuota(request), expectedError); + }); }); }); diff --git a/packages/google-api-servicecontrol/test/gapic_service_controller_v1.ts b/packages/google-api-servicecontrol/test/gapic_service_controller_v1.ts index bf0093d7a86..7340e9cbc56 100644 --- a/packages/google-api-servicecontrol/test/gapic_service_controller_v1.ts +++ b/packages/google-api-servicecontrol/test/gapic_service_controller_v1.ts @@ -90,12 +90,27 @@ describe('v1.ServiceControllerClient', () => { assert(client.serviceControllerStub); }); - it('has close method', () => { + it('has close method for the initialized client', done => { const client = new servicecontrollerModule.v1.ServiceControllerClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); - client.close(); + client.initialize(); + assert(client.serviceControllerStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new servicecontrollerModule.v1.ServiceControllerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.serviceControllerStub, undefined); + client.close().then(() => { + done(); + }); }); it('has getProjectId method', async () => { @@ -237,6 +252,22 @@ describe('v1.ServiceControllerClient', () => { .calledWith(request, expectedOptions, undefined) ); }); + + it('invokes check with closed client', async () => { + const client = new servicecontrollerModule.v1.ServiceControllerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.api.servicecontrol.v1.CheckRequest() + ); + request.serviceName = ''; + const expectedHeaderRequestParams = 'service_name='; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.check(request), expectedError); + }); }); describe('report', () => { @@ -345,5 +376,21 @@ describe('v1.ServiceControllerClient', () => { .calledWith(request, expectedOptions, undefined) ); }); + + it('invokes report with closed client', async () => { + const client = new servicecontrollerModule.v1.ServiceControllerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.api.servicecontrol.v1.ReportRequest() + ); + request.serviceName = ''; + const expectedHeaderRequestParams = 'service_name='; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.report(request), expectedError); + }); }); });