Skip to content

Commit

Permalink
docs(samples): include metadata file, add exclusions for samples to h…
Browse files Browse the repository at this point in the history
…andwritten libraries (#106)

- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 429395631

Source-Link: googleapis/googleapis@84594b3

Source-Link: googleapis/googleapis-gen@ed74f97
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWQ3NGY5NzBmZDgyOTE0ODc0ZTZiMjdiMDQ3NjNjZmE2NmJhZmU5YiJ9
  • Loading branch information
gcf-owl-bot[bot] committed Feb 18, 2022
1 parent dd271ad commit abefb54
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,8 @@ export class QuotaControllerClient {
* @returns {Promise} A promise that resolves when the client is closed.
*/
close(): Promise<void> {
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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,8 @@ export class ServiceControllerClient {
* @returns {Promise} A promise that resolves when the client is closed.
*/
close(): Promise<void> {
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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit abefb54

Please sign in to comment.