Class: Kitchen::Driver::Aws::Client
- Inherits:
-
Object
- Object
- Kitchen::Driver::Aws::Client
- Defined in:
- lib/kitchen/driver/aws/client.rb
Overview
A class for creating and managing the EC2 client connection
Class Method Summary collapse
-
.default_shared_credentials? ⇒ Boolean
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
.get_credentials(profile_name, access_key_id, secret_access_key, session_token, region, options = {}) ⇒ Object
Try and get the credentials from an ordered list of locations http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity rubocop:disable Metrics/ParameterLists, Metrics/MethodLength.
Instance Method Summary collapse
- #client ⇒ Object
- #create_instance(options) ⇒ Object
- #get_instance(id) ⇒ Object
- #get_instance_from_spot_request(request_id) ⇒ Object
-
#initialize(region, profile_name = nil, access_key_id = nil, secret_access_key = nil, session_token = nil, http_proxy = nil, retry_limit = nil, ssl_verify_peer = true) ⇒ Client
constructor
rubocop:disable Metrics/ParameterLists.
- #resource ⇒ Object
Constructor Details
#initialize(region, profile_name = nil, access_key_id = nil, secret_access_key = nil, session_token = nil, http_proxy = nil, retry_limit = nil, ssl_verify_peer = true) ⇒ Client
rubocop:disable Metrics/ParameterLists
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kitchen/driver/aws/client.rb', line 35 def initialize( # rubocop:disable Metrics/ParameterLists region, profile_name = nil, access_key_id = nil, secret_access_key = nil, session_token = nil, http_proxy = nil, retry_limit = nil, ssl_verify_peer = true ) creds = self.class.get_credentials( profile_name, access_key_id, secret_access_key, session_token, region ) ::Aws.config.update( :region => region, :credentials => creds, :http_proxy => http_proxy, :ssl_verify_peer => ssl_verify_peer ) ::Aws.config.update(:retry_limit => retry_limit) unless retry_limit.nil? end |
Class Method Details
.default_shared_credentials? ⇒ Boolean
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
96 97 98 99 100 |
# File 'lib/kitchen/driver/aws/client.rb', line 96 def self.default_shared_credentials? ::Aws::SharedCredentials.new.loadable? rescue ::Aws::Errors::NoSuchProfileError false end |
.get_credentials(profile_name, access_key_id, secret_access_key, session_token, region, options = {}) ⇒ Object
Try and get the credentials from an ordered list of locations http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kitchen/driver/aws/client.rb', line 61 def self.get_credentials(profile_name, access_key_id, secret_access_key, session_token, region, = {}) source_creds = if access_key_id && secret_access_key ::Aws::Credentials.new(access_key_id, secret_access_key, session_token) elsif ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"] ::Aws::Credentials.new( ENV["AWS_ACCESS_KEY_ID"], ENV["AWS_SECRET_ACCESS_KEY"], ENV["AWS_SESSION_TOKEN"] ) elsif profile_name ::Aws::SharedCredentials.new(:profile_name => profile_name) elsif default_shared_credentials? ::Aws::SharedCredentials.new else ::Aws::InstanceProfileCredentials.new(:retries => 1) end if [:assume_role_arn] && [:assume_role_session_name] sts = ::Aws::STS::Client.new(:credentials => source_creds, :region => region) = ([:assume_role_options] || {}).merge( :client => sts, :role_arn => [:assume_role_arn], :role_session_name => [:assume_role_session_name] ) ::Aws::AssumeRoleCredentials.new() else source_creds end end |
Instance Method Details
#client ⇒ Object
119 120 121 |
# File 'lib/kitchen/driver/aws/client.rb', line 119 def client @client ||= ::Aws::EC2::Client.new end |
#create_instance(options) ⇒ Object
102 103 104 |
# File 'lib/kitchen/driver/aws/client.rb', line 102 def create_instance() resource.create_instances()[0] end |
#get_instance(id) ⇒ Object
106 107 108 |
# File 'lib/kitchen/driver/aws/client.rb', line 106 def get_instance(id) resource.instance(id) end |
#get_instance_from_spot_request(request_id) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/kitchen/driver/aws/client.rb', line 110 def get_instance_from_spot_request(request_id) resource.instances( :filters => [{ :name => "spot-instance-request-id", :values => [request_id] }] ).to_a[0] end |
#resource ⇒ Object
123 124 125 |
# File 'lib/kitchen/driver/aws/client.rb', line 123 def resource @resource ||= ::Aws::EC2::Resource.new end |