Class: Envoi::Mam::Agent::TransferClient::S3
Instance Attribute Summary
#agent, #initial_args, #logger
Instance Method Summary
collapse
#initialize, #initialize_logger
Instance Method Details
#after_initialize(args = initial_args) ⇒ Object
12
13
14
|
# File 'lib/envoi/mam/agent/transfer_client/s3.rb', line 12
def after_initialize(args = initial_args)
end
|
#download(config, path, destination_path = DEFAULT_DESTINATION_PATH) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/envoi/mam/agent/transfer_client/s3.rb', line 36
def download(config, path, destination_path = DEFAULT_DESTINATION_PATH)
s3 = initialize_s3_client(config)
bucket_name = config['bucket_name']
bucket = s3.bucket(bucket_name)
object_prefix = config['object_prefix']
object_path = object_prefix && !object_prefix.empty? ? File.join(object_prefix, path) : path
object_path = object_path[1..-1] if object_path.start_with?('/')
object = bucket.object(object_path)
object.get(response_target: destination_path) if agent && !agent.dry_run?
end
|
#initialize_s3_client(config) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/envoi/mam/agent/transfer_client/s3.rb', line 16
def initialize_s3_client(config)
region = config['region']
access_key_id = config['access_key_id']
secret_access_key = config['secret_access_key']
profile_name = config['profile'] || config['aws_profile']
aws_config = {}
aws_config[:credentials] = (access_key_id || secret_access_key) ?
Aws::Credentials.new(access_key_id, secret_access_key) :
Aws::SharedCredentials.new(profile_name: profile_name)
aws_config[:region] = region if region
@s3 = Aws::S3::Resource.new(aws_config)
end
|
#upload(config, path, destination_path) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/envoi/mam/agent/transfer_client/s3.rb', line 49
def upload(config, path, destination_path)
s3 = initialize_s3_client(config)
bucket_name = config['bucket_name']
bucket = s3.bucket(bucket_name)
object_prefix = config['object_prefix']
object_path = object_prefix && !object_prefix.empty? ? File.join(object_prefix, destination_path) : path
object_path = object_path[1..-1] if object_path.start_with?('/')
object_path = object_path[0..-2] if object_path.end_with?('/')
object = bucket.object(object_path)
logger.debug { "Uploading File '#{path}' to '#{destination_path}' Object Path: '#{object_path}'" }
object.upload_file(path) if agent && !agent.dry_run?
object
end
|