|
1 | 1 | /**
|
2 |
| - * Copyright 2018, Google LLC. |
| 2 | + * Copyright 2018, Google, LLC. |
3 | 3 | * Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | * you may not use this file except in compliance with the License.
|
5 | 5 | * You may obtain a copy of the License at
|
|
15 | 15 |
|
16 | 16 | 'use strict';
|
17 | 17 |
|
18 |
| -// [START asset_quickstart] |
19 |
| -// Imports the Google Cloud client library |
20 |
| -const asset = require('@google-cloud/asset'); |
| 18 | +async function exportAssets(dumpFilePath) { |
| 19 | + // [START asset_quickstart_exportassets] |
| 20 | + const asset = require('@google-cloud/asset'); |
| 21 | + const client = new asset.v1beta1.AssetServiceClient({ |
| 22 | + // optional auth parameters. |
| 23 | + }); |
21 | 24 |
|
22 |
| -// eslint-disable-next-line |
23 |
| -const client = new asset.AssetServiceClient({ |
24 |
| - projectId: 'your-project-id', |
25 |
| - keyFilename: '/path/to/keyfile.json', |
26 |
| -}); |
| 25 | + // Your Google Cloud Platform project ID |
| 26 | + const projectId = process.env.GCLOUD_PROJECT; |
| 27 | + const projectResource = client.projectPath(projectId); |
27 | 28 |
|
28 |
| -// [END asset_quickstart] |
| 29 | + // var dumpFilePath = 'Dump file path, e.g.: gs://<my_bucket>/<my_asset_file>' |
| 30 | + const outputConfig = { |
| 31 | + gcsDestination: { |
| 32 | + uri: dumpFilePath, |
| 33 | + }, |
| 34 | + }; |
| 35 | + const request = { |
| 36 | + parent: projectResource, |
| 37 | + outputConfig: outputConfig, |
| 38 | + }; |
| 39 | + |
| 40 | + // Handle the operation using the promise pattern. |
| 41 | + const [operation] = await client.exportAssets(request); |
| 42 | + // Operation#promise starts polling for the completion of the operation. |
| 43 | + const [result] = await operation.promise(); |
| 44 | + // Do things with with the response. |
| 45 | + console.log(result); |
| 46 | + // [END asset_quickstart_exportassets] |
| 47 | +} |
| 48 | + |
| 49 | +const cli = require('yargs') |
| 50 | + .demand(1) |
| 51 | + .command( |
| 52 | + 'export-assets <dumpFilePath>', |
| 53 | + 'Export asserts to specified dump file path.', |
| 54 | + {}, |
| 55 | + opts => exportAssets(opts.dumpFilePath) |
| 56 | + ) |
| 57 | + .example( |
| 58 | + 'node $0 export-assets gs://my-bucket/my-assets.txt', |
| 59 | + 'Export assets to gs://my-bucket/my-assets.txt.' |
| 60 | + ) |
| 61 | + .wrap(10) |
| 62 | + .recommendCommands() |
| 63 | + .epilogue( |
| 64 | + 'https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview' |
| 65 | + ) |
| 66 | + .help() |
| 67 | + .strict(); |
| 68 | + |
| 69 | +if (module === require.main) { |
| 70 | + cli.parse(process.argv.slice(2)); |
| 71 | +} |
0 commit comments