Skip to content

Commit

Permalink
Merge pull request nccgroup#902 from nccgroup/bugfix/gcp-service-usag…
Browse files Browse the repository at this point in the history
…e-calls

Improve error handling
  • Loading branch information
x4v13r64 authored Oct 16, 2020
2 parents 6441082 + bc161c2 commit 6c990ba
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ScoutSuite/providers/gcp/facade/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ async def is_api_enabled(self, project_id, service):

serviceusage_client = self._build_arbitrary_client('serviceusage', 'v1', force_new=True)
services = serviceusage_client.services()
request = services.list(parent=f'projects/{project_id}')
services_response = await GCPFacadeUtils.get_all('services', request, services)
try:
request = services.list(parent=f'projects/{project_id}')
services_response = await GCPFacadeUtils.get_all('services', request, services)
except Exception as e:
print_exception(f'Could not fetch the state of services for project \"{project_id}\", '
f'including {format_service_name(service.lower())} in the execution', {'exception': e})
return True

# These are hardcoded endpoint correspondences as there's no easy way to do this.
if service == 'IAM':
Expand All @@ -153,8 +158,8 @@ async def is_api_enabled(self, project_id, service):
elif service == 'StackdriverMonitoring':
endpoint = 'monitoring'
else:
print_debug('Could not validate the state of the {} API for project \"{}\", including it in the execution'.format(
format_service_name(service.lower()), project_id))
print_debug('Could not validate the state of the {} API for project \"{}\", '
'including it in the execution'.format(format_service_name(service.lower()), project_id))
return True

for s in services_response:
Expand All @@ -166,6 +171,6 @@ async def is_api_enabled(self, project_id, service):
project_id))
return False

print_error('Could not validate the state of the {} API for project \"{}\", including it in the execution'.format(
format_service_name(service.lower()), project_id))
print_error(f'Could not validate the state of the {format_service_name(service.lower())} API '
f'for project \"{project_id}\", including it in the execution')
return True

0 comments on commit 6c990ba

Please sign in to comment.