Skip to content

Commit

Permalink
switches method of determining aws account id to STS (#286)
Browse files Browse the repository at this point in the history
This is more stable, as it also works when using  temporary credentials.

Signed-off-by: Thorsten Krüger <thorstenkg@gmail.com>
  • Loading branch information
tkrueger authored and jquick committed Apr 24, 2018
1 parent 4cc6f20 commit 5414790
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
5 changes: 2 additions & 3 deletions lib/train/transports/aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ def uri

def unique_identifier
# use aws account id
client = aws_client(::Aws::IAM::Client)
arn = client.get_user.user.arn
arn.split(':')[4]
client = aws_client(::Aws::STS::Client)
client.get_caller_identity.account
end
end
end
Expand Down
23 changes: 10 additions & 13 deletions test/unit/transports/aws_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,23 @@ def initialize(hash)
end

describe 'unique_identifier' do
class AwsArn
def arn
'arn:aws:iam::158551926027:user/test-fixture-maker'
end
end

class AwsUser
def user
AwsArn.new
class AwsCallerId
def account
"123456789012"
end
end

class AwsClient
def get_user
AwsUser.new
class StsClient
def get_caller_identity
AwsCallerId.new
end
end

it 'returns an account id' do
connection.stubs(:aws_client).returns(AwsClient.new)
connection.unique_identifier.must_equal '158551926027'
connection.stubs(:aws_client).returns(StsClient.new)
connection.unique_identifier.must_equal '123456789012'
end
end

end

0 comments on commit 5414790

Please sign in to comment.