diff --git a/asset/snippets/createFeed.js b/asset/snippets/createFeed.js new file mode 100644 index 00000000000..57576e1bc6d --- /dev/null +++ b/asset/snippets/createFeed.js @@ -0,0 +1,60 @@ +/** + * Copyright 2019, Google, Inc. + * 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: Create Feed +// description: Create Feed. +// usage: node createFeed "//storage.googleapis.com/", projects//topics/ + +async function main(feedId, assetNames, topicName) { + // [START asset_quickstart_create_feed] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); + + const client = new AssetServiceClient(); + + async function createFeed() { + const projectId = await client.getProjectId(); + // TODO(developer): Choose asset names, such as //storage.googleapis.com/[YOUR_BUCKET_NAME]. + // const assetNames = ['ASSET_NAME1', 'ASSET_NAME2', ...]; + + const request = { + parent: `projects/${projectId}`, + feedId: feedId, + feed: { + assetNames: assetNames.split(','), + feedOutputConfig: { + pubsubDestination: { + topic: topicName, + }, + }, + }, + }; + + // Handle the operation using the promise pattern. + const result = await client.createFeed(request); + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + // [END asset_quickstart_create_feed] + } + createFeed(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/asset/snippets/deleteFeed.js b/asset/snippets/deleteFeed.js new file mode 100644 index 00000000000..18b0d3ff48a --- /dev/null +++ b/asset/snippets/deleteFeed.js @@ -0,0 +1,47 @@ +/** + * Copyright 2019, Google, Inc. + * 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: Delete Feed +// description: Delete Feed. +// usage: node deleteFeed "project//feeds/" + +async function main(feedName) { + // [START asset_quickstart_delete_feed] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); + + const client = new AssetServiceClient(); + + async function deleteFeed() { + const request = { + name: feedName, + }; + + // Handle the operation using the promise pattern. + const result = await client.deleteFeed(request); + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + // [END asset_quickstart_delete_feed] + } + deleteFeed(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/asset/snippets/getFeed.js b/asset/snippets/getFeed.js new file mode 100644 index 00000000000..e2e435972bf --- /dev/null +++ b/asset/snippets/getFeed.js @@ -0,0 +1,47 @@ +/** + * Copyright 2019, Google, Inc. + * 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: Get Feed +// description: Get Feed. +// usage: node getFeed "project//feeds/" + +async function main(feedName) { + // [START asset_quickstart_get_feed] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); + + const client = new AssetServiceClient(); + + async function getFeed() { + const request = { + name: feedName, + }; + + // Handle the operation using the promise pattern. + const result = await client.getFeed(request); + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + // [END asset_quickstart_get_feed] + } + getFeed(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/asset/snippets/listFeeds.js b/asset/snippets/listFeeds.js new file mode 100644 index 00000000000..19a0f30e932 --- /dev/null +++ b/asset/snippets/listFeeds.js @@ -0,0 +1,49 @@ +/** + * Copyright 2019, Google, Inc. + * 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: List Feeds +// description: List Feeds. +// usage: node listFeeds + +async function main() { + // [START asset_quickstart_list_feeds] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); + + const client = new AssetServiceClient(); + + async function listFeeds() { + const projectId = await client.getProjectId(); + + const request = { + parent: `projects/${projectId}`, + }; + + // Handle the operation using the promise pattern. + const result = await client.listFeeds(request); + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + // [END asset_quickstart_list_feeds] + } + listFeeds(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/asset/snippets/updateFeed.js b/asset/snippets/updateFeed.js new file mode 100644 index 00000000000..1a0bc492e82 --- /dev/null +++ b/asset/snippets/updateFeed.js @@ -0,0 +1,57 @@ +/** + * Copyright 2019, Google, Inc. + * 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: Update Feed +// description: Update Feed. +// usage: node updateFeed "project//feeds/" projects//topics/ + +async function main(feedName, topicName) { + // [START asset_quickstart_update_feed] + const util = require('util'); + const {AssetServiceClient} = require('@google-cloud/asset/src/v1p2beta1'); + + const client = new AssetServiceClient(); + + async function updateFeed() { + const request = { + feed: { + name: feedName, + feedOutputConfig: { + pubsubDestination: { + topic: topicName, + }, + }, + }, + updateMask: { + paths: ['feed_output_config.pubsub_destination.topic'], + }, + }; + + // Handle the operation using the promise pattern. + const result = await client.updateFeed(request); + // Do things with with the response. + console.log(util.inspect(result, {depth: null})); + // [END asset_quickstart_update_feed] + } + updateFeed(); +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +});