def upload(self, name, body, private_key, chain, options, **kwargs): files = self.export(body, private_key, chain, options) for ext, passphrase, data in files: s3.put(self.get_option('bucket', options), self.get_option('region', options), '{prefix}/{name}.{extension}'.format(prefix=self.get_option( 'prefix', options), name=name, extension=ext), data, self.get_option('encrypt', options), account_number=self.get_option('accountNumber', options))
def upload(self, name, body, private_key, chain, options, **kwargs): files = self.export(body, private_key, chain, options) for ext, passphrase, data in files: s3.put( self.get_option("bucket", options), self.get_option("region", options), "{prefix}/{name}.{extension}".format( prefix=self.get_option("prefix", options), name=name, extension=ext ), data, self.get_option("encrypt", options), account_number=self.get_option("accountNumber", options), )
def upload(self, name, body, private_key, chain, options, **kwargs): files = self.export(body, private_key, chain, options) for ext, passphrase, data in files: s3.put( self.get_option('bucket', options), self.get_option('region', options), '{prefix}/{name}.{extension}'.format( prefix=self.get_option('prefix', options), name=name, extension=ext), data, self.get_option('encrypt', options), account_number=self.get_option('accountNumber', options) )
def test_put_delete_s3_object(app): from lemur.plugins.lemur_aws.s3 import put, delete, get bucket = "public-bucket" region = "us-east-1" account = "123456789012" path = "some-path/foo" data = "dummy data" s3_client = boto3.client('s3') s3_client.create_bucket(Bucket=bucket) put(bucket_name=bucket, region_name=region, prefix=path, data=data, encrypt=False, account_number=account, region=region) response = get(bucket_name=bucket, prefixed_object_name=path, account_number=account) # put data, and getting the same data assert (response == data) response = get(bucket_name="wrong-bucket", prefixed_object_name=path, account_number=account) # attempting to get thccle wrong data assert (response is None) delete(bucket_name=bucket, prefixed_object_name=path, account_number=account) response = get(bucket_name=bucket, prefixed_object_name=path, account_number=account) # delete data, and getting the same data assert (response is None)
def upload(self, name, body, private_key, chain, options, **kwargs): # ensure our data is in the right format if self.get_option('export-plugin', options): pass # assume we want standard pem file else: # s3 doesn't require private key we write whatever we have files = [(body, '.pem'), (private_key, '.key.pem'), (chain, '.chain.pem')] for data, ext in files: s3.put(account_number=self.get_option('account_number', options), region=self.get_option('region', options), bucket_name=self.get_option('bucket', options), prefix='{prefix}/{name}{extension}'.format( prefix=self.get_option('prefix', options), name=name, extension=ext), data=data, encrypt=self.get_option('encrypt', options))
def upload_acme_token(self, token_path, token, options, **kwargs): """ This is called from the acme http challenge :param self: :param token_path: :param token: :param options: :param kwargs: :return: """ current_app.logger.debug( "S3 destination plugin is started to upload HTTP-01 challenge") function = f"{__name__}.{sys._getframe().f_code.co_name}" account_number = self.get_option("accountNumber", options) bucket_name = self.get_option("bucket", options) prefix = self.get_option("prefix", options) region = self.get_option("region", options) filename = token_path.split("/")[-1] if not prefix.endswith("/"): prefix + "/" response = s3.put(bucket_name=bucket_name, region_name=region, prefix=prefix + filename, data=token, encrypt=False, account_number=account_number) res = "Success" if response else "Failure" log_data = { "function": function, "message": "upload acme token challenge", "result": res, "bucket_name": bucket_name, "filename": filename } current_app.logger.info(log_data) metrics.send(f"{function}", "counter", 1, metric_tags={ "result": res, "bucket_name": bucket_name, "filename": filename }) return response