Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions asset/cloud-client/quickstart_exportassets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def export_assets(project_id, dump_file_path):
from google.cloud import asset_v1beta1
from google.cloud.asset_v1beta1.proto import asset_service_pb2

# TODO project_id = "Your Google Cloud Project ID"
# TODO dump_file_path = "Your asset dump file path"
# TODO project_id = 'Your Google Cloud Project ID'
# TODO dump_file_path = 'Your asset dump file path'

client = asset_v1beta1.AssetServiceClient()
parent = client.project_path(project_id)
output_config = asset_service_pb2.OutputConfig()
output_config.gcs_destination.uri = dump_file_path
response = client.export_assets(parent, output_config)
print(response.result)
print(response.result())
# [END asset_quickstart_exportassets]


Expand All @@ -42,9 +42,10 @@ def export_assets(project_id, dump_file_path):
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument('project_id', help='Your Google Cloud project ID')
parser.add_argument('dump_file_path',
help='The file ExportAssets API will dump assets to, '
'e.g.: gs://<bucket-name>/asset_dump_file')
parser.add_argument(
'dump_file_path',
help='The file ExportAssets API will dump assets to, '
'e.g.: gs://<bucket-name>/asset_dump_file')

args = parser.parse_args()

Expand Down
12 changes: 7 additions & 5 deletions asset/cloud-client/quickstart_exportassets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
# limitations under the License.

import os
import time

from google.cloud import storage
import pytest

import quickstart_exportassets

PROJECT = os.environ['GCLOUD_PROJECT']
BUCKET = 'bucket-for-assets'
BUCKET = 'assets-{}'.format(int(time.time()))


@pytest.fixture(scope='module')
Expand All @@ -36,15 +37,16 @@ def asset_bucket(storage_client):

try:
storage_client.delete_bucket(BUCKET)
except Exception:
pass
except Exception as e:
print('Failed to delete bucket{}'.format(BUCKET))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space between bucket and {}:

print('Failed to delete bucket: {}'.format(BUCKET))

raise e

yield BUCKET


def test_export_assets(asset_bucket, capsys):
dump_file_path = "gs://", asset_bucket, "/assets-dump.txt"
dump_file_path = 'gs://{}/assets-dump.txt'.format(asset_bucket)
quickstart_exportassets.export_assets(PROJECT, dump_file_path)
out, _ = capsys.readouterr()

assert "uri: \"gs://cai-prober-prod-for-assets/phython-test.txt\"" in out
assert dump_file_path in out
2 changes: 2 additions & 0 deletions asset/cloud-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
google-cloud-storage==1.13.0
google-cloud-asset==0.1.1