Implement new settings for s3 (#328)

* Fix s3 path documented as an int

* Implement new settings for s3 storage
This commit is contained in:
William Desportes
2022-06-20 15:47:29 +02:00
committed by GitHub
parent 6354c9bce7
commit 9671a49166
4 changed files with 41 additions and 4 deletions
+5 -1
View File
@@ -281,7 +281,11 @@ The full set of configuration options are:
- ``message`` - str: The email message (Default: Please see the attached parsedmarc report.)
- ``s3``
- ``bucket`` - str: The S3 bucket name
- ``path`` - int: The path to upload reports to (Default: /)
- ``path`` - str: The path to upload reports to (Default: /)
- ``region_name`` - str: The region name (Optional)
- ``endpoint_url`` - str: The endpoint URL (Optional)
- ``access_key_id`` - str: The access key id (Optional)
- ``secret_access_key`` - str: The secret access key (Optional)
- ``syslog``
- ``server`` - str: The Syslog server name or IP address
- ``port`` - int: The UDP port to use (Default: 514)
+5 -1
View File
@@ -280,7 +280,11 @@ The full set of configuration options are:
- ``s3``
- ``bucket`` - str: The S3 bucket name
- ``path`` - int: The path to upload reports to (Default: /)
- ``path`` - str: The path to upload reports to (Default: /)
- ``region_name`` - str: The region name (Optional)
- ``endpoint_url`` - str: The endpoint URL (Optional)
- ``access_key_id`` - str: The access key id (Optional)
- ``secret_access_key`` - str: The secret access key (Optional)
- ``syslog``
- ``server`` - str: The Syslog server name or IP address
- ``port`` - int: The UDP port to use (Default: 514)
+18
View File
@@ -92,6 +92,10 @@ def _main():
s3_client = s3.S3Client(
bucket_name=opts.s3_bucket,
bucket_path=opts.s3_path,
region_name=opts.s3_region_name,
endpoint_url=opts.s3_endpoint_url,
access_key_id=opts.s3_access_key_id,
secret_access_key=opts.s3_secret_access_key,
)
except Exception as error_:
logger.error("S3 Error: {0}".format(error_.__str__()))
@@ -314,6 +318,10 @@ def _main():
smtp_message="Please see the attached DMARC results.",
s3_bucket=None,
s3_path=None,
s3_region_name=None,
s3_endpoint_url=None,
s3_access_key_id=None,
s3_secret_access_key=None,
syslog_server=None,
syslog_port=None,
gmail_api_credentials_file=None,
@@ -681,6 +689,16 @@ def _main():
opts.s3_path = opts.s3_path[:-1]
else:
opts.s3_path = ""
if "region_name" in s3_config:
opts.s3_region_name = s3_config["region_name"]
if "endpoint_url" in s3_config:
opts.s3_endpoint_url = s3_config["endpoint_url"]
if "access_key_id" in s3_config:
opts.s3_access_key_id = s3_config["access_key_id"]
if "secret_access_key" in s3_config:
opts.s3_secret_access_key = s3_config["secret_access_key"]
if "syslog" in config.sections():
syslog_config = config["syslog"]
if "server" in syslog_config:
+13 -2
View File
@@ -12,12 +12,16 @@ logger = logging.getLogger("parsedmarc")
class S3Client(object):
"""A client for a Amazon S3"""
def __init__(self, bucket_name, bucket_path):
def __init__(self, bucket_name, bucket_path, region_name, endpoint_url, access_key_id, secret_access_key):
"""
Initializes the S3Client
Args:
bucket_name (str): The S3 Bucket
bucket_path (str): The path to save reports
region_name (str): The region name
endpoint_url (str): The endpoint URL
access_key_id (str): The access key id
secret_access_key (str): The secret access key
"""
self.bucket_name = bucket_name
self.bucket_path = bucket_path
@@ -29,7 +33,14 @@ class S3Client(object):
"end_date",
]
self.s3 = boto3.resource('s3')
# https://github.com/boto/boto3/blob/1.24.7/boto3/session.py#L312
self.s3 = boto3.resource(
's3',
region_name=region_name,
endpoint_url=endpoint_url,
aws_access_key_id=access_key_id,
aws_secret_access_key=secret_access_key,
)
self.bucket = self.s3.Bucket(self.bucket_name)
def save_aggregate_report_to_s3(self, report):