Skip to content

Commit

Permalink
Improve throttling check
Browse files Browse the repository at this point in the history
  • Loading branch information
x4v13r64 committed Mar 22, 2020
1 parent 3266f9d commit e075cc3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ScoutSuite/providers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ async def run_concurrently(function, backoff_seconds=15):
return await run_function_concurrently(function)
except Exception as e:
# Determine whether the exception is due to API throttling
throttled = aws_is_throttled(e) # FIXME - this only works for AWS
if throttled:
if is_throttled(e):
print_info('Hitting API rate limiting, will retry in {}s'.format(backoff_seconds))
await asyncio.sleep(backoff_seconds)
return await run_concurrently(function, backoff_seconds + 15)
Expand Down Expand Up @@ -105,3 +104,15 @@ async def map_concurrently(coroutine, entities, **kwargs):
results.append(result)

return results


def is_throttled(e):
"""
Function that tries to determine if an exception was caused by throttling
TODO - this implementation is incomplete
"""

if hasattr(e, 'message') and 'Google Cloud' in e.message:
return False
else:
return aws_is_throttled(e)

0 comments on commit e075cc3

Please sign in to comment.