class Brillo::Transferrer::S3
Attributes
bucket[R]
enabled[R]
filename[R]
path[R]
region[R]
Public Class Methods
new(config)
click to toggle source
# File lib/brillo/transferrer/s3.rb, line 10 def initialize(config) @enabled = config.transfer_config.enabled @bucket = config.transfer_config.bucket @region = config.transfer_config.region @filename = config.compressed_filename @path = config.compressed_dump_path Aws.config.update(aws_config(config.transfer_config)) end
Public Instance Methods
download()
click to toggle source
# File lib/brillo/transferrer/s3.rb, line 19 def download return unless enabled logger.info("download #{path} from s3 #{bucket} #{filename}") FileUtils.rm path, force: true client.get_object({bucket: bucket, key: filename}, target: path) rescue Aws::S3::Errors::NoSuchBucket create_bucket retry end
upload()
click to toggle source
# File lib/brillo/transferrer/s3.rb, line 29 def upload return unless enabled logger.info("uploading #{path} to s3 #{bucket} #{filename}") object = resource.bucket(bucket).object(filename) object.upload_file(path) rescue Aws::S3::Errors::NoSuchBucket create_bucket retry end
Private Instance Methods
aws_config(transfer_config)
click to toggle source
# File lib/brillo/transferrer/s3.rb, line 41 def aws_config(transfer_config) { region: transfer_config.region }.tap do |hash| # Don't explicitly set credentials if we have none # Doing so stops [automatic configuration](https://github.com/aws/aws-sdk-ruby#configuration) return hash unless transfer_config.access_key_id hash[:credentials] = Aws::Credentials.new( transfer_config.access_key_id, transfer_config.secret_access_key ) end end
client()
click to toggle source
# File lib/brillo/transferrer/s3.rb, line 59 def client Aws::S3::Client.new end
create_bucket()
click to toggle source
# File lib/brillo/transferrer/s3.rb, line 55 def create_bucket client.create_bucket(bucket: bucket) end
resource()
click to toggle source
# File lib/brillo/transferrer/s3.rb, line 63 def resource Aws::S3::Resource.new end