Skip to content

Commit caf64d8

Browse files
lvvvvvfAce Nassri
authored andcommitted
samples: add relationship support samples (#560)
1 parent 271c50e commit caf64d8

File tree

5 files changed

+108
-15
lines changed

5 files changed

+108
-15
lines changed

asset/snippets/createFeed.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Google LLC
1+
// Copyright 2021 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,10 +17,18 @@
1717
// sample-metadata:
1818
// title: Create Feed
1919
// description: Create Feed.
20-
// usage: node createFeed <FEED_ID> "//storage.googleapis.com/<BUCKET_NAME>", projects/<PROJECT_ID>/topics/<TOPIC_ID>
20+
// usage: node createFeed <FEED_ID> "//storage.googleapis.com/<BUCKET_NAME>", projects/<PROJECT_ID>/topics/<TOPIC_ID>, "RESOURCE"
2121

22-
async function main(feedId, assetNames, topicName) {
22+
async function main(feedId, assetNames, topicName, contentType) {
2323
// [START asset_quickstart_create_feed]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const feedId = 'my feed';
28+
// const assetNames = '//storage.googleapis.com/<BUCKET_NAME1>,//storage.googleapis.com/<BUCKET_NAME2>';
29+
// const topicName = 'projects/<PROJECT_ID>/topics/<TOPIC_ID>'
30+
// const contentType = 'RESOURCE';
31+
2432
const util = require('util');
2533
const {AssetServiceClient} = require('@google-cloud/asset');
2634

@@ -36,6 +44,7 @@ async function main(feedId, assetNames, topicName) {
3644
feedId: feedId,
3745
feed: {
3846
assetNames: assetNames.split(','),
47+
contentType: contentType,
3948
feedOutputConfig: {
4049
pubsubDestination: {
4150
topic: topicName,

asset/snippets/exportAssets.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC
1+
// Copyright 2021 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,10 +17,16 @@
1717
// sample-metadata:
1818
// title: Export Assets
1919
// description: Export asserts to specified dump file path.
20-
// usage: node exportAssets.js <gs://my-bucket/my-assets.txt>
20+
// usage: node exportAssets.js <gs://my-bucket/my-assets.txt> <content_type>
2121

22-
async function main(dumpFilePath) {
22+
async function main(dumpFilePath, contentType) {
2323
// [START asset_quickstart_export_assets]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const dumpFilePath = 'gs://my-bucket/my-assets.txt';
28+
// const contentType = 'RESOURCE';
29+
2430
const {AssetServiceClient} = require('@google-cloud/asset');
2531
const client = new AssetServiceClient();
2632

@@ -30,9 +36,9 @@ async function main(dumpFilePath) {
3036

3137
// TODO(developer): choose the dump file path
3238
// const dumpFilePath = 'Dump file path, e.g.: gs://<my_bucket>/<my_asset_file>'
33-
3439
const request = {
3540
parent: projectResource,
41+
contentType: contentType,
3642
outputConfig: {
3743
gcsDestination: {
3844
uri: dumpFilePath,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
// sample-metadata:
18+
// title: Export Assets To BigQuery
19+
// description: Export asserts to specified BigQuery table.
20+
// usage: node exportAssetsBigquery.js <projects/project_id/datasets/dataset_id> <table_name>
21+
22+
async function main(dataSet, table) {
23+
// [START asset_quickstart_export_assets_bigquery]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const dataSet = 'projects/project_id/datasets/dataset_id';
28+
// const table = 'mytable';
29+
30+
const {AssetServiceClient} = require('@google-cloud/asset');
31+
const client = new AssetServiceClient();
32+
33+
async function exportAssetsBigquery() {
34+
const projectId = await client.getProjectId();
35+
const projectResource = client.projectPath(projectId);
36+
const dataset = dataSet;
37+
38+
const request = {
39+
parent: projectResource,
40+
outputConfig: {
41+
bigqueryDestination: {
42+
dataset: `projects/${projectId}/${dataset}`,
43+
table: table,
44+
force: true,
45+
},
46+
},
47+
};
48+
49+
// Handle the operation using the promise pattern.
50+
const [operation] = await client.exportAssets(request);
51+
52+
// Operation#promise starts polling for the completion of the operation.
53+
const [result] = await operation.promise();
54+
55+
// Do things with with the response.
56+
console.log(result);
57+
}
58+
59+
exportAssetsBigquery();
60+
// [END asset_quickstart_export_assets_bigquery]
61+
}
62+
63+
main(...process.argv.slice(2)).catch(err => {
64+
console.error(err.message);
65+
process.exitCode = 1;
66+
});

asset/snippets/getBatchAssetHistory.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC
1+
// Copyright 2021 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -19,8 +19,14 @@
1919
// description: Batch get history of assets.
2020
// usage: node getBatchAssetHistory "//storage.googleapis.com/<BUCKET_NAME>"
2121

22-
async function main(assetNames) {
22+
async function main(assetNames, contentType) {
2323
// [START asset_quickstart_batch_get_assets_history]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const assetNames = '//storage.googleapis.com/<BUCKET_NAME1>,//storage.googleapis.com/<BUCKET_NAME2>';
28+
// const contentType = 'RESOURCE';
29+
2430
const util = require('util');
2531
const {AssetServiceClient} = require('@google-cloud/asset');
2632

@@ -35,7 +41,7 @@ async function main(assetNames) {
3541
const request = {
3642
parent: projectResource,
3743
assetNames: assetNames.split(','),
38-
contentType: 'RESOURCE',
44+
contentType: contentType,
3945
readTimeWindow: {
4046
startTime: {
4147
seconds: Math.floor(new Date().getTime() / 1000),

asset/snippets/listAssets.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Google LLC
1+
// Copyright 2021 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,11 +17,17 @@
1717
// sample-metadata:
1818
// title: List Assets
1919
// description: List assets under the current project.
20-
// usage: node listAssets <ASSET_TYPES>
21-
// example: node listAssets "storage.googleapis.com/Bucket,bigquery.googleapis.com/Table"
20+
// usage: node listAssets <ASSET_TYPES> <content_type>
21+
// example: node listAssets "storage.googleapis.com/Bucket,bigquery.googleapis.com/Table" 'RESOURCE'
2222

23-
async function main(assetTypes) {
23+
async function main(assetTypes, contentType) {
2424
// [START asset_quickstart_list_assets]
25+
/**
26+
* TODO(developer): Uncomment these variables before running the sample.
27+
*/
28+
// const assetTypes = 'storage.googleapis.com/Bucket,bigquery.googleapis.com/Table';
29+
// const contentType = 'RESOURCE';
30+
2531
const util = require('util');
2632
const {v1} = require('@google-cloud/asset');
2733
const client = new v1.AssetServiceClient();
@@ -38,7 +44,7 @@ async function main(assetTypes) {
3844
const request = {
3945
parent: projectResource,
4046
assetTypes: assetTypesList,
41-
contentType: 'RESOURCE',
47+
contentType: contentType,
4248
// (Optional) Add readTime parameter to list assets at the given time instead of current time:
4349
// readTime: { seconds: 1593988758 },
4450
};

0 commit comments

Comments
 (0)