Module: Conduit::Storage::Aws::ClassMethods

Defined in:
lib/conduit/storage/aws.rb

Instance Method Summary collapse

Instance Method Details

#bucketObject

Bucket we want to work with

Configurable in: config/initializers/conduit.rb



52
53
54
55
56
57
58
# File 'lib/conduit/storage/aws.rb', line 52

def bucket
  @bucket ||= begin
    bucket = config[:bucket]
    connection.buckets.create(bucket) unless connection.buckets[bucket].exists?
    connection.buckets[bucket]
  end
end

#configureObject

Configure AWS::S3 with credentials if provided, else, assume IAM will provide them.



25
26
27
28
29
30
31
32
33
34
# File 'lib/conduit/storage/aws.rb', line 25

def configure
  if [:aws_access_key_id, :aws_access_secret].all? { |key| config.key?(key) }
    AWS.config(
      access_key_id:     config[:aws_access_key_id],
      secret_access_key: config[:aws_access_secret]
    )
  else
    AWS.config
  end
end

#connectionObject

Primary connection object to AWS::S3

Configurable in: config/initializers/conduit.rb TODO: Update how conduit gets the credentials for s3



43
44
45
# File 'lib/conduit/storage/aws.rb', line 43

def connection
  @connection ||= AWS::S3.new
end

#delete(key) ⇒ Object

Delete a file from AWS::S3

e.g.

> Conduit::Storage.delete(‘/path/to/file’)



85
86
87
88
89
# File 'lib/conduit/storage/aws.rb', line 85

def delete(key)
  bucket.objects[key].delete
rescue AWS::S3::Errors::NoSuchKey
  nil
end

#read(key) ⇒ Object

Read a file from AWS::S3

e.g.

> Conduit::Storage.read(‘/path/to/file’)



74
75
76
77
78
# File 'lib/conduit/storage/aws.rb', line 74

def read(key)
  bucket.objects[key].read
rescue AWS::S3::Errors::NoSuchKey
  nil
end

#write(key, content) ⇒ Object

Write a file to AWS::S3

e.g.

> Conduit::Storage.write(‘/path/to/file’, ‘foo’)



65
66
67
# File 'lib/conduit/storage/aws.rb', line 65

def write(key, content)
  bucket.objects[key].write(content)
end