Sha256: 4484b10d566c3430f8ef9ecad9562beb4eaf9a64af8acb67c0206fc34d9513b1

Contents?: true

Size: 1009 Bytes

Versions: 10

Compression:

Stored size: 1009 Bytes

Contents

require 'time'

require 'aws/s3'

module Murlsh

  # Store assets in Amazon S3.
  #
  # Depends on 's3_id', 's3_secret', and 's3_bucket' in config.
  class StoreAsset40S3 < Plugin

    @hook = 'store_asset'

    def self.run(name, data, config)
      if !config['s3_id'].to_s.empty? and
        !config['s3_secret'].to_s.empty? and
        !config['s3_bucket'].to_s.empty?
        AWS::S3::Base.establish_connection!(
          :access_key_id => config['s3_id'],
          :secret_access_key => config['s3_secret']
        )

        bucket = begin
          AWS::S3::Bucket.find config['s3_bucket']
        rescue AWS::S3::NoSuchBucket
          AWS::S3::Bucket.create config['s3_bucket'], :access => :public_read
        end

        AWS::S3::S3Object.store name, data, bucket.name,
          :access => :public_read,
          # 100 years
          :expires => (Time.now + (31536000000)).httpdate

        AWS::S3::S3Object.url_for(name, bucket.name, :authenticated => false)
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
murlsh-1.9.3 plugins/store_asset_40_s3.rb
murlsh-1.9.2 plugins/store_asset_40_s3.rb
murlsh-1.9.1 plugins/store_asset_40_s3.rb
murlsh-1.9.0 plugins/store_asset_40_s3.rb
murlsh-1.8.0 plugins/store_asset_40_s3.rb
murlsh-1.7.1 plugins/store_asset_40_s3.rb
murlsh-1.7.0 plugins/store_asset_40_s3.rb
murlsh-1.6.1 plugins/store_asset_40_s3.rb
murlsh-1.6.0 plugins/store_asset_40_s3.rb
murlsh-1.5.0 plugins/store_asset_40_s3.rb