Sha256: b85fac335263b038c74455d00213e80254c40b5bc3c25c47a16acf2727e48267

Contents?: true

Size: 854 Bytes

Versions: 13

Compression:

Stored size: 854 Bytes

Contents

module OpsPreflight
  class S3Transfer
    attr_accessor :bucket
    attr_accessor :file

    def initialize(bucket, file)
      @bucket = bucket
      @file = file
    end

    def upload
      basename = File.basename(file)

      remote_file = directory.files.head(basename)
      remote_file.destroy if remote_file

      directory.files.create(
        :key => basename,
        :body => File.open(file),
        :public => false
      )
    end

    def download
      basename = File.basename(file)

      remote_file = directory.files.get(basename)
      File.open(file, 'w') do |local_file|
        local_file.write(remote_file.body)
      end
    end

    protected
    def connection
      require 'fog'
      Fog::Storage::AWS.new :use_iam_profile => true
    end

    def directory
      connection.directories.get(bucket)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ops_preflight-1.3.1 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.3.0 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.2.1 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.2.0 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.1.2 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.1.1 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.1.0 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.0.0.pre2 lib/ops_preflight/s3_transfer.rb
ops_preflight-1.0.0.pre1 lib/ops_preflight/s3_transfer.rb
ops_preflight-0.9.0 lib/ops_preflight/s3_transfer.rb
ops_preflight-0.9.0.pre2 lib/ops_preflight/s3_transfer.rb
ops_preflight-0.9.0.pre1 lib/ops_preflight/s3_transfer.rb
ops_preflight-0.0.1.pre lib/ops_preflight/s3_transfer.rb