in processors/cai.py [0:0]
def process(self, output_var='assets'):
cai_config = self.config
if 'parent' not in cai_config:
raise NotConfiguredException('No parent configured!')
cai_service = discovery.build('cloudasset',
'v1',
http=self._get_branded_http())
request_parameters = {}
request_parameters['parent'] = self._jinja_expand_string(
cai_config['parent'])
for k in ['readTime', 'pageSize', 'contentType']:
if k in cai_config:
request_parameters[k] = self._jinja_expand_string(cai_config[k])
if 'assetTypes' in cai_config:
request_parameters['assetTypes'] = self._jinja_var_to_list(
cai_config['assetTypes'])
indexing = 'asset_type'
if 'indexing' in cai_config:
if cai_config['indexing'] == 'list':
indexing = 'list'
if indexing == 'asset_type':
assets = {}
else:
assets = []
page_token = None
while True:
if page_token is not None:
request_parameters['pageToken'] = page_token
request = cai_service.assets().list(**request_parameters)
response = request.execute()
if 'assets' in response:
for asset in response['assets']:
if indexing == 'asset_type':
if asset['assetType'] not in assets:
assets[asset['assetType']] = []
assets[asset['assetType']].append(asset)
elif indexing == 'list':
assets.append(asset)
if 'nextPageToken' in response:
page_token = response['nextPageToken']
else:
break
return {output_var: assets}