class TrainPlugins::Aws::Connection

You must inherit from BaseConnection.

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/train-aws/connection.rb, line 46
def initialize(options)
  # 'options' here is a hash, Symbol-keyed,
  # of what Train.target_config decided to do with the URI that it was
  # passed by `inspec -t` (or however the application gathered target information)
  # Some plugins might use this moment to capture credentials from the URI,
  # and the configure an underlying SDK accordingly.
  # You might also take a moment to manipulate the options.
  # Have a look at the Local, SSH, and AWS transports for ideas about what
  # you can do with the 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].sub(%r{^/}, "")
  end

  # Now let the BaseConnection have a chance to configure itself.
  super(options)

  # Force enable caching.
  enable_cache :api_call

  # Why are we doing this?
  # Why aren't we calling the AWS config system?
  ENV["AWS_PROFILE"] = @options[:profile] if @options[:profile]
  ENV["AWS_REGION"] = @options[:region] if @options[:region]
end

Public Instance Methods

aws_client(klass) click to toggle source

We support caching on the aws_client call, but not the aws_resource call

# File lib/train-aws/connection.rb, line 77
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) click to toggle source
# File lib/train-aws/connection.rb, line 83
def aws_resource(klass, args)
  klass.new(args)
end
unique_identifier() click to toggle source
# File lib/train-aws/connection.rb, line 92
def unique_identifier
  # use aws account id
  sts_client = aws_client(::Aws::STS::Client)
  sts_client.get_caller_identity.account
end
uri() click to toggle source

TODO: determine exactly what this is used for

# File lib/train-aws/connection.rb, line 88
def uri
  "aws://#{@options[:region]}"
end