Sha256: b39a8d11b864cf9c3a273662da73c98d443bbb07ce3039bf92da9ba64c42eb5e

Contents?: true

Size: 1.71 KB

Versions: 12

Compression:

Stored size: 1.71 KB

Contents

gem 'right_aws'

module CloudCrowd
  class AssetStore

    # The S3Store is an implementation of an AssetStore that uses a bucket
    # on S3 for all resulting files.
    module S3Store

      # Configure authentication and establish a connection to S3, first thing.
      def setup
        @use_auth   = CloudCrowd.config[:s3_authentication]
        bucket_name = CloudCrowd.config[:s3_bucket]
        key, secret = CloudCrowd.config[:aws_access_key], CloudCrowd.config[:aws_secret_key]
        valid_conf  = [bucket_name, key, secret].all? {|s| s.is_a? String }
        raise Error::MissingConfiguration, "An S3 account must be configured in 'config.yml' before 's3' storage can be used" unless valid_conf
        protocol    = @use_auth ? 'https' : 'http'
        port        = @use_auth ? 443 : 80
        @s3         = RightAws::S3.new(key, secret, :protocol => protocol, :port => port)
        @bucket     = @s3.bucket(bucket_name)
        @bucket     = @s3.bucket(bucket_name, true) unless @bucket
      end

      # Save a finished file from local storage to S3. Save it publicly unless
      # we're configured to use S3 authentication. Authenticated links expire
      # after one day by default.
      def save(local_path, save_path)
        if @use_auth
          @bucket.put(save_path, File.open(local_path), {}, 'private')
          @s3.interface.get_link(@bucket, save_path)
        else
          @bucket.put(save_path, File.open(local_path), {}, 'public-read')
          @bucket.key(save_path).public_link
        end
      end

      # Remove all of a Job's resulting files from S3, both intermediate and finished.
      def cleanup(job)
        @bucket.delete_folder("#{job.action}/job_#{job.id}")
      end

    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cloud-crowd-0.7.2.pre2 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.7.2.pre lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.7.1 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.7.0 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.7.0.pre lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.6.2 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.6.1 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.6.0 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.5.2 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.5.0 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.4.1 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.4.0 lib/cloud_crowd/asset_store/s3_store.rb