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 Cloud Formation client connection
Class Method Summary collapse
-
.get_credentials(profile_name, access_key_id, secret_access_key, session_token) ⇒ Object
Try and get the credentials from an ordered list of locations docs.aws.amazon.com/sdkforruby/api/index.html#Configuration.
Instance Method Summary collapse
- #client ⇒ Object
- #create_stack(options) ⇒ Object
- #delete_stack(stack_name) ⇒ Object
- #get_stack(stack_name) ⇒ Object
- #get_stack_events(stack_name) ⇒ Object
-
#initialize(region, profile_name = nil, ssl_cert_file = nil, aws_key = {}, session_token = nil) ⇒ CfClient
constructor
A new instance of CfClient.
- #resource ⇒ Object
Constructor Details
#initialize(region, profile_name = nil, ssl_cert_file = nil, aws_key = {}, session_token = nil) ⇒ CfClient
Returns a new instance of CfClient.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 27 def initialize( region, profile_name = nil, ssl_cert_file = nil, aws_key = {}, session_token = nil ) access_key_id = aws_key[:access_key_id] secret_access_key = aws_key[:secret_access_key] creds = self.class.get_credentials( profile_name, access_key_id, secret_access_key, session_token ) ::AWS.config( region: region, credentials: creds, ssl_ca_bundle: ssl_cert_file ) end |
Class Method Details
.get_credentials(profile_name, access_key_id, secret_access_key, session_token) ⇒ Object
Try and get the credentials from an ordered list of locations docs.aws.amazon.com/sdkforruby/api/index.html#Configuration
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 49 def self.get_credentials(profile_name, access_key_id, secret_access_key, session_token) shared_creds = ::Aws::SharedCredentials.new(profile_name: profile_name) if access_key_id && secret_access_key ::Aws::Credentials.new(access_key_id, secret_access_key, session_token) # TODO: these are deprecated, remove them in the next major version elsif ENV['AWS_ACCESS_KEY'] && ENV['AWS_SECRET_KEY'] ::Aws::Credentials.new( ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET_KEY'], ENV['AWS_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 shared_creds.loadable? shared_creds else ::Aws::InstanceProfileCredentials.new(retries: 1) end end |
Instance Method Details
#client ⇒ Object
90 91 92 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 90 def client @client ||= ::Aws::CloudFormation::Client.new end |
#create_stack(options) ⇒ Object
73 74 75 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 73 def create_stack() resource.create_stack() end |
#delete_stack(stack_name) ⇒ Object
85 86 87 88 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 85 def delete_stack(stack_name) s = resource.stack(stack_name) s.delete end |
#get_stack(stack_name) ⇒ Object
77 78 79 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 77 def get_stack(stack_name) resource.stack(stack_name) end |
#get_stack_events(stack_name) ⇒ Object
81 82 83 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 81 def get_stack_events(stack_name) client.describe_stack_events(stack_name: stack_name) end |
#resource ⇒ Object
94 95 96 |
# File 'lib/kitchen/driver/aws/cf_client.rb', line 94 def resource @resource ||= ::Aws::CloudFormation::Resource.new end |