class Envoi::Mam::Agent::TransferClient::S3

Public Instance Methods

after_initialize(args = initial_args) click to toggle source
# File lib/envoi/mam/agent/transfer_client/s3.rb, line 12
def after_initialize(args = initial_args)

end
download(config, path, destination_path = DEFAULT_DESTINATION_PATH) click to toggle source
# File lib/envoi/mam/agent/transfer_client/s3.rb, line 36
def download(config, path, destination_path = DEFAULT_DESTINATION_PATH)
  s3 = initialize_s3_client(config)
  bucket_name = config['bucket_name']
  bucket = s3.bucket(bucket_name)
  object_prefix = config['object_prefix']
  object_path = object_prefix && !object_prefix.empty? ? File.join(object_prefix, path) : path
  object_path = object_path[1..-1] if object_path.start_with?('/')
  object = bucket.object(object_path)
  # puts object.data
  # puts "Path: '#{path}' DPath: '#{destination_path}'"
  object.get(response_target: destination_path) if agent && !agent.dry_run?
end
initialize_s3_client(config) click to toggle source
# File lib/envoi/mam/agent/transfer_client/s3.rb, line 16
def initialize_s3_client(config)
  region = config['region']
  access_key_id = config['access_key_id']
  secret_access_key = config['secret_access_key']
  profile_name = config['profile'] || config['aws_profile']

  aws_config = {}
  aws_config[:credentials] = (access_key_id || secret_access_key) ?
                                 Aws::Credentials.new(access_key_id, secret_access_key) :
                                 Aws::SharedCredentials.new(profile_name: profile_name)
  aws_config[:region] = region if region

  # resource_args = { }
  # resource_args[:region] = region if region && !region.empty?
  # resource_args[:access_key_id] = access_key_id if access_key_id && !access_key_id.empty?
  # resource_args[:secret_access_key] = secret_access_key if secret_access_key && !secret_access_key.empty?
  # @s3 = Aws::S3::Resource.new(resource_args)
  @s3 = Aws::S3::Resource.new(aws_config)
end
upload(config, path, destination_path) click to toggle source
# File lib/envoi/mam/agent/transfer_client/s3.rb, line 49
def upload(config, path, destination_path)
  s3 = initialize_s3_client(config)
  bucket_name = config['bucket_name']
  bucket = s3.bucket(bucket_name)
  object_prefix = config['object_prefix']
  object_path = object_prefix && !object_prefix.empty? ? File.join(object_prefix, destination_path) : path
  object_path = object_path[1..-1] if object_path.start_with?('/')
  object_path = object_path[0..-2] if object_path.end_with?('/')
  object = bucket.object(object_path)
  logger.debug { "Uploading File '#{path}' to '#{destination_path}' Object Path: '#{object_path}'" }

  object.upload_file(path) if agent && !agent.dry_run?
  object

  # puts object.data
  # puts "Path: '#{path}' DPath: '#{destination_path}'"
  # abort
end