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!',
},
{
'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)
)

View File

@ -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'
)

View File

@ -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')