Class: Brillo::Transferrer::S3

Inherits:
Object
  • Object
show all
Includes:
Helpers::ExecHelper, Logger
Defined in:
lib/brillo/transferrer/s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger, logger, logger=

Methods included from Helpers::ExecHelper

#execute, #execute!

Constructor Details

#initialize(config) ⇒ S3

Returns a new instance of S3.



10
11
12
13
14
15
16
17
# File 'lib/brillo/transferrer/s3.rb', line 10

def initialize(config)
  @enabled              = config.transfer_config.enabled
  @bucket               = config.transfer_config.bucket
  @region               = config.transfer_config.region
  @filename             = config.compressed_filename
  @path                 = config.compressed_dump_path
  Aws.config.update(aws_config(config.transfer_config))
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



8
9
10
# File 'lib/brillo/transferrer/s3.rb', line 8

def bucket
  @bucket
end

#enabledObject (readonly)

Returns the value of attribute enabled.



8
9
10
# File 'lib/brillo/transferrer/s3.rb', line 8

def enabled
  @enabled
end

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/brillo/transferrer/s3.rb', line 8

def filename
  @filename
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/brillo/transferrer/s3.rb', line 8

def path
  @path
end

#regionObject (readonly)

Returns the value of attribute region.



8
9
10
# File 'lib/brillo/transferrer/s3.rb', line 8

def region
  @region
end

Instance Method Details

#downloadObject



19
20
21
22
23
24
25
26
27
# File 'lib/brillo/transferrer/s3.rb', line 19

def download
  return unless enabled
  logger.info("download #{path} from s3 #{bucket} #{filename}")
  FileUtils.rm path, force: true
  client.get_object({bucket: bucket, key: filename}, target: path)
rescue Aws::S3::Errors::NoSuchBucket
  create_bucket
  retry
end

#uploadObject



29
30
31
32
33
34
35
36
37
# File 'lib/brillo/transferrer/s3.rb', line 29

def upload
  return unless enabled
  logger.info("uploading #{path} to s3 #{bucket} #{filename}")
  object = resource.bucket(bucket).object(filename)
  object.upload_file(path)
rescue Aws::S3::Errors::NoSuchBucket
  create_bucket
  retry
end