in blueprints/cloud-operations/compute-quota-monitoring/src/main.py [0:0]
def discover_projects(discovery_root):
'Discovers projects under a folder or organization.'
if discovery_root.partition('/')[0] not in ('folders', 'organizations'):
raise SystemExit(f'Invalid discovery root {discovery_root}.')
next_page_token = ''
while True:
list_assets_results = fetch(
HTTPRequest(URL_DISCOVERY.format(discovery_root, next_page_token)))
if 'assets' in list_assets_results:
for asset in list_assets_results['assets']:
if (asset['resource']['data']['lifecycleState'] == 'ACTIVE'):
yield asset['resource']['data']['projectId']
next_page_token = list_assets_results.get('nextPageToken')
if not next_page_token:
break