Class: StackMaster::Identity

Inherits:
Object
  • Object
show all
Defined in:
lib/stack_master/identity.rb

Constant Summary collapse

AllowedAccountAliasesError =
Class.new(StandardError)
MissingIamPermissionsError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#accountObject



17
18
19
# File 'lib/stack_master/identity.rb', line 17

def 
  @account ||= sts.get_caller_identity.
end

#account_aliasesObject



21
22
23
24
25
# File 'lib/stack_master/identity.rb', line 21

def 
  @aliases ||= iam..
rescue Aws::IAM::Errors::AccessDenied
  raise MissingIamPermissionsError, 'Failed to retrieve account aliases. Missing required IAM permission: iam:ListAccountAliases'
end

#running_in_account?(accounts) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
# File 'lib/stack_master/identity.rb', line 6

def running_in_account?(accounts)
  return true if accounts.nil? || accounts.empty? || (accounts)

  # skip alias check (which makes an API call) if all values are account IDs
  return false if accounts.all? { || () }

  (accounts)
rescue MissingIamPermissionsError
  raise AllowedAccountAliasesError, 'Failed to validate whether the current AWS account is allowed'
end