* Added error handling in case the aws cli wasn't properly installed.

This commit is contained in:
maor.rayzin 2018-11-27 22:28:06 +02:00
parent 2f1240cc0e
commit 83ea8af9e0
1 changed files with 8 additions and 4 deletions

View File

@ -2,6 +2,7 @@ import logging
import uuid import uuid
from datetime import datetime from datetime import datetime
import boto3 import boto3
from botocore.exceptions import UnknownServiceError
from cc.resources.exporter import Exporter from cc.resources.exporter import Exporter
from cc.services.config import ConfigService from cc.services.config import ConfigService
@ -93,17 +94,20 @@ class AWSExporter(Exporter):
@staticmethod @staticmethod
def _send_findings(findings_list, creds_dict): def _send_findings(findings_list, creds_dict):
securityhub = boto3.client('securityhub',
aws_access_key_id=creds_dict.get('aws_access_key_id', ''),
aws_secret_access_key=creds_dict.get('aws_secret_access_key', ''))
try: try:
securityhub = boto3.client('securityhub',
aws_access_key_id=creds_dict.get('aws_access_key_id', ''),
aws_secret_access_key=creds_dict.get('aws_secret_access_key', ''))
import_response = securityhub.batch_import_findings(Findings=findings_list) import_response = securityhub.batch_import_findings(Findings=findings_list)
print import_response print import_response
if import_response['ResponseMetadata']['HTTPStatusCode'] == 200: if import_response['ResponseMetadata']['HTTPStatusCode'] == 200:
return True return True
else: else:
return False return False
except UnknownServiceError as e:
logger.warning('AWS exporter called but AWS-CLI not installed')
return False
except Exception as e: except Exception as e:
logger.error('AWS security hub findings failed to send.') logger.error('AWS security hub findings failed to send.')
return False return False