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 28
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']

  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)
end
upload(config, path, destination_path) click to toggle source
# File lib/envoi/mam/agent/transfer_client/s3.rb, line 41
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