Skip to content
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

switched method of determining aws account id to STS #286

Merged
merged 1 commit into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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