Class: Kitchen::Driver::Aws::CfClient
- Inherits:
-
Object
- Object
- Kitchen::Driver::Aws::CfClient
- Defined in:
- lib/kitchen/driver/aws/cf_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 docs.aws.amazon.com/sdkforruby/api/index.html#Configuration rubocop:disable Metrics/ParameterLists.
Instance Method Summary collapse
- #client ⇒ Object
- #create_change_set(options) ⇒ Object
- #create_stack(options) ⇒ Object
- #delete_stack(stack_name) ⇒ Object
-
#describe_change_set(stack_name, change_set_name) ⇒ Object
rubocop:disable Lint/RescueWithoutErrorClass.
- #execute_change_set(options) ⇒ Object
- #get_stack(stack_name) ⇒ Object
-
#get_stack_events(stack_name) ⇒ Object
rubocop:enable Lint/RescueWithoutErrorClass.
-
#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) ⇒ CfClient
constructor
rubocop:disable Metrics/ParameterLists.
- #resource ⇒ Object
- #update_stack(options) ⇒ 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) ⇒ CfClient
rubocop:disable Metrics/ParameterLists
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 27 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
87 88 89 90 91 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 87 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 docs.aws.amazon.com/sdkforruby/api/index.html#Configuration rubocop:disable Metrics/ParameterLists
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 52 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
131 132 133 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 131 def client @client ||= ::Aws::CloudFormation::Client.new end |
#create_change_set(options) ⇒ Object
101 102 103 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 101 def create_change_set() client.create_change_set() end |
#create_stack(options) ⇒ Object
93 94 95 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 93 def create_stack() resource.create_stack() end |
#delete_stack(stack_name) ⇒ Object
126 127 128 129 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 126 def delete_stack(stack_name) s = resource.stack(stack_name) s.delete end |
#describe_change_set(stack_name, change_set_name) ⇒ Object
rubocop:disable Lint/RescueWithoutErrorClass
114 115 116 117 118 119 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 114 def describe_change_set(stack_name, change_set_name) client.describe_change_set(change_set_name: change_set_name, stack_name: stack_name) rescue nil end |
#execute_change_set(options) ⇒ Object
105 106 107 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 105 def execute_change_set() client.execute_change_set() end |
#get_stack(stack_name) ⇒ Object
109 110 111 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 109 def get_stack(stack_name) resource.stack(stack_name) end |
#get_stack_events(stack_name) ⇒ Object
rubocop:enable Lint/RescueWithoutErrorClass
122 123 124 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 122 def get_stack_events(stack_name) client.describe_stack_events(stack_name: stack_name) end |
#resource ⇒ Object
135 136 137 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 135 def resource @resource ||= ::Aws::CloudFormation::Resource.new end |
#update_stack(options) ⇒ Object
97 98 99 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 97 def update_stack() resource.update_stack() end |