diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_iam_policy.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_iam_policy.js new file mode 100644 index 000000000000..5d7f2cc17da6 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_iam_policy.js @@ -0,0 +1,63 @@ +// 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. +// 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'; + +function main(analysisQuery) { + // [START cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The request query. + */ + // const analysisQuery = '' + /** + * Optional. Amount of time executable has to complete. See JSON representation of + * [Duration](https://developers.google.com/protocol-buffers/docs/proto3#json). + * If this field is set with a value less than the RPC deadline, and the + * execution of your query hasn't finished in the specified + * execution timeout, you will get a response with partial result. + * Otherwise, your query's execution will continue until the RPC deadline. + * If it's not finished until then, you will get a DEADLINE_EXCEEDED error. + * Default is empty. + */ + // const executionTimeout = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function analyzeIamPolicy() { + // Construct request + const request = { + analysisQuery, + }; + + // Run request + const response = await assetClient.analyzeIamPolicy(request); + console.log(response); + } + + analyzeIamPolicy(); + // [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicy_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_iam_policy_longrunning.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_iam_policy_longrunning.js new file mode 100644 index 000000000000..6570bd6220d6 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_iam_policy_longrunning.js @@ -0,0 +1,58 @@ +// 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. +// 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'; + +function main(analysisQuery, outputConfig) { + // [START cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The request query. + */ + // const analysisQuery = '' + /** + * Required. Output configuration indicating where the results will be output to. + */ + // const outputConfig = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function analyzeIamPolicyLongrunning() { + // Construct request + const request = { + analysisQuery, + outputConfig, + }; + + // Run request + const [operation] = await assetClient.analyzeIamPolicyLongrunning(request); + const [response] = await operation.promise(); + console.log(response); + } + + analyzeIamPolicyLongrunning(); + // [END cloudasset_v1_generated_AssetService_AnalyzeIamPolicyLongrunning_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_move.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_move.js new file mode 100644 index 000000000000..0df32716ef57 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.analyze_move.js @@ -0,0 +1,69 @@ +// 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. +// 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'; + +function main(resource, destinationParent) { + // [START cloudasset_v1_generated_AssetService_AnalyzeMove_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. Name of the resource to perform the analysis against. + * Only GCP Project are supported as of today. Hence, this can only be Project + * ID (such as "projects/my-project-id") or a Project Number (such as + * "projects/12345"). + */ + // const resource = 'abc123' + /** + * Required. Name of the GCP Folder or Organization to reparent the target + * resource. The analysis will be performed against hypothetically moving the + * resource to this specified desitination parent. This can only be a Folder + * number (such as "folders/123") or an Organization number (such as + * "organizations/123"). + */ + // const destinationParent = 'abc123' + /** + * Analysis view indicating what information should be included in the + * analysis response. If unspecified, the default view is FULL. + */ + // const view = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function analyzeMove() { + // Construct request + const request = { + resource, + destinationParent, + }; + + // Run request + const response = await assetClient.analyzeMove(request); + console.log(response); + } + + analyzeMove(); + // [END cloudasset_v1_generated_AssetService_AnalyzeMove_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.batch_get_assets_history.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.batch_get_assets_history.js new file mode 100644 index 000000000000..651d1555c8e4 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.batch_get_assets_history.js @@ -0,0 +1,95 @@ +// 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. +// 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'; + +function main(parent) { + // [START cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The relative name of the root asset. It can only be an + * organization number (such as "organizations/123"), a project ID (such as + * "projects/my-project-id")", or a project number (such as "projects/12345"). + */ + // const parent = 'abc123' + /** + * A list of the full names of the assets. + * See: https://cloud.google.com/asset-inventory/docs/resource-name-format + * Example: + * `//compute.googleapis.com/projects/my_project_123/zones/zone1/instances/instance1`. + * The request becomes a no-op if the asset name list is empty, and the max + * size of the asset name list is 100 in one request. + */ + // const assetNames = 'abc123' + /** + * Optional. The content type. + */ + // const contentType = '' + /** + * Optional. The time window for the asset history. Both start_time and + * end_time are optional and if set, it must be after the current time minus + * 35 days. If end_time is not set, it is default to current timestamp. + * If start_time is not set, the snapshot of the assets at end_time will be + * returned. The returned results contain all temporal assets whose time + * window overlap with read_time_window. + */ + // const readTimeWindow = '' + /** + * Optional. A list of relationship types to output, for example: + * `INSTANCE_TO_INSTANCEGROUP`. This field should only be specified if + * content_type=RELATIONSHIP. + * * If specified: + * it outputs specified relationships' history on the [asset_names]. It + * returns an error if any of the [relationship_types] doesn't belong to the + * supported relationship types of the [asset_names] or if any of the + * [asset_names]'s types doesn't belong to the source types of the + * [relationship_types]. + * * Otherwise: + * it outputs the supported relationships' history on the [asset_names] or + * returns an error if any of the [asset_names]'s types has no relationship + * support. + * See [Introduction to Cloud Asset + * Inventory](https://cloud.google.com/asset-inventory/docs/overview) for all + * supported asset types and relationship types. + */ + // const relationshipTypes = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function batchGetAssetsHistory() { + // Construct request + const request = { + parent, + }; + + // Run request + const response = await assetClient.batchGetAssetsHistory(request); + console.log(response); + } + + batchGetAssetsHistory(); + // [END cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.create_feed.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.create_feed.js new file mode 100644 index 000000000000..05d24467524d --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.create_feed.js @@ -0,0 +1,71 @@ +// 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. +// 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'; + +function main(parent, feedId, feed) { + // [START cloudasset_v1_generated_AssetService_CreateFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the project/folder/organization where this feed + * should be created in. It can only be an organization number (such as + * "organizations/123"), a folder number (such as "folders/123"), a project ID + * (such as "projects/my-project-id")", or a project number (such as + * "projects/12345"). + */ + // const parent = 'abc123' + /** + * Required. This is the client-assigned asset feed identifier and it needs to + * be unique under a specific parent project/folder/organization. + */ + // const feedId = 'abc123' + /** + * Required. The feed details. The field `name` must be empty and it will be generated + * in the format of: + * projects/project_number/feeds/feed_id + * folders/folder_number/feeds/feed_id + * organizations/organization_number/feeds/feed_id + */ + // const feed = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function createFeed() { + // Construct request + const request = { + parent, + feedId, + feed, + }; + + // Run request + const response = await assetClient.createFeed(request); + console.log(response); + } + + createFeed(); + // [END cloudasset_v1_generated_AssetService_CreateFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.delete_feed.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.delete_feed.js new file mode 100644 index 000000000000..e72349b3130d --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.delete_feed.js @@ -0,0 +1,55 @@ +// 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. +// 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'; + +function main(name) { + // [START cloudasset_v1_generated_AssetService_DeleteFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the feed and it must be in the format of: + * projects/project_number/feeds/feed_id + * folders/folder_number/feeds/feed_id + * organizations/organization_number/feeds/feed_id + */ + // const name = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function deleteFeed() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await assetClient.deleteFeed(request); + console.log(response); + } + + deleteFeed(); + // [END cloudasset_v1_generated_AssetService_DeleteFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.export_assets.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.export_assets.js new file mode 100644 index 000000000000..ef338fd65fea --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.export_assets.js @@ -0,0 +1,109 @@ +// 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. +// 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'; + +function main(parent, outputConfig) { + // [START cloudasset_v1_generated_AssetService_ExportAssets_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The relative name of the root asset. This can only be an + * organization number (such as "organizations/123"), a project ID (such as + * "projects/my-project-id"), or a project number (such as "projects/12345"), + * or a folder number (such as "folders/123"). + */ + // const parent = 'abc123' + /** + * Timestamp to take an asset snapshot. This can only be set to a timestamp + * between the current time and the current time minus 35 days (inclusive). + * If not specified, the current time will be used. Due to delays in resource + * data collection and indexing, there is a volatile window during which + * running the same query may get different results. + */ + // const readTime = '' + /** + * A list of asset types to take a snapshot for. For example: + * "compute.googleapis.com/Disk". + * Regular expressions are also supported. For example: + * * "compute.googleapis.com.*" snapshots resources whose asset type starts + * with "compute.googleapis.com". + * * ".*Instance" snapshots resources whose asset type ends with "Instance". + * * ".*Instance.*" snapshots resources whose asset type contains "Instance". + * See [RE2](https://github.com/google/re2/wiki/Syntax) for all supported + * regular expression syntax. If the regular expression does not match any + * supported asset type, an INVALID_ARGUMENT error will be returned. + * If specified, only matching assets will be returned, otherwise, it will + * snapshot all asset types. See [Introduction to Cloud Asset + * Inventory](https://cloud.google.com/asset-inventory/docs/overview) + * for all supported asset types. + */ + // const assetTypes = 'abc123' + /** + * Asset content type. If not specified, no content but the asset name will be + * returned. + */ + // const contentType = '' + /** + * Required. Output configuration indicating where the results will be output to. + */ + // const outputConfig = '' + /** + * A list of relationship types to export, for example: + * `INSTANCE_TO_INSTANCEGROUP`. This field should only be specified if + * content_type=RELATIONSHIP. + * * If specified: + * it snapshots specified relationships. It returns an error if + * any of the [relationship_types] doesn't belong to the supported + * relationship types of the [asset_types] or if any of the [asset_types] + * doesn't belong to the source types of the [relationship_types]. + * * Otherwise: + * it snapshots the supported relationships for all [asset_types] or returns + * an error if any of the [asset_types] has no relationship support. + * An unspecified asset types field means all supported asset_types. + * See [Introduction to Cloud Asset + * Inventory](https://cloud.google.com/asset-inventory/docs/overview) for all + * supported asset types and relationship types. + */ + // const relationshipTypes = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function exportAssets() { + // Construct request + const request = { + parent, + outputConfig, + }; + + // Run request + const [operation] = await assetClient.exportAssets(request); + const [response] = await operation.promise(); + console.log(response); + } + + exportAssets(); + // [END cloudasset_v1_generated_AssetService_ExportAssets_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.get_feed.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.get_feed.js new file mode 100644 index 000000000000..eeda3a194ac7 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.get_feed.js @@ -0,0 +1,55 @@ +// 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. +// 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'; + +function main(name) { + // [START cloudasset_v1_generated_AssetService_GetFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the Feed and it must be in the format of: + * projects/project_number/feeds/feed_id + * folders/folder_number/feeds/feed_id + * organizations/organization_number/feeds/feed_id + */ + // const name = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function getFeed() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await assetClient.getFeed(request); + console.log(response); + } + + getFeed(); + // [END cloudasset_v1_generated_AssetService_GetFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.list_assets.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.list_assets.js new file mode 100644 index 000000000000..84556de5da41 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.list_assets.js @@ -0,0 +1,116 @@ +// 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. +// 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'; + +function main(parent) { + // [START cloudasset_v1_generated_AssetService_ListAssets_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. Name of the organization or project the assets belong to. Format: + * "organizations/[organization-number]" (such as "organizations/123"), + * "projects/[project-id]" (such as "projects/my-project-id"), or + * "projects/[project-number]" (such as "projects/12345"). + */ + // const parent = 'abc123' + /** + * Timestamp to take an asset snapshot. This can only be set to a timestamp + * between the current time and the current time minus 35 days (inclusive). + * If not specified, the current time will be used. Due to delays in resource + * data collection and indexing, there is a volatile window during which + * running the same query may get different results. + */ + // const readTime = '' + /** + * A list of asset types to take a snapshot for. For example: + * "compute.googleapis.com/Disk". + * Regular expression is also supported. For example: + * * "compute.googleapis.com.*" snapshots resources whose asset type starts + * with "compute.googleapis.com". + * * ".*Instance" snapshots resources whose asset type ends with "Instance". + * * ".*Instance.*" snapshots resources whose asset type contains "Instance". + * See [RE2](https://github.com/google/re2/wiki/Syntax) for all supported + * regular expression syntax. If the regular expression does not match any + * supported asset type, an INVALID_ARGUMENT error will be returned. + * If specified, only matching assets will be returned, otherwise, it will + * snapshot all asset types. See [Introduction to Cloud Asset + * Inventory](https://cloud.google.com/asset-inventory/docs/overview) + * for all supported asset types. + */ + // const assetTypes = 'abc123' + /** + * Asset content type. If not specified, no content but the asset name will + * be returned. + */ + // const contentType = '' + /** + * The maximum number of assets to be returned in a single response. Default + * is 100, minimum is 1, and maximum is 1000. + */ + // const pageSize = 1234 + /** + * The `next_page_token` returned from the previous `ListAssetsResponse`, or + * unspecified for the first `ListAssetsRequest`. It is a continuation of a + * prior `ListAssets` call, and the API should return the next page of assets. + */ + // const pageToken = 'abc123' + /** + * A list of relationship types to output, for example: + * `INSTANCE_TO_INSTANCEGROUP`. This field should only be specified if + * content_type=RELATIONSHIP. + * * If specified: + * it snapshots specified relationships. It returns an error if + * any of the [relationship_types] doesn't belong to the supported + * relationship types of the [asset_types] or if any of the [asset_types] + * doesn't belong to the source types of the [relationship_types]. + * * Otherwise: + * it snapshots the supported relationships for all [asset_types] or returns + * an error if any of the [asset_types] has no relationship support. + * An unspecified asset types field means all supported asset_types. + * See [Introduction to Cloud Asset + * Inventory](https://cloud.google.com/asset-inventory/docs/overview) + * for all supported asset types and relationship types. + */ + // const relationshipTypes = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function listAssets() { + // Construct request + const request = { + parent, + }; + + // Run request + const iterable = await assetClient.listAssetsAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + listAssets(); + // [END cloudasset_v1_generated_AssetService_ListAssets_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.list_feeds.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.list_feeds.js new file mode 100644 index 000000000000..97476d935b16 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.list_feeds.js @@ -0,0 +1,54 @@ +// 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. +// 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'; + +function main(parent) { + // [START cloudasset_v1_generated_AssetService_ListFeeds_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The parent project/folder/organization whose feeds are to be + * listed. It can only be using project/folder/organization number (such as + * "folders/12345")", or a project ID (such as "projects/my-project-id"). + */ + // const parent = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function listFeeds() { + // Construct request + const request = { + parent, + }; + + // Run request + const response = await assetClient.listFeeds(request); + console.log(response); + } + + listFeeds(); + // [END cloudasset_v1_generated_AssetService_ListFeeds_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.search_all_iam_policies.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.search_all_iam_policies.js new file mode 100644 index 000000000000..9b3dd1b53b1a --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.search_all_iam_policies.js @@ -0,0 +1,149 @@ +// 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. +// 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'; + +function main(scope) { + // [START cloudasset_v1_generated_AssetService_SearchAllIamPolicies_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. A scope can be a project, a folder, or an organization. The search is + * limited to the IAM policies within the `scope`. The caller must be granted + * the + * [`cloudasset.assets.searchAllIamPolicies`](https://cloud.google.com/asset-inventory/docs/access-control#required_permissions) + * permission on the desired scope. + * The allowed values are: + * * projects/{PROJECT_ID} (e.g., "projects/foo-bar") + * * projects/{PROJECT_NUMBER} (e.g., "projects/12345678") + * * folders/{FOLDER_NUMBER} (e.g., "folders/1234567") + * * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456") + */ + // const scope = 'abc123' + /** + * Optional. The query statement. See [how to construct a + * query](https://cloud.google.com/asset-inventory/docs/searching-iam-policies#how_to_construct_a_query) + * for more information. If not specified or empty, it will search all the + * IAM policies within the specified `scope`. Note that the query string is + * compared against each Cloud IAM policy binding, including its members, + * roles, and Cloud IAM conditions. The returned Cloud IAM policies will only + * contain the bindings that match your query. To learn more about the IAM + * policy structure, see [IAM policy + * doc](https://cloud.google.com/iam/docs/policies#structure). + * Examples: + * * `policy:amy@gmail.com` to find IAM policy bindings that specify user + * "amy@gmail.com". + * * `policy:roles/compute.admin` to find IAM policy bindings that specify + * the Compute Admin role. + * * `policy:comp*` to find IAM policy bindings that contain "comp" as a + * prefix of any word in the binding. + * * `policy.role.permissions:storage.buckets.update` to find IAM policy + * bindings that specify a role containing "storage.buckets.update" + * permission. Note that if callers don't have `iam.roles.get` access to a + * role's included permissions, policy bindings that specify this role will + * be dropped from the search results. + * * `policy.role.permissions:upd*` to find IAM policy bindings that specify a + * role containing "upd" as a prefix of any word in the role permission. + * Note that if callers don't have `iam.roles.get` access to a role's + * included permissions, policy bindings that specify this role will be + * dropped from the search results. + * * `resource:organizations/123456` to find IAM policy bindings + * that are set on "organizations/123456". + * * `resource=//cloudresourcemanager.googleapis.com/projects/myproject` to + * find IAM policy bindings that are set on the project named "myproject". + * * `Important` to find IAM policy bindings that contain "Important" as a + * word in any of the searchable fields (except for the included + * permissions). + * * `resource:(instance1 OR instance2) policy:amy` to find + * IAM policy bindings that are set on resources "instance1" or + * "instance2" and also specify user "amy". + * * `roles:roles/compute.admin` to find IAM policy bindings that specify the + * Compute Admin role. + * * `memberTypes:user` to find IAM policy bindings that contain the "user" + * member type. + */ + // const query = 'abc123' + /** + * Optional. The page size for search result pagination. Page size is capped at 500 even + * if a larger value is given. If set to zero, server will pick an appropriate + * default. Returned results may be fewer than requested. When this happens, + * there could be more results as long as `next_page_token` is returned. + */ + // const pageSize = 1234 + /** + * Optional. If present, retrieve the next batch of results from the preceding call to + * this method. `page_token` must be the value of `next_page_token` from the + * previous response. The values of all other method parameters must be + * identical to those in the previous call. + */ + // const pageToken = 'abc123' + /** + * Optional. A list of asset types that the IAM policies are attached to. If empty, it + * will search the IAM policies that are attached to all the [searchable asset + * types](https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types). + * Regular expressions are also supported. For example: + * * "compute.googleapis.com.*" snapshots IAM policies attached to asset type + * starts with "compute.googleapis.com". + * * ".*Instance" snapshots IAM policies attached to asset type ends with + * "Instance". + * * ".*Instance.*" snapshots IAM policies attached to asset type contains + * "Instance". + * See [RE2](https://github.com/google/re2/wiki/Syntax) for all supported + * regular expression syntax. If the regular expression does not match any + * supported asset type, an INVALID_ARGUMENT error will be returned. + */ + // const assetTypes = 'abc123' + /** + * Optional. A comma-separated list of fields specifying the sorting order of the + * results. The default order is ascending. Add " DESC" after the field name + * to indicate descending order. Redundant space characters are ignored. + * Example: "assetType DESC, resource". + * Only singular primitive fields in the response are sortable: + * * resource + * * assetType + * * project + * All the other fields such as repeated fields (e.g., `folders`) and + * non-primitive fields (e.g., `policy`) are not supported. + */ + // const orderBy = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function searchAllIamPolicies() { + // Construct request + const request = { + scope, + }; + + // Run request + const iterable = await assetClient.searchAllIamPoliciesAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + searchAllIamPolicies(); + // [END cloudasset_v1_generated_AssetService_SearchAllIamPolicies_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.search_all_resources.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.search_all_resources.js new file mode 100644 index 000000000000..16c28272e402 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.search_all_resources.js @@ -0,0 +1,182 @@ +// 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. +// 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'; + +function main(scope) { + // [START cloudasset_v1_generated_AssetService_SearchAllResources_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. A scope can be a project, a folder, or an organization. The search is + * limited to the resources within the `scope`. The caller must be granted the + * [`cloudasset.assets.searchAllResources`](https://cloud.google.com/asset-inventory/docs/access-control#required_permissions) + * permission on the desired scope. + * The allowed values are: + * * projects/{PROJECT_ID} (e.g., "projects/foo-bar") + * * projects/{PROJECT_NUMBER} (e.g., "projects/12345678") + * * folders/{FOLDER_NUMBER} (e.g., "folders/1234567") + * * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456") + */ + // const scope = 'abc123' + /** + * Optional. The query statement. See [how to construct a + * query](https://cloud.google.com/asset-inventory/docs/searching-resources#how_to_construct_a_query) + * for more information. If not specified or empty, it will search all the + * resources within the specified `scope`. + * Examples: + * * `name:Important` to find Cloud resources whose name contains + * "Important" as a word. + * * `name=Important` to find the Cloud resource whose name is exactly + * "Important". + * * `displayName:Impor*` to find Cloud resources whose display name + * contains "Impor" as a prefix of any word in the field. + * * `location:us-west*` to find Cloud resources whose location contains both + * "us" and "west" as prefixes. + * * `labels:prod` to find Cloud resources whose labels contain "prod" as + * a key or value. + * * `labels.env:prod` to find Cloud resources that have a label "env" + * and its value is "prod". + * * `labels.env:*` to find Cloud resources that have a label "env". + * * `kmsKey:key` to find Cloud resources encrypted with a customer-managed + * encryption key whose name contains the word "key". + * * `state:ACTIVE` to find Cloud resources whose state contains "ACTIVE" as a + * word. + * * `NOT state:ACTIVE` to find Cloud resources whose state doesn't contain + * "ACTIVE" as a word. + * * `createTime<1609459200` to find Cloud resources that were created before + * "2021-01-01 00:00:00 UTC". 1609459200 is the epoch timestamp of + * "2021-01-01 00:00:00 UTC" in seconds. + * * `updateTime>1609459200` to find Cloud resources that were updated after + * "2021-01-01 00:00:00 UTC". 1609459200 is the epoch timestamp of + * "2021-01-01 00:00:00 UTC" in seconds. + * * `Important` to find Cloud resources that contain "Important" as a word + * in any of the searchable fields. + * * `Impor*` to find Cloud resources that contain "Impor" as a prefix of any + * word in any of the searchable fields. + * * `Important location:(us-west1 OR global)` to find Cloud + * resources that contain "Important" as a word in any of the searchable + * fields and are also located in the "us-west1" region or the "global" + * location. + */ + // const query = 'abc123' + /** + * Optional. A list of asset types that this request searches for. If empty, it will + * search all the [searchable asset + * types](https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types). + * Regular expressions are also supported. For example: + * * "compute.googleapis.com.*" snapshots resources whose asset type starts + * with "compute.googleapis.com". + * * ".*Instance" snapshots resources whose asset type ends with "Instance". + * * ".*Instance.*" snapshots resources whose asset type contains "Instance". + * See [RE2](https://github.com/google/re2/wiki/Syntax) for all supported + * regular expression syntax. If the regular expression does not match any + * supported asset type, an INVALID_ARGUMENT error will be returned. + */ + // const assetTypes = 'abc123' + /** + * Optional. The page size for search result pagination. Page size is capped at 500 even + * if a larger value is given. If set to zero, server will pick an appropriate + * default. Returned results may be fewer than requested. When this happens, + * there could be more results as long as `next_page_token` is returned. + */ + // const pageSize = 1234 + /** + * Optional. If present, then retrieve the next batch of results from the preceding call + * to this method. `page_token` must be the value of `next_page_token` from + * the previous response. The values of all other method parameters, must be + * identical to those in the previous call. + */ + // const pageToken = 'abc123' + /** + * Optional. A comma-separated list of fields specifying the sorting order of the + * results. The default order is ascending. Add " DESC" after the field name + * to indicate descending order. Redundant space characters are ignored. + * Example: "location DESC, name". + * Only singular primitive fields in the response are sortable: + * * name + * * assetType + * * project + * * displayName + * * description + * * location + * * kmsKey + * * createTime + * * updateTime + * * state + * * parentFullResourceName + * * parentAssetType + * All the other fields such as repeated fields (e.g., `networkTags`), map + * fields (e.g., `labels`) and struct fields (e.g., `additionalAttributes`) + * are not supported. + */ + // const orderBy = 'abc123' + /** + * Optional. A comma-separated list of fields specifying which fields to be returned in + * ResourceSearchResult. Only '*' or combination of top level fields can be + * specified. Field names of both snake_case and camelCase are supported. + * Examples: `"*"`, `"name,location"`, `"name,versionedResources"`. + * The read_mask paths must be valid field paths listed but not limited to + * (both snake_case and camelCase are supported): + * * name + * * assetType + * * project + * * displayName + * * description + * * location + * * labels + * * networkTags + * * kmsKey + * * createTime + * * updateTime + * * state + * * additionalAttributes + * * versionedResources + * If read_mask is not specified, all fields except versionedResources will + * be returned. + * If only '*' is specified, all fields including versionedResources will be + * returned. + * Any invalid field path will trigger INVALID_ARGUMENT error. + */ + // const readMask = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function searchAllResources() { + // Construct request + const request = { + scope, + }; + + // Run request + const iterable = await assetClient.searchAllResourcesAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + searchAllResources(); + // [END cloudasset_v1_generated_AssetService_SearchAllResources_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1/asset_service.update_feed.js b/packages/google-cloud-asset/samples/generated/v1/asset_service.update_feed.js new file mode 100644 index 000000000000..fc0b5b5aff4e --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1/asset_service.update_feed.js @@ -0,0 +1,63 @@ +// 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. +// 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'; + +function main(feed, updateMask) { + // [START cloudasset_v1_generated_AssetService_UpdateFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The new values of feed details. It must match an existing feed and the + * field `name` must be in the format of: + * projects/project_number/feeds/feed_id or + * folders/folder_number/feeds/feed_id or + * organizations/organization_number/feeds/feed_id. + */ + // const feed = '' + /** + * Required. Only updates the `feed` fields indicated by this mask. + * The field mask must not be empty, and it must not contain fields that + * are immutable or only set by the server. + */ + // const updateMask = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function updateFeed() { + // Construct request + const request = { + feed, + updateMask, + }; + + // Run request + const response = await assetClient.updateFeed(request); + console.log(response); + } + + updateFeed(); + // [END cloudasset_v1_generated_AssetService_UpdateFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p1beta1/asset_service.search_all_iam_policies.js b/packages/google-cloud-asset/samples/generated/v1p1beta1/asset_service.search_all_iam_policies.js new file mode 100644 index 000000000000..ce7a4481d43b --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p1beta1/asset_service.search_all_iam_policies.js @@ -0,0 +1,80 @@ +// 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. +// 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'; + +function main(scope) { + // [START cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The relative name of an asset. The search is limited to the resources + * within the `scope`. The allowed value must be: + * * Organization number (such as "organizations/123") + * * Folder number(such as "folders/1234") + * * Project number (such as "projects/12345") + * * Project id (such as "projects/abc") + */ + // const scope = 'abc123' + /** + * Optional. The query statement. + * Examples: + * * "policy:myuser@mydomain.com" + * * "policy:(myuser@mydomain.com viewer)" + */ + // const query = 'abc123' + /** + * Optional. The page size for search result pagination. Page size is capped at 500 even + * if a larger value is given. If set to zero, server will pick an appropriate + * default. Returned results may be fewer than requested. When this happens, + * there could be more results as long as `next_page_token` is returned. + */ + // const pageSize = 1234 + /** + * Optional. If present, retrieve the next batch of results from the preceding call to + * this method. `page_token` must be the value of `next_page_token` from the + * previous response. The values of all other method parameters must be + * identical to those in the previous call. + */ + // const pageToken = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p1beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function searchAllIamPolicies() { + // Construct request + const request = { + scope, + }; + + // Run request + const iterable = await assetClient.searchAllIamPoliciesAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + searchAllIamPolicies(); + // [END cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p1beta1/asset_service.search_all_resources.js b/packages/google-cloud-asset/samples/generated/v1p1beta1/asset_service.search_all_resources.js new file mode 100644 index 000000000000..d5f28f1956c5 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p1beta1/asset_service.search_all_resources.js @@ -0,0 +1,89 @@ +// 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. +// 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'; + +function main(scope) { + // [START cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The relative name of an asset. The search is limited to the resources + * within the `scope`. The allowed value must be: + * * Organization number (such as "organizations/123") + * * Folder number(such as "folders/1234") + * * Project number (such as "projects/12345") + * * Project id (such as "projects/abc") + */ + // const scope = 'abc123' + /** + * Optional. The query statement. + */ + // const query = 'abc123' + /** + * Optional. A list of asset types that this request searches for. If empty, it will + * search all the supported asset types. + */ + // const assetTypes = 'abc123' + /** + * Optional. The page size for search result pagination. Page size is capped at 500 even + * if a larger value is given. If set to zero, server will pick an appropriate + * default. Returned results may be fewer than requested. When this happens, + * there could be more results as long as `next_page_token` is returned. + */ + // const pageSize = 1234 + /** + * Optional. If present, then retrieve the next batch of results from the preceding call + * to this method. `page_token` must be the value of `next_page_token` from + * the previous response. The values of all other method parameters, must be + * identical to those in the previous call. + */ + // const pageToken = 'abc123' + /** + * Optional. A comma separated list of fields specifying the sorting order of the + * results. The default order is ascending. Add " desc" after the field name + * to indicate descending order. Redundant space characters are ignored. For + * example, " foo , bar desc ". + */ + // const orderBy = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p1beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function searchAllResources() { + // Construct request + const request = { + scope, + }; + + // Run request + const iterable = await assetClient.searchAllResourcesAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + searchAllResources(); + // [END cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.create_feed.js b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.create_feed.js new file mode 100644 index 000000000000..9cae8dd8cd87 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.create_feed.js @@ -0,0 +1,71 @@ +// 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. +// 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'; + +function main(parent, feedId, feed) { + // [START cloudasset_v1p2beta1_generated_AssetService_CreateFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the project/folder/organization where this feed + * should be created in. It can only be an organization number (such as + * "organizations/123"), a folder number (such as "folders/123"), a project ID + * (such as "projects/my-project-id")", or a project number (such as + * "projects/12345"). + */ + // const parent = 'abc123' + /** + * Required. This is the client-assigned asset feed identifier and it needs to + * be unique under a specific parent project/folder/organization. + */ + // const feedId = 'abc123' + /** + * Required. The feed details. The field `name` must be empty and it will be generated + * in the format of: + * projects/project_number/feeds/feed_id + * folders/folder_number/feeds/feed_id + * organizations/organization_number/feeds/feed_id + */ + // const feed = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p2beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function createFeed() { + // Construct request + const request = { + parent, + feedId, + feed, + }; + + // Run request + const response = await assetClient.createFeed(request); + console.log(response); + } + + createFeed(); + // [END cloudasset_v1p2beta1_generated_AssetService_CreateFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.delete_feed.js b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.delete_feed.js new file mode 100644 index 000000000000..4b8c15b0146d --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.delete_feed.js @@ -0,0 +1,55 @@ +// 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. +// 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'; + +function main(name) { + // [START cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the feed and it must be in the format of: + * projects/project_number/feeds/feed_id + * folders/folder_number/feeds/feed_id + * organizations/organization_number/feeds/feed_id + */ + // const name = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p2beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function deleteFeed() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await assetClient.deleteFeed(request); + console.log(response); + } + + deleteFeed(); + // [END cloudasset_v1p2beta1_generated_AssetService_DeleteFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.get_feed.js b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.get_feed.js new file mode 100644 index 000000000000..c0fdb7a9e807 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.get_feed.js @@ -0,0 +1,55 @@ +// 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. +// 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'; + +function main(name) { + // [START cloudasset_v1p2beta1_generated_AssetService_GetFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the Feed and it must be in the format of: + * projects/project_number/feeds/feed_id + * folders/folder_number/feeds/feed_id + * organizations/organization_number/feeds/feed_id + */ + // const name = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p2beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function getFeed() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await assetClient.getFeed(request); + console.log(response); + } + + getFeed(); + // [END cloudasset_v1p2beta1_generated_AssetService_GetFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.list_feeds.js b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.list_feeds.js new file mode 100644 index 000000000000..c0e67b8d0ab0 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.list_feeds.js @@ -0,0 +1,54 @@ +// 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. +// 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'; + +function main(parent) { + // [START cloudasset_v1p2beta1_generated_AssetService_ListFeeds_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The parent project/folder/organization whose feeds are to be + * listed. It can only be using project/folder/organization number (such as + * "folders/12345")", or a project ID (such as "projects/my-project-id"). + */ + // const parent = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p2beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function listFeeds() { + // Construct request + const request = { + parent, + }; + + // Run request + const response = await assetClient.listFeeds(request); + console.log(response); + } + + listFeeds(); + // [END cloudasset_v1p2beta1_generated_AssetService_ListFeeds_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.update_feed.js b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.update_feed.js new file mode 100644 index 000000000000..0cfbf0c23190 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p2beta1/asset_service.update_feed.js @@ -0,0 +1,63 @@ +// 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. +// 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'; + +function main(feed, updateMask) { + // [START cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The new values of feed details. It must match an existing feed and the + * field `name` must be in the format of: + * projects/project_number/feeds/feed_id or + * folders/folder_number/feeds/feed_id or + * organizations/organization_number/feeds/feed_id. + */ + // const feed = '' + /** + * Required. Only updates the `feed` fields indicated by this mask. + * The field mask must not be empty, and it must not contain fields that + * are immutable or only set by the server. + */ + // const updateMask = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p2beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function updateFeed() { + // Construct request + const request = { + feed, + updateMask, + }; + + // Run request + const response = await assetClient.updateFeed(request); + console.log(response); + } + + updateFeed(); + // [END cloudasset_v1p2beta1_generated_AssetService_UpdateFeed_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p4beta1/asset_service.analyze_iam_policy.js b/packages/google-cloud-asset/samples/generated/v1p4beta1/asset_service.analyze_iam_policy.js new file mode 100644 index 000000000000..40f9fe5cab55 --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p4beta1/asset_service.analyze_iam_policy.js @@ -0,0 +1,56 @@ +// 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. +// 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'; + +function main(analysisQuery) { + // [START cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The request query. + */ + // const analysisQuery = '' + /** + * Optional. The request options. + */ + // const options = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p4beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function analyzeIamPolicy() { + // Construct request + const request = { + analysisQuery, + }; + + // Run request + const response = await assetClient.analyzeIamPolicy(request); + console.log(response); + } + + analyzeIamPolicy(); + // [END cloudasset_v1p4beta1_generated_AssetService_AnalyzeIamPolicy_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p4beta1/asset_service.export_iam_policy_analysis.js b/packages/google-cloud-asset/samples/generated/v1p4beta1/asset_service.export_iam_policy_analysis.js new file mode 100644 index 000000000000..e72fda42acad --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p4beta1/asset_service.export_iam_policy_analysis.js @@ -0,0 +1,62 @@ +// 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. +// 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'; + +function main(analysisQuery, outputConfig) { + // [START cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The request query. + */ + // const analysisQuery = '' + /** + * Optional. The request options. + */ + // const options = '' + /** + * Required. Output configuration indicating where the results will be output to. + */ + // const outputConfig = '' + + // Imports the Asset library + const {AssetServiceClient} = require('@google-cloud/asset').v1p4beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function exportIamPolicyAnalysis() { + // Construct request + const request = { + analysisQuery, + outputConfig, + }; + + // Run request + const [operation] = await assetClient.exportIamPolicyAnalysis(request); + const [response] = await operation.promise(); + console.log(response); + } + + exportIamPolicyAnalysis(); + // [END cloudasset_v1p4beta1_generated_AssetService_ExportIamPolicyAnalysis_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/generated/v1p5beta1/asset_service.list_assets.js b/packages/google-cloud-asset/samples/generated/v1p5beta1/asset_service.list_assets.js new file mode 100644 index 000000000000..b4424c7c9b3f --- /dev/null +++ b/packages/google-cloud-asset/samples/generated/v1p5beta1/asset_service.list_assets.js @@ -0,0 +1,89 @@ +// 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. +// 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'; + +function main(parent) { + // [START cloudasset_v1p5beta1_generated_AssetService_ListAssets_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. Name of the organization or project the assets belong to. Format: + * "organizations/[organization-number]" (such as "organizations/123"), + * "projects/[project-number]" (such as "projects/my-project-id"), or + * "projects/[project-id]" (such as "projects/12345"). + */ + // const parent = 'abc123' + /** + * Timestamp to take an asset snapshot. This can only be set to a timestamp + * between 2018-10-02 UTC (inclusive) and the current time. If not specified, + * the current time will be used. Due to delays in resource data collection + * and indexing, there is a volatile window during which running the same + * query may get different results. + */ + // const readTime = '' + /** + * A list of asset types of which to take a snapshot for. For example: + * "compute.googleapis.com/Disk". If specified, only matching assets will be + * returned. See [Introduction to Cloud Asset + * Inventory](https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview) + * for all supported asset types. + */ + // const assetTypes = 'abc123' + /** + * Asset content type. If not specified, no content but the asset name will + * be returned. + */ + // const contentType = '' + /** + * The maximum number of assets to be returned in a single response. Default + * is 100, minimum is 1, and maximum is 1000. + */ + // const pageSize = 1234 + /** + * The `next_page_token` returned from the previous `ListAssetsResponse`, or + * unspecified for the first `ListAssetsRequest`. It is a continuation of a + * prior `ListAssets` call, and the API should return the next page of assets. + */ + // const pageToken = 'abc123' + + // Imports the Asset library + const {AssetServiceClient} = require('asset').v1p5beta1; + + // Instantiates a client + const assetClient = new AssetServiceClient(); + + async function listAssets() { + // Construct request + const request = { + parent, + }; + + // Run request + const iterable = await assetClient.listAssetsAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + listAssets(); + // [END cloudasset_v1p5beta1_generated_AssetService_ListAssets_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-asset/samples/package.json b/packages/google-cloud-asset/samples/package.json index 45fc6eadb922..ae1ab6cf42ab 100644 --- a/packages/google-cloud-asset/samples/package.json +++ b/packages/google-cloud-asset/samples/package.json @@ -4,7 +4,7 @@ "license": "Apache-2.0", "author": "Google Inc.", "engines": { - "node": ">=8" + "node": ">=10" }, "files": [ "*.js" diff --git a/packages/google-cloud-asset/src/v1/asset_service_client.ts b/packages/google-cloud-asset/src/v1/asset_service_client.ts index a27708e9e7d7..29343243d2bd 100644 --- a/packages/google-cloud-asset/src/v1/asset_service_client.ts +++ b/packages/google-cloud-asset/src/v1/asset_service_client.ts @@ -1756,7 +1756,8 @@ export class AssetServiceClient { gax.routingHeader.fromParams({ parent: request.parent || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listAssets']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listAssets.createStream( this.innerApiCalls.listAssets as gax.GaxCall, @@ -1856,7 +1857,8 @@ export class AssetServiceClient { parent: request.parent || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listAssets']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listAssets.asyncIterate( this.innerApiCalls['listAssets'] as GaxCall, @@ -2248,7 +2250,8 @@ export class AssetServiceClient { gax.routingHeader.fromParams({ scope: request.scope || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllResources']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllResources.createStream( this.innerApiCalls.searchAllResources as gax.GaxCall, @@ -2422,7 +2425,8 @@ export class AssetServiceClient { scope: request.scope || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllResources']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllResources.asyncIterate( this.innerApiCalls['searchAllResources'] as GaxCall, @@ -2742,7 +2746,8 @@ export class AssetServiceClient { gax.routingHeader.fromParams({ scope: request.scope || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllIamPolicies']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllIamPolicies.createStream( this.innerApiCalls.searchAllIamPolicies as gax.GaxCall, @@ -2880,7 +2885,8 @@ export class AssetServiceClient { scope: request.scope || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllIamPolicies']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllIamPolicies.asyncIterate( this.innerApiCalls['searchAllIamPolicies'] as GaxCall, diff --git a/packages/google-cloud-asset/src/v1p1beta1/asset_service_client.ts b/packages/google-cloud-asset/src/v1p1beta1/asset_service_client.ts index 4ad954dd9b30..1cfca2194f5b 100644 --- a/packages/google-cloud-asset/src/v1p1beta1/asset_service_client.ts +++ b/packages/google-cloud-asset/src/v1p1beta1/asset_service_client.ts @@ -490,7 +490,8 @@ export class AssetServiceClient { gax.routingHeader.fromParams({ scope: request.scope || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllResources']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllResources.createStream( this.innerApiCalls.searchAllResources as gax.GaxCall, @@ -561,7 +562,8 @@ export class AssetServiceClient { scope: request.scope || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllResources']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllResources.asyncIterate( this.innerApiCalls['searchAllResources'] as GaxCall, @@ -739,7 +741,8 @@ export class AssetServiceClient { gax.routingHeader.fromParams({ scope: request.scope || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllIamPolicies']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllIamPolicies.createStream( this.innerApiCalls.searchAllIamPolicies as gax.GaxCall, @@ -805,7 +808,8 @@ export class AssetServiceClient { scope: request.scope || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['searchAllIamPolicies']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.searchAllIamPolicies.asyncIterate( this.innerApiCalls['searchAllIamPolicies'] as GaxCall, diff --git a/packages/google-cloud-asset/src/v1p5beta1/asset_service_client.ts b/packages/google-cloud-asset/src/v1p5beta1/asset_service_client.ts index b3bafc68aa2c..8db22838d819 100644 --- a/packages/google-cloud-asset/src/v1p5beta1/asset_service_client.ts +++ b/packages/google-cloud-asset/src/v1p5beta1/asset_service_client.ts @@ -494,7 +494,8 @@ export class AssetServiceClient { gax.routingHeader.fromParams({ parent: request.parent || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listAssets']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listAssets.createStream( this.innerApiCalls.listAssets as gax.GaxCall, @@ -565,7 +566,8 @@ export class AssetServiceClient { parent: request.parent || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listAssets']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listAssets.asyncIterate( this.innerApiCalls['listAssets'] as GaxCall,