Skip to content

Commit

Permalink
Merge pull request test-kitchen#296 from davidcpell/allow-default-pro…
Browse files Browse the repository at this point in the history
…file-again

reinstate default shared creds option
  • Loading branch information
Seth Thomas committed Feb 16, 2017
2 parents 3c748ed + 5f554ab commit 4044512
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/kitchen/driver/aws/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def self.get_credentials(profile_name, access_key_id, secret_access_key, session
)
elsif profile_name
::Aws::SharedCredentials.new(:profile_name => profile_name)
elsif default_shared_credentials?
::Aws::SharedCredentials.new
else
::Aws::InstanceProfileCredentials.new(:retries => 1)
end
Expand All @@ -91,8 +93,8 @@ def self.get_credentials(profile_name, access_key_id, secret_access_key, session
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

def self.get_shared_creds(profile_name)
::Aws::SharedCredentials.new(:profile_name => profile_name)
def self.default_shared_credentials?
::Aws::SharedCredentials.new.loadable?
rescue ::Aws::Errors::NoSuchProfileError
false
end
Expand Down
19 changes: 17 additions & 2 deletions spec/kitchen/driver/ec2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@
it "loads IAM credentials last" do
iam = instance_double(Aws::InstanceProfileCredentials)

allow(Kitchen::Driver::Aws::Client).to receive(:get_shared_creds).and_return(false)
allow(Kitchen::Driver::Aws::Client).to receive(:default_shared_credentials?).and_return(false)
allow(Aws::InstanceProfileCredentials).to receive(:new).and_return(iam)

env_creds(nil, nil) do
expect(Kitchen::Driver::Aws::Client.get_credentials(nil, nil, nil, nil, nil)).to eq(iam)
end
end

it "loads the shared credentials file second to last" do
it "loads the default shared creds profile second to last" do
shared = instance_double(Aws::SharedCredentials)

allow(Kitchen::Driver::Aws::Client).to receive(:default_shared_credentials?).and_return(true)
allow(Aws::SharedCredentials).to \
receive(:new).and_return(shared)

env_creds(nil, nil) do
expect(Kitchen::Driver::Aws::Client.get_credentials(nil, nil, nil, nil, nil)).to \
eq(shared)
end
end

it "loads a custom shared credentials profile third to last" do
shared = instance_double(Aws::SharedCredentials)

allow(Aws::SharedCredentials).to \
Expand Down Expand Up @@ -103,6 +116,8 @@

# nothing else is set, so we default to this
it "loads an Instance Profile last" do
allow(Kitchen::Driver::Aws::Client).to receive(:default_shared_credentials?).and_return(false)

expect(Aws::InstanceProfileCredentials).to \
receive(:new).and_return(iam)
expect(Aws::STS::Client).to \
Expand Down

0 comments on commit 4044512

Please sign in to comment.