def run(self):
"""Run command."""
self.run_command('ldist')
ldist_cmd = self.get_finalized_command('ldist')
dist_path = getattr(ldist_cmd, 'dist_path', None)
dist_name = getattr(ldist_cmd, 'dist_name', None)
if dist_path is None or dist_name is None:
raise DistutilsArgError('\'ldist\' missing attributes')
dist_name = getattr(self, 's3_prefix') + dist_name
s3 = boto3.client(
's3',
aws_access_key_id=getattr(self, 'access_key'),
aws_secret_access_key=getattr(self, 'secret_access_key'),
config=Config(signature_version='s3v4')
)
log.info('uploading {} to {} using kms key {}'.format(
dist_name,
getattr(self, 's3_bucket'),
getattr(self, 'kms_key_id')
))
with open(dist_path, 'rb') as dist:
if getattr(self, 'kms_key_id'):
response = s3.put_object(
Body=dist,
Bucket=getattr(self, 's3_bucket'),
Key=dist_name,
ServerSideEncryption='aws:kms',
SSEKMSKeyId=getattr(self, 'kms_key_id')
)
else:
response = s3.put_object(
Body=dist,
Bucket=getattr(self, 's3_bucket'),
Key=dist_name,
ServerSideEncryption='AES256'
)
log.info('upload complete:\n{}'.format(
json.dumps(response, sort_keys=True, indent=4, separators=(',', ': ')))
)
评论列表
文章目录