Class: Backup::Storages::AmazonS3

Inherits:
Base
  • Object
show all
Defined in:
lib/backup-agent/storages/amazon-s3.rb

Defined Under Namespace

Classes: Credentials, Object

Instance Method Summary collapse

Constructor Details

#initialize(region:, bucket:, credentials:) ⇒ AmazonS3

Returns a new instance of AmazonS3.



9
10
11
12
13
# File 'lib/backup-agent/storages/amazon-s3.rb', line 9

def initialize(region:, bucket:, credentials:)
  @aws_s3_ruby_credentials = Aws::Credentials.new(credentials.access_key_id, credentials.secret_access_key)
  @aws_s3_ruby_resource    = Aws::S3::Resource.new(region: region, credentials: @aws_s3_ruby_credentials)
  @aws_s3_ruby_bucket      = @aws_s3_ruby_resource.bucket(bucket)
end

Instance Method Details

#delete(id) ⇒ Object



21
22
23
# File 'lib/backup-agent/storages/amazon-s3.rb', line 21

def delete(id)
  @aws_s3_ruby_bucket.object(id).delete
end

#eachObject



25
26
27
28
29
# File 'lib/backup-agent/storages/amazon-s3.rb', line 25

def each
  @aws_s3_ruby_bucket.objects.each do |aws_s3_ruby_object|
    yield Backup::Storages::AmazonS3::Object.new(self, @aws_s3_ruby_bucket, aws_s3_ruby_object.key)
  end
end

#store(id, file_to_upload) ⇒ Object



15
16
17
18
19
# File 'lib/backup-agent/storages/amazon-s3.rb', line 15

def store(id, file_to_upload)
  aws_s3_ruby_object = @aws_s3_ruby_bucket.object(id)
  aws_s3_ruby_object.upload_file(file_to_upload)
  Backup::Storages::AmazonS3::Object.new(self, @aws_s3_ruby_bucket, aws_s3_ruby_object.key)
end