Minor fixes to S3.put signature (#840)

This commit is contained in:
kevgliss 2017-06-27 16:18:34 -07:00 committed by GitHub
parent c05343d58e
commit 98907e66e9
3 changed files with 15 additions and 9 deletions

View File

@ -281,7 +281,7 @@ class S3DestinationPlugin(ExportDestinationPlugin):
'helpMessage': 'Must be a valid S3 bucket name!', 'helpMessage': 'Must be a valid S3 bucket name!',
}, },
{ {
'name': 'account_number', 'name': 'accountNumber',
'type': 'str', 'type': 'str',
'required': True, 'required': True,
'validation': '/^[0-9]{12,12}$/', 'validation': '/^[0-9]{12,12}$/',
@ -319,13 +319,13 @@ class S3DestinationPlugin(ExportDestinationPlugin):
for ext, passphrase, data in files: for ext, passphrase, data in files:
s3.put( s3.put(
self.get_option('region', options),
self.get_option('bucket', 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), prefix=self.get_option('prefix', options),
name=name, name=name,
extension=ext), extension=ext),
self.get_option('encrypt', options),
data, data,
self.get_option('encrypt', options),
account_number=self.get_option('accountNumber', options) account_number=self.get_option('accountNumber', options)
) )

View File

@ -10,24 +10,28 @@ from flask import current_app
from .sts import sts_client from .sts import sts_client
@sts_client('s3', 'resource') @sts_client('s3', service_type='resource')
def put(resource, bucket_name, prefix, data, encrypt): def put(bucket_name, region, prefix, data, encrypt, **kwargs):
""" """
Use STS to write to an S3 bucket 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)) 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: if encrypt:
bucket.put_object( bucket.put_object(
Key=prefix, Key=prefix,
Body=data.encode('utf-8'), Body=data,
ACL='bucket-owner-full-control', ACL='bucket-owner-full-control',
ServerSideEncryption='AES256' ServerSideEncryption='AES256'
) )
else: else:
bucket.put_object( bucket.put_object(
Key=prefix, Key=prefix,
Body=data.encode('utf-8'), Body=data,
ACL='bucket-owner-full-control' ACL='bucket-owner-full-control'
) )

View File

@ -22,6 +22,8 @@ def sts_client(service, service_type='client'):
current_app.config.get('LEMUR_INSTANCE_PROFILE', 'Lemur') 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 # TODO add user specific information to RoleSessionName
role = sts.assume_role(RoleArn=arn, RoleSessionName='lemur') role = sts.assume_role(RoleArn=arn, RoleSessionName='lemur')