Sha256: 2e62ccd0e57ec4532fea42a4648356e4de28daceb401794d7263f4240692c352

Contents?: true

Size: 1.73 KB

Versions: 20

Compression:

Stored size: 1.73 KB

Contents

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

20 entries across 20 versions & 3 rubygems

Version Path
documentcloud-cloud-crowd-0.2.0 lib/cloud_crowd/asset_store/s3_store.rb
documentcloud-cloud-crowd-0.2.1 lib/cloud_crowd/asset_store/s3_store.rb
documentcloud-cloud-crowd-0.2.2 lib/cloud_crowd/asset_store/s3_store.rb
documentcloud-cloud-crowd-0.2.3 lib/cloud_crowd/asset_store/s3_store.rb
mooktakim-cloud-crowd-0.3.5 lib/cloud_crowd/asset_store/s3_store.rb
mooktakim-cloud-crowd-0.3.4 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.3.3 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.3.2 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.3.1 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.3.0 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.9 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.8 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.7 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.6 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.5 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.4 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.3 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.2 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.1 lib/cloud_crowd/asset_store/s3_store.rb
cloud-crowd-0.2.0 lib/cloud_crowd/asset_store/s3_store.rb