|
| 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 | +function main(parent) { |
| 18 | + // [START cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_async] |
| 19 | + /** |
| 20 | + * TODO(developer): Uncomment these variables before running the sample. |
| 21 | + */ |
| 22 | + /** |
| 23 | + * Required. The relative name of the root asset. It can only be an |
| 24 | + * organization number (such as "organizations/123"), a project ID (such as |
| 25 | + * "projects/my-project-id")", or a project number (such as "projects/12345"). |
| 26 | + */ |
| 27 | + // const parent = 'abc123' |
| 28 | + /** |
| 29 | + * A list of the full names of the assets. |
| 30 | + * See: https://cloud.google.com/asset-inventory/docs/resource-name-format |
| 31 | + * Example: |
| 32 | + * `//compute.googleapis.com/projects/my_project_123/zones/zone1/instances/instance1`. |
| 33 | + * The request becomes a no-op if the asset name list is empty, and the max |
| 34 | + * size of the asset name list is 100 in one request. |
| 35 | + */ |
| 36 | + // const assetNames = 'abc123' |
| 37 | + /** |
| 38 | + * Optional. The content type. |
| 39 | + */ |
| 40 | + // const contentType = '' |
| 41 | + /** |
| 42 | + * Optional. The time window for the asset history. Both start_time and |
| 43 | + * end_time are optional and if set, it must be after the current time minus |
| 44 | + * 35 days. If end_time is not set, it is default to current timestamp. |
| 45 | + * If start_time is not set, the snapshot of the assets at end_time will be |
| 46 | + * returned. The returned results contain all temporal assets whose time |
| 47 | + * window overlap with read_time_window. |
| 48 | + */ |
| 49 | + // const readTimeWindow = '' |
| 50 | + /** |
| 51 | + * Optional. A list of relationship types to output, for example: |
| 52 | + * `INSTANCE_TO_INSTANCEGROUP`. This field should only be specified if |
| 53 | + * content_type=RELATIONSHIP. |
| 54 | + * * If specified: |
| 55 | + * it outputs specified relationships' history on the [asset_names]. It |
| 56 | + * returns an error if any of the [relationship_types] doesn't belong to the |
| 57 | + * supported relationship types of the [asset_names] or if any of the |
| 58 | + * [asset_names]'s types doesn't belong to the source types of the |
| 59 | + * [relationship_types]. |
| 60 | + * * Otherwise: |
| 61 | + * it outputs the supported relationships' history on the [asset_names] or |
| 62 | + * returns an error if any of the [asset_names]'s types has no relationship |
| 63 | + * support. |
| 64 | + * See [Introduction to Cloud Asset |
| 65 | + * Inventory](https://cloud.google.com/asset-inventory/docs/overview) for all |
| 66 | + * supported asset types and relationship types. |
| 67 | + */ |
| 68 | + // const relationshipTypes = 'abc123' |
| 69 | + |
| 70 | + // Imports the Asset library |
| 71 | + const {AssetServiceClient} = require('@google-cloud/asset').v1; |
| 72 | + |
| 73 | + // Instantiates a client |
| 74 | + const assetClient = new AssetServiceClient(); |
| 75 | + |
| 76 | + async function batchGetAssetsHistory() { |
| 77 | + // Construct request |
| 78 | + const request = { |
| 79 | + parent, |
| 80 | + }; |
| 81 | + |
| 82 | + // Run request |
| 83 | + const response = await assetClient.batchGetAssetsHistory(request); |
| 84 | + console.log(response); |
| 85 | + } |
| 86 | + |
| 87 | + batchGetAssetsHistory(); |
| 88 | + // [END cloudasset_v1_generated_AssetService_BatchGetAssetsHistory_async] |
| 89 | +} |
| 90 | + |
| 91 | +process.on('unhandledRejection', err => { |
| 92 | + console.error(err.message); |
| 93 | + process.exitCode = 1; |
| 94 | +}); |
| 95 | +main(...process.argv.slice(2)); |
0 commit comments