Module: CloudCrowd::AssetStore::S3Store

Defined in:
lib/cloud_crowd/asset_store/s3_store.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#cleanup(job) ⇒ Object

Remove all of a Job’s resulting files from S3, both intermediate and finished.



36
37
38
# File 'lib/cloud_crowd/asset_store/s3_store.rb', line 36

def cleanup(job)
  @bucket.delete_folder("#{job.action}/job_#{job.id}")
end

#save(local_path, save_path) ⇒ Object

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.



25
26
27
28
29
30
31
32
33
# File 'lib/cloud_crowd/asset_store/s3_store.rb', line 25

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

#setupObject

Configure authentication and establish a connection to S3, first thing.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cloud_crowd/asset_store/s3_store.rb', line 9

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