From 2947b1bc85c76532c990f898abdc422269d1b806 Mon Sep 17 00:00:00 2001 From: Donghe Zhao Date: Fri, 20 Nov 2020 07:43:37 +0000 Subject: [PATCH 01/10] add sample of analyzeIamPolicy --- samples/analyzeIamPolicy.js | 57 +++++++++++++++++++++++++++++++++++++ samples/test/sample.test.js | 6 ++++ 2 files changed, 63 insertions(+) create mode 100644 samples/analyzeIamPolicy.js diff --git a/samples/analyzeIamPolicy.js b/samples/analyzeIamPolicy.js new file mode 100644 index 00000000..69cca91e --- /dev/null +++ b/samples/analyzeIamPolicy.js @@ -0,0 +1,57 @@ +// Copyright 2020 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 +// +// 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. + +'use strict'; + +// sample-metadata: +// title: Analyze Iam Policy +// description: Analyzes accessible IAM policies that match a request. +// usage: node analyzeIamPolicy + +async function main() { + // [START asset_quickstart_analyze_iam_policy] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset'); + + const client = new AssetServiceClient(); + const projectId = await client.getProjectId(); + + async function analyzeIamPolicy() { + const request = { + analysisQuery: { + scope: `projects/${projectId}`, + resourceSelector: { + fullResourceName: + `//cloudresourcemanager.googleapis.com/projects/${projectId}` + }, + options: { + expandGroups: true, + outputGroupEdges: true, + }, + } + }; + + // Handle the operation using the promise pattern. + const result = await client.analyzeIamPolicy(request); + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + } + // [END asset_quickstart_analyze_iam_policy] + analyzeIamPolicy(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/samples/test/sample.test.js b/samples/test/sample.test.js index 30be671a..0c21046f 100644 --- a/samples/test/sample.test.js +++ b/samples/test/sample.test.js @@ -99,4 +99,10 @@ describe('quickstart sample tests', () => { const stdout = execSync(`node listAssets ${assetType}`); assert.include(stdout, assetType); }); + + it('should analyze iam policy successfully', async () => { + const stdout = execSync(`node analyzeIamPolicy`); + assert.include(stdout, '//cloudresourcemanager.googleapis.com/projects'); + }); }); + From b3fb6aa1f636c112e804abf658a39401019cee90 Mon Sep 17 00:00:00 2001 From: Donghe Zhao Date: Fri, 20 Nov 2020 22:51:24 +0000 Subject: [PATCH 02/10] adding samples for analyzeIamPolicyLongrunningGcs --- samples/analyzeIamPolicyLongrunningGcs.js | 73 +++++++++++++++++++++++ samples/test/sample.test.js | 16 ++++- 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 samples/analyzeIamPolicyLongrunningGcs.js diff --git a/samples/analyzeIamPolicyLongrunningGcs.js b/samples/analyzeIamPolicyLongrunningGcs.js new file mode 100644 index 00000000..1ddbe73a --- /dev/null +++ b/samples/analyzeIamPolicyLongrunningGcs.js @@ -0,0 +1,73 @@ +// Copyright 2020 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 +// +// 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. + +'use strict'; + +// sample-metadata: +// title: Analyze Iam Policy Longrunning and write results to GCS +// description: Analyzes accessible IAM policies that match a request. +// usage: node analyzeIamPolicyLongrunningGcsLongrunningGcs +// + +async function main(gcsUri) { + // [START asset_quickstart_analyze_iam_policy_longrunning_gcs] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset'); + + const client = new AssetServiceClient(); + const projectId = await client.getProjectId(); + + async function analyzeIamPolicyLongrunningGcs() { + // TODO(developer): choose the gcs path uri + // const gcsUri = 'Gcs path uri, e.g.: gs:///' + + const request = { + analysisQuery: { + scope: `projects/${projectId}`, + resourceSelector: { + fullResourceName: + `//cloudresourcemanager.googleapis.com/projects/${projectId}` + }, + options: { + expandGroups: true, + outputGroupEdges: true, + }, + }, + outputConfig: { + gcsDestination: { + uri: gcsUri, + }, + } + }; + + // Handle the operation using the promise pattern. + const [operation] = await client.analyzeIamPolicyLongrunning(request); + + // Operation#promise starts polling for the completion of the operation. + const [result] = await operation.promise(); + + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + } + // [END asset_quickstart_analyze_iam_policy_longrunning_gcs] + // analyzeIamPolicyLongrunningGcs(); + analyzeIamPolicyLongrunningGcs().catch(err => { + console.error(err.message); + }); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/samples/test/sample.test.js b/samples/test/sample.test.js index 0c21046f..1fb57a07 100644 --- a/samples/test/sample.test.js +++ b/samples/test/sample.test.js @@ -37,7 +37,7 @@ let vm; // "Timeout of 180000ms exceeded. For async tests and hooks". const delay = async test => { const retries = test.currentRetry(); - if (retries === 0) return; // no retry on the first failure. + if (retries === 0) return; // no retry on the first failure. // see: https://cloud.google.com/storage/docs/exponential-backoff: const ms = Math.pow(2, retries) * 1000 + Math.random() * 2000; return new Promise(done => { @@ -57,7 +57,7 @@ describe('quickstart sample tests', () => { await vm.delete(); }); - it('should export assets to specified path', async function () { + it('should export assets to specified path', async function() { this.retries(2); await delay(this.test); const dumpFilePath = `gs://${bucketName}/my-assets.txt`; @@ -104,5 +104,17 @@ describe('quickstart sample tests', () => { const stdout = execSync(`node analyzeIamPolicy`); assert.include(stdout, '//cloudresourcemanager.googleapis.com/projects'); }); + + it('should analyze iam policy and write analysis results to gcs successfully', + async function() { + this.retries(2); + await delay(this.test); + const uri = `gs://${bucketName}/my-analysis.json`; + execSync(`node analyzeIamPolicyLongrunningGcs ${uri}`); + const file = await bucket.file('my-analysis.json'); + const exists = await file.exists(); + assert.ok(exists); + await file.delete(); + }); }); From 614012c483ba1868463c1bb0f4b7e69b0ec5a939 Mon Sep 17 00:00:00 2001 From: Donghe Zhao Date: Sat, 21 Nov 2020 00:41:33 +0000 Subject: [PATCH 03/10] remove unnecessary comments --- samples/analyzeIamPolicyLongrunningGcs.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/analyzeIamPolicyLongrunningGcs.js b/samples/analyzeIamPolicyLongrunningGcs.js index 1ddbe73a..80f6a64b 100644 --- a/samples/analyzeIamPolicyLongrunningGcs.js +++ b/samples/analyzeIamPolicyLongrunningGcs.js @@ -17,7 +17,7 @@ // sample-metadata: // title: Analyze Iam Policy Longrunning and write results to GCS // description: Analyzes accessible IAM policies that match a request. -// usage: node analyzeIamPolicyLongrunningGcsLongrunningGcs +// usage: node analyzeIamPolicyLongrunningGcs // async function main(gcsUri) { @@ -61,7 +61,6 @@ async function main(gcsUri) { console.log(util.inspect(result, {depth: null})); } // [END asset_quickstart_analyze_iam_policy_longrunning_gcs] - // analyzeIamPolicyLongrunningGcs(); analyzeIamPolicyLongrunningGcs().catch(err => { console.error(err.message); }); From 14086dbc6dfe297cae77af98e75a9148edc54279 Mon Sep 17 00:00:00 2001 From: Donghe Zhao Date: Sat, 21 Nov 2020 01:17:37 +0000 Subject: [PATCH 04/10] adding samples for analyzeIamPolicyLongrunningBigquery --- .../analyzeIamPolicyLongrunningBigquery.js | 73 +++++++++++++++++++ samples/package.json | 2 + samples/test/sample.test.js | 30 +++++++- 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 samples/analyzeIamPolicyLongrunningBigquery.js diff --git a/samples/analyzeIamPolicyLongrunningBigquery.js b/samples/analyzeIamPolicyLongrunningBigquery.js new file mode 100644 index 00000000..3711beb7 --- /dev/null +++ b/samples/analyzeIamPolicyLongrunningBigquery.js @@ -0,0 +1,73 @@ +// Copyright 2020 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 +// +// 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. + +'use strict'; + +// sample-metadata: +// title: Analyze Iam Policy Longrunning and write results to Bigquery +// description: Analyzes accessible IAM policies that match a request. +// usage: node analyzeIamPolicyLongrunningBigquery + +async function main(datasetId, tablePrefix) { + // [START asset_quickstart_analyze_iam_policy_longrunning_bigquery] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset'); + + const client = new AssetServiceClient(); + const projectId = await client.getProjectId(); + + async function analyzeIamPolicyLongrunningBigquery() { + // TODO(developer): choose the dataset and table prefix + // const datasetId = '' + // const tablePrefix = '' + + const request = { + analysisQuery: { + scope: `projects/${projectId}`, + resourceSelector: { + fullResourceName: + `//cloudresourcemanager.googleapis.com/projects/${projectId}` + }, + options: { + expandGroups: true, + outputGroupEdges: true, + }, + }, + outputConfig: { + bigqueryDestination: { + dataset: `projects/${projectId}/datasets/${datasetId}`, + tablePrefix: tablePrefix, + }, + } + }; + + // Handle the operation using the promise pattern. + const [operation] = await client.analyzeIamPolicyLongrunning(request); + + // Operation#promise starts polling for the completion of the operation. + const [result] = await operation.promise(); + + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + } + // [END asset_quickstart_analyze_iam_policy_longrunning_bigquery] + analyzeIamPolicyLongrunningBigquery().catch(err => { + console.error(err.message); + }); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/samples/package.json b/samples/package.json index 9de361fd..8e391a6c 100644 --- a/samples/package.json +++ b/samples/package.json @@ -16,8 +16,10 @@ }, "dependencies": { "@google-cloud/asset": "^3.9.1", + "@google-cloud/bigquery": "^5.5.0", "@google-cloud/compute": "^2.0.0", "@google-cloud/storage": "^5.0.0", + "express": "^4.17.1", "uuid": "^8.0.0", "yargs": "^16.0.0" }, diff --git a/samples/test/sample.test.js b/samples/test/sample.test.js index 1fb57a07..0feae31f 100644 --- a/samples/test/sample.test.js +++ b/samples/test/sample.test.js @@ -26,6 +26,13 @@ const storage = new Storage(); const bucketName = `asset-nodejs-${uuid.v4()}`; const bucket = storage.bucket(bucketName); +const {BigQuery} = require('@google-cloud/bigquery'); +const bigquery = new BigQuery(); +const options = { + location: 'US', +}; +const datasetId = `asset_nodejs_${uuid.v4()}`.replace(/-/gi, '_'); + const Compute = require('@google-cloud/compute'); const zone = new Compute().zone('us-central1-c'); const vmName = `asset-nodejs-${uuid.v4()}`; @@ -49,11 +56,14 @@ const delay = async test => { describe('quickstart sample tests', () => { before(async () => { await bucket.create(); + await bigquery.createDataset(datasetId, options); + await bigquery.dataset(datasetId).exists(); [vm] = await zone.createVM(vmName, {os: 'ubuntu'}); }); after(async () => { await bucket.delete(); + await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn); await vm.delete(); }); @@ -116,5 +126,23 @@ describe('quickstart sample tests', () => { assert.ok(exists); await file.delete(); }); -}); + it('should analyze iam policy and write analysis results to bigquery successfully', + async function() { + this.retries(2); + await delay(this.test); + const tablePrefix = 'analysis_nodejs'; + execSync(`node analyzeIamPolicyLongrunningBigquery ${datasetId} ${ + tablePrefix}`); + const metadataTable = + await bigquery.dataset(datasetId).table('analysis_nodejs_analysis'); + const metadataTable_exists = await metadataTable.exists(); + assert.ok(metadataTable_exists); + const resultsTable = await bigquery.dataset(datasetId).table( + 'analysis_nodejs_analysis_result'); + const resultsTable_exists = await resultsTable.exists(); + assert.ok(resultsTable_exists); + await metadataTable.delete(); + await resultsTable.delete(); + }); +}); From 8f5d2ace5040e78d8fe30b90bf9f99f3fac030f2 Mon Sep 17 00:00:00 2001 From: Donghe Zhao Date: Sat, 21 Nov 2020 01:35:38 +0000 Subject: [PATCH 05/10] replace a string with single quote --- samples/test/sample.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/test/sample.test.js b/samples/test/sample.test.js index 0feae31f..15e14dd5 100644 --- a/samples/test/sample.test.js +++ b/samples/test/sample.test.js @@ -111,7 +111,7 @@ describe('quickstart sample tests', () => { }); it('should analyze iam policy successfully', async () => { - const stdout = execSync(`node analyzeIamPolicy`); + const stdout = execSync('node analyzeIamPolicy'); assert.include(stdout, '//cloudresourcemanager.googleapis.com/projects'); }); From 90ce94914b2d76085455dc515c109d5e64ff5a3b Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Wed, 27 Jan 2021 13:51:02 -0800 Subject: [PATCH 06/10] Update samples/analyzeIamPolicy.js --- samples/analyzeIamPolicy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/analyzeIamPolicy.js b/samples/analyzeIamPolicy.js index 69cca91e..72bba8e7 100644 --- a/samples/analyzeIamPolicy.js +++ b/samples/analyzeIamPolicy.js @@ -39,7 +39,7 @@ async function main() { expandGroups: true, outputGroupEdges: true, }, - } + }, }; // Handle the operation using the promise pattern. From 9eb4bd25ccb37264520742978a830917785d8564 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Wed, 27 Jan 2021 13:51:10 -0800 Subject: [PATCH 07/10] Update samples/analyzeIamPolicy.js --- samples/analyzeIamPolicy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/analyzeIamPolicy.js b/samples/analyzeIamPolicy.js index 72bba8e7..5b6d8d68 100644 --- a/samples/analyzeIamPolicy.js +++ b/samples/analyzeIamPolicy.js @@ -33,7 +33,7 @@ async function main() { scope: `projects/${projectId}`, resourceSelector: { fullResourceName: - `//cloudresourcemanager.googleapis.com/projects/${projectId}` + `//cloudresourcemanager.googleapis.com/projects/${projectId}`, }, options: { expandGroups: true, From 0923632944e22c8fc77e7fcfdcf148d028f75c19 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Wed, 27 Jan 2021 14:05:11 -0800 Subject: [PATCH 08/10] lint: fix formatting --- samples/analyzeIamPolicy.js | 3 +- .../analyzeIamPolicyLongrunningBigquery.js | 5 +- samples/analyzeIamPolicyLongrunningGcs.js | 5 +- samples/test/sample.test.js | 65 ++++++++++--------- 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/samples/analyzeIamPolicy.js b/samples/analyzeIamPolicy.js index 5b6d8d68..83fb7b25 100644 --- a/samples/analyzeIamPolicy.js +++ b/samples/analyzeIamPolicy.js @@ -32,8 +32,7 @@ async function main() { analysisQuery: { scope: `projects/${projectId}`, resourceSelector: { - fullResourceName: - `//cloudresourcemanager.googleapis.com/projects/${projectId}`, + fullResourceName: `//cloudresourcemanager.googleapis.com/projects/${projectId}`, }, options: { expandGroups: true, diff --git a/samples/analyzeIamPolicyLongrunningBigquery.js b/samples/analyzeIamPolicyLongrunningBigquery.js index 3711beb7..137be7bd 100644 --- a/samples/analyzeIamPolicyLongrunningBigquery.js +++ b/samples/analyzeIamPolicyLongrunningBigquery.js @@ -36,8 +36,7 @@ async function main(datasetId, tablePrefix) { analysisQuery: { scope: `projects/${projectId}`, resourceSelector: { - fullResourceName: - `//cloudresourcemanager.googleapis.com/projects/${projectId}` + fullResourceName: `//cloudresourcemanager.googleapis.com/projects/${projectId}`, }, options: { expandGroups: true, @@ -49,7 +48,7 @@ async function main(datasetId, tablePrefix) { dataset: `projects/${projectId}/datasets/${datasetId}`, tablePrefix: tablePrefix, }, - } + }, }; // Handle the operation using the promise pattern. diff --git a/samples/analyzeIamPolicyLongrunningGcs.js b/samples/analyzeIamPolicyLongrunningGcs.js index 80f6a64b..e6370eac 100644 --- a/samples/analyzeIamPolicyLongrunningGcs.js +++ b/samples/analyzeIamPolicyLongrunningGcs.js @@ -36,8 +36,7 @@ async function main(gcsUri) { analysisQuery: { scope: `projects/${projectId}`, resourceSelector: { - fullResourceName: - `//cloudresourcemanager.googleapis.com/projects/${projectId}` + fullResourceName: `//cloudresourcemanager.googleapis.com/projects/${projectId}`, }, options: { expandGroups: true, @@ -48,7 +47,7 @@ async function main(gcsUri) { gcsDestination: { uri: gcsUri, }, - } + }, }; // Handle the operation using the promise pattern. diff --git a/samples/test/sample.test.js b/samples/test/sample.test.js index 15e14dd5..141f2cb2 100644 --- a/samples/test/sample.test.js +++ b/samples/test/sample.test.js @@ -44,7 +44,7 @@ let vm; // "Timeout of 180000ms exceeded. For async tests and hooks". const delay = async test => { const retries = test.currentRetry(); - if (retries === 0) return; // no retry on the first failure. + if (retries === 0) return; // no retry on the first failure. // see: https://cloud.google.com/storage/docs/exponential-backoff: const ms = Math.pow(2, retries) * 1000 + Math.random() * 2000; return new Promise(done => { @@ -67,7 +67,7 @@ describe('quickstart sample tests', () => { await vm.delete(); }); - it('should export assets to specified path', async function() { + it('should export assets to specified path', async function () { this.retries(2); await delay(this.test); const dumpFilePath = `gs://${bucketName}/my-assets.txt`; @@ -115,34 +115,35 @@ describe('quickstart sample tests', () => { assert.include(stdout, '//cloudresourcemanager.googleapis.com/projects'); }); - it('should analyze iam policy and write analysis results to gcs successfully', - async function() { - this.retries(2); - await delay(this.test); - const uri = `gs://${bucketName}/my-analysis.json`; - execSync(`node analyzeIamPolicyLongrunningGcs ${uri}`); - const file = await bucket.file('my-analysis.json'); - const exists = await file.exists(); - assert.ok(exists); - await file.delete(); - }); - - it('should analyze iam policy and write analysis results to bigquery successfully', - async function() { - this.retries(2); - await delay(this.test); - const tablePrefix = 'analysis_nodejs'; - execSync(`node analyzeIamPolicyLongrunningBigquery ${datasetId} ${ - tablePrefix}`); - const metadataTable = - await bigquery.dataset(datasetId).table('analysis_nodejs_analysis'); - const metadataTable_exists = await metadataTable.exists(); - assert.ok(metadataTable_exists); - const resultsTable = await bigquery.dataset(datasetId).table( - 'analysis_nodejs_analysis_result'); - const resultsTable_exists = await resultsTable.exists(); - assert.ok(resultsTable_exists); - await metadataTable.delete(); - await resultsTable.delete(); - }); + it('should analyze iam policy and write analysis results to gcs successfully', async function () { + this.retries(2); + await delay(this.test); + const uri = `gs://${bucketName}/my-analysis.json`; + execSync(`node analyzeIamPolicyLongrunningGcs ${uri}`); + const file = await bucket.file('my-analysis.json'); + const exists = await file.exists(); + assert.ok(exists); + await file.delete(); + }); + + it('should analyze iam policy and write analysis results to bigquery successfully', async function () { + this.retries(2); + await delay(this.test); + const tablePrefix = 'analysis_nodejs'; + execSync( + `node analyzeIamPolicyLongrunningBigquery ${datasetId} ${tablePrefix}` + ); + const metadataTable = await bigquery + .dataset(datasetId) + .table('analysis_nodejs_analysis'); + const metadataTable_exists = await metadataTable.exists(); + assert.ok(metadataTable_exists); + const resultsTable = await bigquery + .dataset(datasetId) + .table('analysis_nodejs_analysis_result'); + const resultsTable_exists = await resultsTable.exists(); + assert.ok(resultsTable_exists); + await metadataTable.delete(); + await resultsTable.delete(); + }); }); From 7172612f27292ba74ceacdbaf52587ebbc02b77d Mon Sep 17 00:00:00 2001 From: Donghe Zhao Date: Thu, 28 Jan 2021 22:22:22 +0000 Subject: [PATCH 09/10] Fixing reviewer's comments --- samples/analyzeIamPolicy.js | 3 ++- samples/analyzeIamPolicyLongrunningBigquery.js | 7 +++---- samples/analyzeIamPolicyLongrunningGcs.js | 7 +++---- samples/package.json | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/samples/analyzeIamPolicy.js b/samples/analyzeIamPolicy.js index 83fb7b25..118b66fe 100644 --- a/samples/analyzeIamPolicy.js +++ b/samples/analyzeIamPolicy.js @@ -50,7 +50,8 @@ async function main() { analyzeIamPolicy(); } -main(...process.argv.slice(2)).catch(err => { +process.on('unhandledRejection', err => { console.error(err.message); process.exitCode = 1; }); +main(...process.argv.slice(2)); diff --git a/samples/analyzeIamPolicyLongrunningBigquery.js b/samples/analyzeIamPolicyLongrunningBigquery.js index 137be7bd..3678c5f9 100644 --- a/samples/analyzeIamPolicyLongrunningBigquery.js +++ b/samples/analyzeIamPolicyLongrunningBigquery.js @@ -61,12 +61,11 @@ async function main(datasetId, tablePrefix) { console.log(util.inspect(result, {depth: null})); } // [END asset_quickstart_analyze_iam_policy_longrunning_bigquery] - analyzeIamPolicyLongrunningBigquery().catch(err => { - console.error(err.message); - }); + analyzeIamPolicyLongrunningBigquery(); } -main(...process.argv.slice(2)).catch(err => { +process.on('unhandledRejection', err => { console.error(err.message); process.exitCode = 1; }); +main(...process.argv.slice(2)); diff --git a/samples/analyzeIamPolicyLongrunningGcs.js b/samples/analyzeIamPolicyLongrunningGcs.js index e6370eac..f04d1cd2 100644 --- a/samples/analyzeIamPolicyLongrunningGcs.js +++ b/samples/analyzeIamPolicyLongrunningGcs.js @@ -60,12 +60,11 @@ async function main(gcsUri) { console.log(util.inspect(result, {depth: null})); } // [END asset_quickstart_analyze_iam_policy_longrunning_gcs] - analyzeIamPolicyLongrunningGcs().catch(err => { - console.error(err.message); - }); + analyzeIamPolicyLongrunningGcs(); } -main(...process.argv.slice(2)).catch(err => { +process.on('unhandledRejection', err => { console.error(err.message); process.exitCode = 1; }); +main(...process.argv.slice(2)); diff --git a/samples/package.json b/samples/package.json index eb2aa318..4c6b84b3 100644 --- a/samples/package.json +++ b/samples/package.json @@ -15,8 +15,8 @@ "test": "mocha --timeout 180000" }, "dependencies": { - "@google-cloud/bigquery": "^5.5.0", "@google-cloud/asset": "^3.11.0", + "@google-cloud/bigquery": "^5.5.0", "@google-cloud/compute": "^2.0.0", "@google-cloud/storage": "^5.0.0", "uuid": "^8.0.0", From 0eb3ce2b2af022fe7b69e60d78f9bc778f6326aa Mon Sep 17 00:00:00 2001 From: Donghe Zhao Date: Thu, 28 Jan 2021 22:26:12 +0000 Subject: [PATCH 10/10] Updating copyright to year of 2021 --- samples/analyzeIamPolicy.js | 2 +- samples/analyzeIamPolicyLongrunningBigquery.js | 2 +- samples/analyzeIamPolicyLongrunningGcs.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/analyzeIamPolicy.js b/samples/analyzeIamPolicy.js index 118b66fe..44ea9f6a 100644 --- a/samples/analyzeIamPolicy.js +++ b/samples/analyzeIamPolicy.js @@ -1,4 +1,4 @@ -// Copyright 2020 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/samples/analyzeIamPolicyLongrunningBigquery.js b/samples/analyzeIamPolicyLongrunningBigquery.js index 3678c5f9..10eab93e 100644 --- a/samples/analyzeIamPolicyLongrunningBigquery.js +++ b/samples/analyzeIamPolicyLongrunningBigquery.js @@ -1,4 +1,4 @@ -// Copyright 2020 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/samples/analyzeIamPolicyLongrunningGcs.js b/samples/analyzeIamPolicyLongrunningGcs.js index f04d1cd2..15a576d6 100644 --- a/samples/analyzeIamPolicyLongrunningGcs.js +++ b/samples/analyzeIamPolicyLongrunningGcs.js @@ -1,4 +1,4 @@ -// Copyright 2020 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.