diff --git a/lemur/plugins/lemur_aws/plugin.py b/lemur/plugins/lemur_aws/plugin.py index 28c34acd..c9da599b 100644 --- a/lemur/plugins/lemur_aws/plugin.py +++ b/lemur/plugins/lemur_aws/plugin.py @@ -281,7 +281,7 @@ class S3DestinationPlugin(ExportDestinationPlugin): 'helpMessage': 'Must be a valid S3 bucket name!', }, { - 'name': 'account_number', + 'name': 'accountNumber', 'type': 'str', 'required': True, 'validation': '/^[0-9]{12,12}$/', @@ -319,13 +319,13 @@ class S3DestinationPlugin(ExportDestinationPlugin): for ext, passphrase, data in files: s3.put( - self.get_option('region', options), self.get_option('bucket', options), - '{prefix}/{name}{extension}'.format( + self.get_option('region', options), + '{prefix}/{name}.{extension}'.format( prefix=self.get_option('prefix', options), name=name, extension=ext), - self.get_option('encrypt', options), data, + self.get_option('encrypt', options), account_number=self.get_option('accountNumber', options) ) diff --git a/lemur/plugins/lemur_aws/s3.py b/lemur/plugins/lemur_aws/s3.py index 0ba7aa4b..9e98d3c5 100644 --- a/lemur/plugins/lemur_aws/s3.py +++ b/lemur/plugins/lemur_aws/s3.py @@ -10,24 +10,28 @@ from flask import current_app from .sts import sts_client -@sts_client('s3', 'resource') -def put(resource, bucket_name, prefix, data, encrypt): +@sts_client('s3', service_type='resource') +def put(bucket_name, region, prefix, data, encrypt, **kwargs): """ Use STS to write to an S3 bucket """ - bucket = resource.Bucket(bucket_name) + bucket = kwargs['resource'].Bucket(bucket_name) current_app.logger.debug('Persisting data to S3. Bucket: {0} Prefix: {1}'.format(bucket_name, prefix)) + # get data ready for writing + if isinstance(data, str): + data = data.encode('utf-8') + if encrypt: bucket.put_object( Key=prefix, - Body=data.encode('utf-8'), + Body=data, ACL='bucket-owner-full-control', ServerSideEncryption='AES256' ) else: bucket.put_object( Key=prefix, - Body=data.encode('utf-8'), + Body=data, ACL='bucket-owner-full-control' ) diff --git a/lemur/plugins/lemur_aws/sts.py b/lemur/plugins/lemur_aws/sts.py index 0ef1c3f8..d82297e5 100644 --- a/lemur/plugins/lemur_aws/sts.py +++ b/lemur/plugins/lemur_aws/sts.py @@ -22,6 +22,8 @@ def sts_client(service, service_type='client'): current_app.config.get('LEMUR_INSTANCE_PROFILE', 'Lemur') ) + current_app.logger.debug('Assuming Role. Role: {0}'.format(arn)) + # TODO add user specific information to RoleSessionName role = sts.assume_role(RoleArn=arn, RoleSessionName='lemur')