Sha256: 2acf5b16177078fa178a1ff9a5ae96c4f30c9f9d591ab3fb157b29b4b73a5f87

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

module Heirloom

  class ArtifactUploader

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

    def upload(args)
      id = args[:id]
      name = args[:name]
      file = args[:file]
      key = "#{id}.tar.gz"
      public_readable = args[:public_readable]

      @config.regions.each do |region|
        bucket = "#{@config.bucket_prefix}-#{region}"

        s3_uploader = Uploader::S3.new :config => @config,
                                       :region => region

        s3_uploader.upload_file :file => file,
                                :bucket => bucket,
                                :key_name => key,
                                :key_folder => name,
                                :public_readable => public_readable
        sdb.put_attributes name, id, { "#{region}-s3-url" => 
                                       "s3://#{bucket}/#{name}/#{key}" }

        @logger.info "Uploading s3://#{bucket}/#{name}/#{key}"

        sdb.put_attributes name, id, { "#{region}-http-url" => 
                                       "http://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}" }
        @logger.info "Uploading http://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}"

        sdb.put_attributes name, id, { "#{region}-https-url" => 
                                       "https://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}" }
        @logger.info "Uploading https://#{s3_endpoints[region]}/#{bucket}/#{name}/#{key}"
      end
    end

    private

    def s3_endpoints
      {
        'us-east-1' => 's3.amazonaws.com',
        'us-west-1' => 's3-us-west-1.amazonaws.com',
        'us-west-2' => 's3-us-west-2.amazonaws.com'
      }
    end

    def sdb
      @sdb ||= AWS::SimpleDB.new :config => @config
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
heirloom-0.1.0 lib/heirloom/artifact/artifact_uploader.rb
heirloom-0.0.9 lib/heirloom/artifact/artifact_uploader.rb
heirloom-0.0.8 lib/heirloom/artifact/artifact_uploader.rb