lib/brillo/transferrer/s3.rb in brillo-1.1.4 vs lib/brillo/transferrer/s3.rb in brillo-1.2.0

- old
+ new

@@ -11,17 +11,11 @@ @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( - credentials: Aws::Credentials.new( - config.transfer_config.access_key_id, - config.transfer_config.secret_access_key - ), - region: config.transfer_config.region - ) + Aws.config.update(aws_config(config.transfer_config)) end def download return unless enabled logger.info("download #{path} from s3 #{bucket} #{filename}") @@ -41,9 +35,23 @@ create_bucket retry end private + + 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 unless transfer_config.access_key_id + hash[:credentials] = Aws::Credentials.new( + transfer_config.access_key_id, + transfer_config.secret_access_key + ) + end + end def create_bucket client.create_bucket(bucket: bucket) end