From 4d6e3462a93f403666f85c5385d7a26782cd11e4 Mon Sep 17 00:00:00 2001 From: misg Date: Tue, 9 Apr 2019 20:01:12 -0400 Subject: [PATCH] Handle exceptions in Azure StorageAccounts facade. --- .../providers/azure/facade/storageaccounts.py | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/ScoutSuite/providers/azure/facade/storageaccounts.py b/ScoutSuite/providers/azure/facade/storageaccounts.py index 2fdd4cdc9..bfe245633 100644 --- a/ScoutSuite/providers/azure/facade/storageaccounts.py +++ b/ScoutSuite/providers/azure/facade/storageaccounts.py @@ -3,6 +3,7 @@ from azure.mgmt.storage import StorageManagementClient from azure.mgmt.monitor import MonitorManagementClient from ScoutSuite.providers.utils import run_concurrently, get_and_set_concurrently +from ScoutSuite.core.console import print_exception class StorageAccountsFacade: @@ -12,17 +13,25 @@ def __init__(self, credentials, subscription_id): self._client = StorageManagementClient(credentials, subscription_id) async def get_storage_accounts(self): - storage_accounts = await run_concurrently( - lambda: list(self._client.storage_accounts.list()) - ) - await get_and_set_concurrently([self._get_and_set_activity_logs], storage_accounts) - - return storage_accounts + try: + storage_accounts = await run_concurrently( + lambda: list(self._client.storage_accounts.list()) + ) + except Exception as e: + print_exception('Failed to retrieve storage accounts: {}'.format(e)) + return [] + else: + await get_and_set_concurrently([self._get_and_set_activity_logs], storage_accounts) + return storage_accounts async def get_blob_containers(self, resource_group_name, storage_account_name): - return await run_concurrently( - lambda: list(self._client.blob_containers.list(resource_group_name, storage_account_name).value) - ) + try: + return await run_concurrently( + lambda: list(self._client.blob_containers.list(resource_group_name, storage_account_name).value) + ) + except Exception as e: + print_exception('Failed to retrieve blob containers: {}'.format(e)) + return [] async def _get_and_set_activity_logs(self, storage_account): client = MonitorManagementClient(self._credentials, self._subscription_id) @@ -40,7 +49,12 @@ async def _get_and_set_activity_logs(self, storage_account): "eventTimestamp le {}".format(utc_now.strftime(time_format)), "resourceId eq {}".format(storage_account.id), ]) - activity_logs = await run_concurrently( - lambda: list(client.activity_logs.list(filter=logs_filter, select="eventTimestamp, operationName")) - ) - setattr(storage_account, 'activity_logs', activity_logs) + try: + activity_logs = await run_concurrently( + lambda: list(client.activity_logs.list(filter=logs_filter, select="eventTimestamp, operationName")) + ) + except Exception as e: + print_exception('Failed to retrieve activity logs: {}'.format(e)) + setattr(storage_account, 'activity_logs', []) + else: + setattr(storage_account, 'activity_logs', activity_logs)