class TrainPlugins::AliCloud::Connection
You must inherit from BaseConnection.
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/train-alicloud/connection.rb, line 30 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 # alicloud://region options[:region] = options[:host] || options[:region] # Now let the BaseConnection have a chance to configure itself. super(options) # Force enable caching. enable_cache :api_call # Why are we doing this? ENV["ALICLOUD_REGION"] = @options[:region] if @options[:region] end
Public Instance Methods
alicloud_client(api:, api_version:)
click to toggle source
# File lib/train-alicloud/connection.rb, line 54 def alicloud_client(api:, api_version:) region = @options[:region] endpoint ||= if api == "sts" "https://#{api}.aliyuncs.com" else "https://#{api}.#{region}.aliyuncs.com" end RPCClient.new( access_key_id: @options[:access_key_id], access_key_secret: @options[:secret_access_key], endpoint: endpoint, api_version: api_version ) end
alicloud_resource(klass, args)
click to toggle source
# File lib/train-alicloud/connection.rb, line 71 def alicloud_resource(klass, args) klass.new(args) end
unique_identifier()
click to toggle source
# File lib/train-alicloud/connection.rb, line 80 def unique_identifier # use alicloud account id caller_identity = alicloud_client(api: "sts", api_version: "2015-04-01").request(action: "GetCallerIdentity") caller_identity["AccountId"] end
uri()
click to toggle source
TODO: determine exactly what this is used for
# File lib/train-alicloud/connection.rb, line 76 def uri "alicloud://#{@options[:region]}" end