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

Commit

Permalink
feat: add minimum wrapper for compute LRO method (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
summer-ji-eng authored Sep 13, 2021
1 parent 0ff67e6 commit 2fa4f93
Show file tree
Hide file tree
Showing 153 changed files with 10,457 additions and 3,642 deletions.
35 changes: 20 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
"disks",
"disk types",
"external vpn gateways",
"firewall policies",
"firewalls",
"forwarding rules",
"global addresses",
"global forwarding rules",
"global network endpoint groups",
"global operations",
"global organization operations",
"global public delegated prefixes",
"health checks",
"images",
"instance group managers",
Expand All @@ -58,6 +60,8 @@
"node types",
"packet mirrorings",
"projects",
"public advertised prefixes",
"public delegated prefixes",
"region autoscalers",
"region backend services",
"region commitments",
Expand All @@ -67,6 +71,7 @@
"region health check services",
"region instance group managers",
"region instance groups",
"region instances",
"region network endpoint groups",
"region notification endpoints",
"region operations",
Expand Down Expand Up @@ -115,27 +120,27 @@
"precompile": "gts clean"
},
"dependencies": {
"google-gax": "^2.24.1"
"google-gax": "^2.25.2"
},
"devDependencies": {
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.13",
"@types/sinon": "^10.0.0",
"c8": "^7.3.5",
"@types/mocha": "^9.0.0",
"@types/node": "^14.17.3",
"@types/sinon": "^10.0.2",
"c8": "^7.7.3",
"chai": "^4.3.4",
"gts": "^3.1.0",
"jsdoc": "^3.6.6",
"jsdoc-fresh": "^1.0.2",
"jsdoc-region-tag": "^1.0.6",
"linkinator": "^2.8.0",
"mocha": "^8.2.1",
"jsdoc": "^3.6.7",
"jsdoc-fresh": "^1.1.0",
"jsdoc-region-tag": "^1.1.0",
"linkinator": "^2.13.6",
"mocha": "^9.0.2",
"null-loader": "^4.0.1",
"pack-n-play": "^1.0.0-2",
"sinon": "^11.0.0",
"ts-loader": "^9.0.0",
"typescript": "^4.1.3",
"sinon": "^11.1.1",
"ts-loader": "^9.2.3",
"typescript": "^4.3.4",
"uuid": "^8.0.0",
"webpack": "^5.10.1",
"webpack-cli": "^4.2.0"
"webpack": "^5.39.1",
"webpack-cli": "^4.7.2"
}
}
3 changes: 2 additions & 1 deletion protos/protos.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions protos/protos.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion protos/protos.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions samples/createInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function main(

console.log(`Creating the ${instanceName} instance in ${zone}...`);

let [operation] = await instancesClient.insert({
const [response] = await instancesClient.insert({
instanceResource: {
name: instanceName,
disks: [
Expand All @@ -86,7 +86,7 @@ function main(
project: projectId,
zone,
});

let operation = response.latestResponse;
const operationsClient = new compute.ZoneOperationsClient();

// Wait for the create operation to complete.
Expand Down
4 changes: 2 additions & 2 deletions samples/deleteInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ function main(projectId, zone, instanceName) {

console.log(`Deleting ${instanceName} from ${zone}...`);

let [operation] = await instancesClient.delete({
const [response] = await instancesClient.delete({
project: projectId,
zone,
instance: instanceName,
});

let operation = response.latestResponse;
const operationsClient = new compute.ZoneOperationsClient();

// Wait for the delete operation to complete.
Expand Down
4 changes: 2 additions & 2 deletions samples/disableUsageExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ function main(projectId) {
const operationsClient = new compute.GlobalOperationsClient();

// Updating the setting with empty usageExportLocationResource will disable the usage report generation.
let [operation] = await projectsClient.setUsageExportBucket({
const [response] = await projectsClient.setUsageExportBucket({
project: projectId,
usageExportLocationResource: {},
});

let operation = response.latestResponse;
while (operation.status !== 'DONE') {
[operation] = await operationsClient.wait({
operation: operation.name,
Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "mocha test --timeout 1200000"
},
"dependencies": {
"@google-cloud/compute": "^3.0.0",
"@google-cloud/compute": "^3.0.0-alpha.4",
"@sendgrid/mail": "^7.0.0",
"nodemailer": "^6.0.0",
"nodemailer-smtp-transport": "^2.7.4"
Expand Down
4 changes: 2 additions & 2 deletions samples/test/samples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ describe('samples', () => {

execSync(`node createInstance ${projectId} ${zone} ${newinstanceName}`);

const [operation] = await instancesClient.delete({
const [response] = await instancesClient.delete({
project: projectId,
zone,
instance: newinstanceName,
});

const operationString = JSON.stringify(operation);
const operationString = JSON.stringify(response.latestResponse);

const output = execSync(
`node waitForOperation ${projectId} '${operationString}'`
Expand Down
3 changes: 3 additions & 0 deletions src/v1/accelerator_types_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ export class AcceleratorTypesClient {
// Save the auth object to the client, for use by other methods.
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;

// Set defaultServicePath on the auth object.
this.auth.defaultServicePath = staticMembers.servicePath;

// Set the default scopes in auth client if needed.
if (servicePath === staticMembers.servicePath) {
this.auth.defaultScopes = staticMembers.scopes;
Expand Down
86 changes: 70 additions & 16 deletions src/v1/addresses_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CallOptions,
Descriptors,
ClientOptions,
LROperation,
PaginationCallback,
GaxCall,
} from 'google-gax';
Expand Down Expand Up @@ -136,6 +137,9 @@ export class AddressesClient {
// Save the auth object to the client, for use by other methods.
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;

// Set defaultServicePath on the auth object.
this.auth.defaultServicePath = staticMembers.servicePath;

// Set the default scopes in auth client if needed.
if (servicePath === staticMembers.servicePath) {
this.auth.defaultScopes = staticMembers.scopes;
Expand Down Expand Up @@ -320,8 +324,8 @@ export class AddressesClient {
options?: CallOptions
): Promise<
[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IDeleteAddressRequest | undefined,
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
protos.google.cloud.compute.v1.IOperation | undefined,
{} | undefined
]
>;
Expand Down Expand Up @@ -362,12 +366,17 @@ export class AddressesClient {
* @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.
* The first element of the array is an object representing [Operation]{@link google.cloud.compute.v1.Operation}.
* The first element of the array is an object representing
* a long running operation.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
* for more details and examples.
* This method is considered to be in beta. This means while
* stable it is still a work-in-progress and under active development,
* and might get backwards-incompatible changes at any time.
* `.promise()` is not supported yet.
* @example
* const [response] = await client.delete(request);
* const [operation] = await client.delete(request);
*/
delete(
request?: protos.google.cloud.compute.v1.IDeleteAddressRequest,
Expand All @@ -387,8 +396,8 @@ export class AddressesClient {
>
): Promise<
[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IDeleteAddressRequest | undefined,
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
protos.google.cloud.compute.v1.IOperation | undefined,
{} | undefined
]
> | void {
Expand All @@ -408,7 +417,27 @@ export class AddressesClient {
project: request.project || '',
});
this.initialize();
return this.innerApiCalls.delete(request, options, callback);
return this.innerApiCalls
.delete(request, options, callback)
.then(
([response, operation, rawResponse]: [
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IOperation
]) => {
return [
{
latestResponse: response,
done: false,
name: response.id,
metadata: null,
result: {},
},
operation,
rawResponse,
];
}
);
}
get(
request?: protos.google.cloud.compute.v1.IGetAddressRequest,
Expand Down Expand Up @@ -502,8 +531,8 @@ export class AddressesClient {
options?: CallOptions
): Promise<
[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IInsertAddressRequest | undefined,
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
protos.google.cloud.compute.v1.IOperation | undefined,
{} | undefined
]
>;
Expand Down Expand Up @@ -544,12 +573,17 @@ export class AddressesClient {
* @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.
* The first element of the array is an object representing [Operation]{@link google.cloud.compute.v1.Operation}.
* The first element of the array is an object representing
* a long running operation.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
* for more details and examples.
* This method is considered to be in beta. This means while
* stable it is still a work-in-progress and under active development,
* and might get backwards-incompatible changes at any time.
* `.promise()` is not supported yet.
* @example
* const [response] = await client.insert(request);
* const [operation] = await client.insert(request);
*/
insert(
request?: protos.google.cloud.compute.v1.IInsertAddressRequest,
Expand All @@ -569,8 +603,8 @@ export class AddressesClient {
>
): Promise<
[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IInsertAddressRequest | undefined,
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
protos.google.cloud.compute.v1.IOperation | undefined,
{} | undefined
]
> | void {
Expand All @@ -590,7 +624,27 @@ export class AddressesClient {
project: request.project || '',
});
this.initialize();
return this.innerApiCalls.insert(request, options, callback);
return this.innerApiCalls
.insert(request, options, callback)
.then(
([response, operation, rawResponse]: [
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IOperation
]) => {
return [
{
latestResponse: response,
done: false,
name: response.id,
metadata: null,
result: {},
},
operation,
rawResponse,
];
}
);
}

/**
Expand Down
Loading

0 comments on commit 2fa4f93

Please sign in to comment.