18
18
import argparse
19
19
20
20
21
- def list_assets (project_id , asset_types , page_size , content_type ):
21
+ def list_assets (project_id , asset_types , page_size , content_type , max_results = 0 ):
22
22
# [START asset_quickstart_list_assets]
23
23
from google .cloud import asset_v1
24
24
@@ -28,6 +28,7 @@ def list_assets(project_id, asset_types, page_size, content_type):
28
28
# TODO page_size = 'Num of assets in one page, which must be between 1 and
29
29
# 1000 (both inclusively)'
30
30
# TODO content_type ="Content type to list"
31
+ # max_results - total number of assets to return. max_results=0 returns all
31
32
32
33
project_resource = "projects/{}" .format (project_id )
33
34
client = asset_v1 .AssetServiceClient ()
@@ -43,13 +44,12 @@ def list_assets(project_id, asset_types, page_size, content_type):
43
44
}
44
45
)
45
46
46
- # DEBUGGING - remove before merging. See if timeouts are because there are so many assets being listed
47
- count = 0 # DEBUGGING
47
+ count = 0
48
48
for asset in response :
49
49
print (asset )
50
- count += 1 # DEBUGGING
51
- if count > 3 * page_size : # DEBUGGING
52
- break # DEBUGGING - three pages is plenty for a test
50
+ count += 1
51
+ if max_results > 0 and count >= max_results :
52
+ break
53
53
# [END asset_quickstart_list_assets]
54
54
55
55
@@ -74,4 +74,6 @@ def list_assets(project_id, asset_types, page_size, content_type):
74
74
75
75
asset_type_list = args .asset_types .split ("," )
76
76
77
- list_assets (args .project_id , asset_type_list , int (args .page_size ), args .content_type )
77
+ list_assets (
78
+ args .project_id , asset_type_list , int (args .page_size ), args .content_type
79
+ )
0 commit comments