-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add explicit option for using iam profile for authentication #107
Changes from 1 commit
69d4f41
4b12e1b
adc082d
389522c
aaaa892
1945879
9853526
770557e
f13c073
d352cb4
40ce055
e1d5ae4
16302ab
ac3d1c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ module Driver | |
# | ||
# @author Fletcher Nichol <[email protected]> | ||
class Ec2 < Kitchen::Driver::SSHBase | ||
|
||
extend Fog::AWS::CredentialFetcher::ServiceMethods | ||
default_config :region, 'us-east-1' | ||
default_config :availability_zone, 'us-east-1b' | ||
|
@@ -41,14 +40,16 @@ class Ec2 < Kitchen::Driver::SSHBase | |
default_config :private_ip_address, nil | ||
default_config :iam_profile_name, nil | ||
default_config :price, nil | ||
default_config :use_iam_profile, false | ||
default_config :aws_access_key_id do |driver| | ||
ENV['AWS_ACCESS_KEY'] || ENV['AWS_ACCESS_KEY_ID'] || iam_creds[:aws_access_key_id] | ||
ENV['AWS_ACCESS_KEY'] || ENV['AWS_ACCESS_KEY_ID'] || driver.iam_creds[:aws_access_key_id] | ||
end | ||
default_config :aws_secret_access_key do |driver| | ||
ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY'] || iam_creds[:aws_secret_access_key] | ||
ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY'] \ | ||
|| driver.iam_creds[:aws_secret_access_key] | ||
end | ||
default_config :aws_session_token do |driver| | ||
ENV['AWS_SESSION_TOKEN'] || ENV['AWS_TOKEN'] || iam_creds[:aws_session_token] | ||
ENV['AWS_SESSION_TOKEN'] || ENV['AWS_TOKEN'] || driver.iam_creds[:aws_session_token] | ||
end | ||
default_config :aws_ssh_key_id do |driver| | ||
ENV['AWS_SSH_KEY_ID'] | ||
|
@@ -98,10 +99,10 @@ class Ec2 < Kitchen::Driver::SSHBase | |
end | ||
end | ||
|
||
def self.iam_creds | ||
def iam_creds | ||
@iam_creds ||= begin | ||
fetch_credentials(use_iam_profile:true) | ||
rescue RuntimeError => e | ||
config[:use_iam_profile] ? fetch_credentials(use_iam_profile: true) : {} | ||
rescue RuntimeError, NoMethodError => e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do you expect the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fetch_credentials calls super when it fails, so since we don't have a super for it to fail over to we need to catch NoMethodError, I think I made a note in the commit message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still have the same question about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/fog/fog-aws/blob/master/lib/fog/aws/credential_fetcher.rb#L27 fetch_credentials will always call super if it fails There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NM, I was able to reproduce the error from https://github.com/test-kitchen/kitchen-ec2/pull/104/files locally and I see why you have the |
||
debug("fetch_credentials failed with exception #{e.message}:#{e.backtrace.join("\n")}") | ||
{} | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to break this across multiple lines you don't need the
\
- just leave the||
at the end of the line