Skip to content

Commit

Permalink
Fix for Regression in AWS profile support
Browse files Browse the repository at this point in the history
Signed-off-by: Kapil Chouhan <[email protected]>
  • Loading branch information
Kapil Chouhan committed Feb 24, 2020
1 parent 1385fba commit 5b4832e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/chef/knife/helpers/ec2_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def iam_name_from_profile(profile)
if profile && profile.key?("arn")
name = profile["arn"].split("/")[-1]
end
name ||= ""
name || ""
end

def ini_parse(file)
Expand Down Expand Up @@ -325,10 +325,8 @@ def validate_aws_credential_file!
# [default]
# aws_access_key_id = somethingsomethingdarkside
# aws_secret_access_key = somethingsomethingdarkside

aws_creds = ini_parse(File.read(aws_cred_file_location))
profile = locate_config_value(:aws_profile)
profile = "profile #{profile}" if profile != "default"
Chef::Log.debug "Using AWS profile #{profile}"
entries = if aws_creds.values.first.key?("AWSAccessKeyId")
aws_creds.values.first
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/ec2_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@
it "loads the correct profile" do
Chef::Config[:knife][:aws_profile] = "other"
allow(File).to receive(:read)
.and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET\n\n[profile other]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
.and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET\n\n[other]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
knife_ec2_create.validate_aws_config!
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
Expand All @@ -961,7 +961,7 @@
it "raises exception" do
Chef::Config[:knife][:aws_profile] = "xyz"
allow(File).to receive(:read).and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET")
expect { knife_ec2_create.validate_aws_config! }.to raise_error("The provided --aws-profile 'profile xyz' is invalid. Does the credential file at '/apple/pear' contain this profile?")
expect { knife_ec2_create.validate_aws_config! }.to raise_error("The provided --aws-profile 'xyz' is invalid. Does the credential file at '/apple/pear' contain this profile?")
end
end

Expand Down

0 comments on commit 5b4832e

Please sign in to comment.