Class: Train::Transports::Aws::Connection

Inherits:
BaseConnection
  • Object
show all
Defined in:
lib/train/transports/aws.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/train/transports/aws.rb', line 21

def initialize(options)
  # Override for any cli options
  # aws://region/my-profile
  options[:region] = options[:host] || options[:region]
  if options[:path]
    # string the leading / from path
    options[:profile] = options[:path][1..-1]
  end
  super(options)

  @cache_enabled[:api_call] = true
  @cache[:api_call] = {}

  # additional platform details
  release = Gem.loaded_specs['aws-sdk'].version
  @platform_details = { release: "aws-sdk-v#{release}" }

  connect
end

Instance Method Details

#aws_client(klass) ⇒ Object



45
46
47
48
# File 'lib/train/transports/aws.rb', line 45

def aws_client(klass)
  return klass.new unless cache_enabled?(:api_call)
  @cache[:api_call][klass.to_s.to_sym] ||= klass.new
end

#aws_resource(klass, args) ⇒ Object



50
51
52
# File 'lib/train/transports/aws.rb', line 50

def aws_resource(klass, args)
  klass.new(args)
end

#connectObject



54
55
56
57
# File 'lib/train/transports/aws.rb', line 54

def connect
  ENV['AWS_PROFILE'] = @options[:profile] if @options[:profile]
  ENV['AWS_REGION'] = @options[:region] if @options[:region]
end

#platformObject



41
42
43
# File 'lib/train/transports/aws.rb', line 41

def platform
  force_platform!('aws', @platform_details)
end

#unique_identifierObject



63
64
65
66
67
# File 'lib/train/transports/aws.rb', line 63

def unique_identifier
  # use aws account id
  client = aws_client(::Aws::STS::Client)
  client.get_caller_identity.
end

#uriObject



59
60
61
# File 'lib/train/transports/aws.rb', line 59

def uri
  "aws://#{@options[:region]}"
end