Module: S3Secure::AwsServices

Extended by:
Memoist
Included in:
AbstractBase
Defined in:
lib/s3_secure/aws_services.rb

Constant Summary collapse

@@buckets =

holds bucket => region map

{}

Instance Method Summary collapse

Instance Method Details

#new_s3_regional_client(region = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/s3_secure/aws_services.rb', line 20

def new_s3_regional_client(region=nil)
  options = {}
  options[:endpoint] = "https://s3.#{region}.amazonaws.com" if region
  options[:region] = region if region
  Aws::S3::Client.new(options)
rescue Aws::STS::Errors::RegionDisabledException
  puts "ERROR: Fail to establish client connection to region #{region}".color(:red)
  raise
end

#s3_clientObject

Generic s3 client. Will be configured to whatever region user has locally configured in ~/.aws/config Used to call get_bucket_location to get each specific bucket’s location. Generally use the s3_regional_client instead of this.



34
35
36
# File 'lib/s3_secure/aws_services.rb', line 34

def s3_client
  Aws::S3::Client.new
end

#s3_regional_client(bucket) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/s3_secure/aws_services.rb', line 8

def s3_regional_client(bucket)
  region = @@buckets[bucket]

  unless region
    resp = s3_client.get_bucket_location(bucket: bucket)
    region = resp.location_constraint
    region = 'us-east-1' if region.empty? # "" means us-east-1
  end

  new_s3_regional_client(region)
end