Modifying the was s3 uploading works. (#810)
* Modiying the was s3 uploading works. * Fixing pep8
This commit is contained in:
parent
4093f4669a
commit
f9b388c658
|
@ -285,56 +285,54 @@ class S3DestinationPlugin(DestinationPlugin):
|
||||||
{
|
{
|
||||||
'name': 'region',
|
'name': 'region',
|
||||||
'type': 'str',
|
'type': 'str',
|
||||||
'default': 'eu-west-1',
|
'default': 'us-east-1',
|
||||||
'required': False,
|
'required': False,
|
||||||
'validation': '/^\w+-\w+-\d+$/',
|
'helpMessage': 'Region bucket exists',
|
||||||
'helpMessage': 'Availability zone to use',
|
'available': ['us-east-1', 'us-west-2', 'eu-west-1']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'encrypt',
|
'name': 'encrypt',
|
||||||
'type': 'bool',
|
'type': 'bool',
|
||||||
'required': False,
|
'required': False,
|
||||||
'helpMessage': 'Availability zone to use',
|
'helpMessage': 'Enable server side encryption',
|
||||||
'default': True
|
'default': True
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'key',
|
'name': 'prefix',
|
||||||
'type': 'str',
|
'type': 'str',
|
||||||
'required': False,
|
'required': False,
|
||||||
'validation': '/^$|\s+/',
|
'validation': '/^$|\s+/',
|
||||||
'helpMessage': 'Must be a valid S3 object key!',
|
'helpMessage': 'Must be a valid S3 object prefix!',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'caKey',
|
'name': 'export-plugin',
|
||||||
'type': 'str',
|
'type': 'str',
|
||||||
'required': False,
|
'required': False
|
||||||
'validation': '/^$|\s+/',
|
|
||||||
'helpMessage': 'Must be a valid S3 object key!',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'name': 'certKey',
|
|
||||||
'type': 'str',
|
|
||||||
'required': False,
|
|
||||||
'validation': '/^$|\s+/',
|
|
||||||
'helpMessage': 'Must be a valid S3 object key!',
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(S3DestinationPlugin, self).__init__(*args, **kwargs)
|
super(S3DestinationPlugin, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def upload(self, name, body, private_key, cert_chain, options, **kwargs):
|
def upload(self, name, body, private_key, chain, options, **kwargs):
|
||||||
account_number = self.get_option('accountNumber', options)
|
# ensure our data is in the right format
|
||||||
encrypt = self.get_option('encrypt', options)
|
if self.get_option('export-plugin', options):
|
||||||
bucket = self.get_option('bucket', options)
|
pass
|
||||||
key = self.get_option('key', options)
|
|
||||||
ca_key = self.get_option('caKey', options)
|
|
||||||
cert_key = self.get_option('certKey', options)
|
|
||||||
|
|
||||||
if key and ca_key and cert_key:
|
# assume we want standard pem file
|
||||||
s3.write_to_s3(account_number, bucket, key, private_key, encrypt=encrypt)
|
|
||||||
s3.write_to_s3(account_number, bucket, ca_key, cert_chain, encrypt=encrypt)
|
|
||||||
s3.write_to_s3(account_number, bucket, cert_key, body, encrypt=encrypt)
|
|
||||||
else:
|
else:
|
||||||
pem_body = key + '\n' + body + '\n' + cert_chain + '\n'
|
# s3 doesn't require private key we write whatever we have
|
||||||
s3.write_to_s3(account_number, bucket, name, pem_body, encrypt=encrypt)
|
files = [(body, '.pem'), (private_key, '.key.pem'), (chain, '.chain.pem')]
|
||||||
|
|
||||||
|
for data, ext in files:
|
||||||
|
s3.put(
|
||||||
|
self.get_option('accountNumber', options),
|
||||||
|
self.get_option('region', options),
|
||||||
|
self.get_option('bucket', options),
|
||||||
|
'{prefix}/{name}{extension}'.format(
|
||||||
|
prefix=self.get_option('prefix', options),
|
||||||
|
name=name,
|
||||||
|
extension=ext),
|
||||||
|
self.get_option('encrypt', options),
|
||||||
|
data
|
||||||
|
)
|
||||||
|
|
|
@ -12,7 +12,7 @@ from .sts import sts_client
|
||||||
|
|
||||||
|
|
||||||
@sts_client('s3', 'resource')
|
@sts_client('s3', 'resource')
|
||||||
def write_to_s3(resource, bucket_name, prefix, data, encrypt=True):
|
def put(resource, bucket_name, prefix, data, encrypt):
|
||||||
"""
|
"""
|
||||||
Use STS to write to an S3 bucket
|
Use STS to write to an S3 bucket
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue