class AssetsDeployer::Storage::AwsS3

Public Class Methods

new(credentials:, region: nil, bucket: nil, prefix_key: nil) click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 6
def initialize(credentials:, region: nil, bucket: nil, prefix_key: nil)
  @credentials = credentials
  @bucket = bucket
  @prefix_key = prefix_key
  @region = region
end

Public Instance Methods

upload(files) click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 13
def upload(files)
  files.each do |file|
    client.put_object(
      bucket: @bucket,
      key: [@prefix_key, file.key].compact.join('/'),
      body: file.body,
      content_type: file.content_type
    )
  end
end

Private Instance Methods

access_key_id() click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 45
def access_key_id
  @credentials[:access_key_id] || ENV['AWS_ACCESS_KEY_ID']
end
client() click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 26
def client
  @client ||= Aws::S3::Client.new(client_options)
end
client_options() click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 30
def client_options
  hash = {}
  hash[:credentials] = credentials
  hash[:region] = region if !region.nil? && !region.empty?
  hash
end
credentials() click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 37
def credentials
  if access_key_id && secret_access_key
    Aws::Credentials.new(access_key_id, secret_access_key)
  else
    Aws::InstanceProfileCredentials.new
  end
end
region() click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 53
def region
  @region || ENV['AWS_REGION']
end
secret_access_key() click to toggle source
# File lib/assets_deployer/storage/aws_s3.rb, line 49
def secret_access_key
  @credentials[:secret_access_key] || ENV['AWS_SECRET_ACCESS_KEY']
end