From 6db35d156de243b31f5224c69b6c80084cc6bb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Kr=C3=BCger?= Date: Thu, 19 Apr 2018 17:41:33 +0200 Subject: [PATCH] switches method of determining aws account id to STS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is more stable, as it also works when using temporary credentials. Signed-off-by: Thorsten Krüger --- lib/train/transports/aws.rb | 5 ++--- test/unit/transports/aws_test.rb | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/train/transports/aws.rb b/lib/train/transports/aws.rb index f2b1f144..0d9e2eea 100644 --- a/lib/train/transports/aws.rb +++ b/lib/train/transports/aws.rb @@ -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 diff --git a/test/unit/transports/aws_test.rb b/test/unit/transports/aws_test.rb index 92e910ca..db06d636 100644 --- a/test/unit/transports/aws_test.rb +++ b/test/unit/transports/aws_test.rb @@ -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