class Envoi::Restore::GlacierRestoreEventHandler
Constants
- DEFAULT_DESTINATION_PATH
Attributes
agent[RW]
config[RW]
logger[RW]
Public Class Methods
new(args = {})
click to toggle source
# File lib/envoi/restore/glacier-restore-event-handler.rb, line 16 def initialize(args = {}) @config = args[:config] initialize_logger(args) end
Public Instance Methods
download_file(args, file)
click to toggle source
# File lib/envoi/restore/glacier-restore-event-handler.rb, line 60 def download_file(args, file) logger.debug { "File: #{file}" } transfer_type = args[:transfer_type] file_path = file['path'] preserve_path = args.fetch(:preserve_path, true) destination_path = args[:destination_path] || DEFAULT_DESTINATION_PATH relative_path = preserve_path ? File.dirname(file_path) : nil relative_path = nil if relative_path == '.' target_path = relative_path ? File.join(destination_path, relative_path) : destination_path target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/') aspera_config = @current_config['aspera'] if (transfer_type.nil? || transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?) client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self) return client.download(aspera_config, file_path, target_path) end s3_config = @current_config['s3'] if (transfer_type.nil? || transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?) target_path = File.expand_path(target_path) if target_path == '.' target_path = File.join(target_path, File.basename(file_path)) client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self) return client.download(s3_config, file_path, target_path) end end
initialize_logger(args = {})
click to toggle source
# File lib/envoi/restore/glacier-restore-event-handler.rb, line 21 def initialize_logger(args = {}) @logger = args[:logger] ||= begin log_to = args[:log_to] || STDOUT log_age = args[:log_age] Logger.new(log_to, log_age) end log_level = args[:log_level] ||= Logger::DEBUG @logger.level = log_level @logger end
process_event(event)
click to toggle source
# File lib/envoi/restore/glacier-restore-event-handler.rb, line 37 def process_event(event) event_s3_data = event['s3'] event_bucket_data = event_s3_data['bucket'] event_bucket_name = event_bucket_data['name'] event_object_data = event_s3_data['object'] event_object_key = event_object_data['key'] s3_config = system_config['s3'] @current_config = s3_config[event_bucket_name] || s3_config download_file_args = { :destination_path => config['destination_path'] || DEFAULT_DESTINATION_PATH } file = { 'path' => event_object_key } download_file(download_file_args, file) end
system_config()
click to toggle source
# File lib/envoi/restore/glacier-restore-event-handler.rb, line 33 def system_config @system_config ||= config end