Class: TrainPlugins::Aws::Connection
- Inherits:
-
Train::Plugins::Transport::BaseConnection
- Object
- Train::Plugins::Transport::BaseConnection
- TrainPlugins::Aws::Connection
- Includes:
- Platform
- Defined in:
- lib/train-aws/connection.rb
Overview
You must inherit from BaseConnection.
Instance Method Summary collapse
-
#aws_client(klass) ⇒ Object
We support caching on the aws_client call, but not the aws_resource call.
- #aws_resource(klass, args) ⇒ Object
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #unique_identifier ⇒ Object
-
#uri ⇒ Object
TODO: determine exactly what this is used for.
Methods included from Platform
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/train-aws/connection.rb', line 46 def initialize() # '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 [:region] = [:host] || [:region] if [:path] # string the leading / from path [:profile] = [:path].sub(%r{^/}, "") end # Now let the BaseConnection have a chance to configure itself. super() # 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 |
Instance Method Details
#aws_client(klass) ⇒ Object
We support caching on the aws_client call, but not the aws_resource call
77 78 79 80 81 |
# 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) ⇒ Object
83 84 85 |
# File 'lib/train-aws/connection.rb', line 83 def aws_resource(klass, args) klass.new(args) end |
#unique_identifier ⇒ Object
92 93 94 95 96 |
# 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 ⇒ Object
TODO: determine exactly what this is used for
88 89 90 |
# File 'lib/train-aws/connection.rb', line 88 def uri "aws://#{@options[:region]}" end |