|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright 2018 Google LLC. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | + |
| 18 | +import argparse |
| 19 | + |
| 20 | + |
| 21 | +def export_assets(project_id, dump_file_path): |
| 22 | + # [START asset_quickstart_exportassets] |
| 23 | + from google.cloud import asset_v1beta1 |
| 24 | + from google.cloud.asset_v1beta1.proto import asset_service_pb2 |
| 25 | + |
| 26 | + # TODO project_id = "Your Google Cloud Project ID" |
| 27 | + # TODO dump_file_path = "Your asset dump file path" |
| 28 | + |
| 29 | + client = asset_v1beta1.AssetServiceClient() |
| 30 | + parent = client.project_path(project_id) |
| 31 | + output_config = asset_service_pb2.OutputConfig() |
| 32 | + output_config.gcs_destination.uri = dump_file_path |
| 33 | + response = client.export_assets(parent, output_config) |
| 34 | + print(response.result) |
| 35 | + # [END asset_quickstart_exportassets] |
| 36 | + |
| 37 | + |
| 38 | +if __name__ == '__main__': |
| 39 | + |
| 40 | + parser = argparse.ArgumentParser( |
| 41 | + description=__doc__, |
| 42 | + formatter_class=argparse.RawDescriptionHelpFormatter |
| 43 | + ) |
| 44 | + parser.add_argument('project_id', help='Your Google Cloud project ID') |
| 45 | + parser.add_argument('dump_file_path', |
| 46 | + help='The file ExportAssets API will dump assets to, ' |
| 47 | + 'e.g.: gs://<bucket-name>/asset_dump_file') |
| 48 | + |
| 49 | + args = parser.parse_args() |
| 50 | + |
| 51 | + export_assets(args.project_id, args.dump_file_path) |
0 commit comments