Sha256: dd995b6b5d045a3d9f5b7e9037b2d1b45d1ae0d642d4c8127d6e7d419c0d793c

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

module Heirloom

  class Downloader

    def initialize(args)
      @config = args[:config]
      @name   = args[:name]
      @id     = args[:id]
      @logger = @config.logger
    end

    def download(args)
      @region        = args[:region]
      @bucket_prefix = args[:bucket_prefix]
      @secret        = args[:secret]
      extract        = args[:extract]
      output         = args[:output] ||= './'

      @logger.info "Downloading s3://#{bucket}/#{key} from #{@region}."

      s3_downloader = Downloader::S3.new :config => @config,
                                         :logger => @logger,
                                         :region => @region

      raw_archive = s3_downloader.download_file :bucket => bucket,
                                                :key    => key

      return false unless raw_archive

      archive = cipher_data.decrypt_data :data   => raw_archive,
                                         :secret => @secret

      return false unless archive

      return false unless writer.save_archive :archive => archive, 
                                              :output  => output,
                                              :file    => file,
                                              :extract => extract

      @logger.info "Download complete."

      output
    end

    private

    def file
      "#{@id}.tar.gz"
    end

    def key
      @secret ? "#{@name}/#{@id}.tar.gz.gpg" : "#{@name}/#{@id}.tar.gz"
    end

    def bucket
      "#{@bucket_prefix}-#{@region}"
    end

    def writer
      @writer ||= Writer.new :config => @config
    end

    def cipher_data
      @cipher_data ||= Cipher::Data.new :config => @config
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
heirloom-0.12.7 lib/heirloom/archive/downloader.rb
heirloom-0.12.5 lib/heirloom/archive/downloader.rb
heirloom-0.12.4 lib/heirloom/archive/downloader.rb