Skip to content

Commit

Permalink
Better way to get account_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuya YAGUCHI committed Aug 30, 2016
1 parent 039a387 commit 9dc9087
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/subiam/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ def initialize(options = {})
@options = {:format => :ruby}.merge(options)
aws_config = options[:aws_config] || {}
@iam = Aws::IAM::Client.new(aws_config)
@driver = Subiam::Driver.new(@iam, options)
@sts = Aws::STS::Client.new(aws_config)
@driver = Subiam::Driver.new(@iam, @sts, options)
@password_manager = options[:password_manager] || Subiam::PasswordManager.new('-', options)
@target = nil
end
Expand Down
5 changes: 3 additions & 2 deletions lib/subiam/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ class Subiam::Driver
MAX_POLICY_SIZE = 2048
MAX_POLICY_VERSIONS = 5

def initialize(iam, options = {})
def initialize(iam, sts, options = {})
@iam = iam
@sts = sts
@options = options
end

Expand Down Expand Up @@ -457,7 +458,7 @@ def unless_dry_run

def account_id
# https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
@account_id ||= @iam.get_user.user.arn.split(':').fetch(4)
@account_id ||= @sts.get_caller_identity.account
end

def policy_arn(policy_name)
Expand Down

0 comments on commit 9dc9087

Please sign in to comment.