Class: Envoi::Restore::GlacierRestoreEventHandler
- Inherits:
-
Object
- Object
- Envoi::Restore::GlacierRestoreEventHandler
- Defined in:
- lib/envoi/restore/glacier-restore-event-handler.rb
Constant Summary collapse
- DEFAULT_DESTINATION_PATH =
'.'
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#config ⇒ Object
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #download_file(args, file) ⇒ Object
-
#initialize(args = {}) ⇒ GlacierRestoreEventHandler
constructor
A new instance of GlacierRestoreEventHandler.
- #initialize_logger(args = {}) ⇒ Object
- #process_event(event) ⇒ Object
- #system_config ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ GlacierRestoreEventHandler
Returns a new instance of GlacierRestoreEventHandler.
16 17 18 19 |
# File 'lib/envoi/restore/glacier-restore-event-handler.rb', line 16 def initialize(args = {}) @config = args[:config] initialize_logger(args) end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
12 13 14 |
# File 'lib/envoi/restore/glacier-restore-event-handler.rb', line 12 def agent @agent end |
#config ⇒ Object
Returns the value of attribute config.
12 13 14 |
# File 'lib/envoi/restore/glacier-restore-event-handler.rb', line 12 def config @config end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/envoi/restore/glacier-restore-event-handler.rb', line 12 def logger @logger end |
Instance Method Details
#download_file(args, file) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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.(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 = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/envoi/restore/glacier-restore-event-handler.rb', line 33 def system_config @system_config ||= config end |