ruby/example_code/iam/iam_ruby_example_show_admins.rb
# Determines whether the specified user in
# AWS Identity and Access Management (IAM) has a policy attached that
# provides administrator privileges.
#
# Prerequisites:
# - The existing user in IAM.
#
# @param user [Aws::IAM::User] The specified user.
# @param admin_access [String] The name of the administrator-related policy
#   to search for, for example 'AdministratorAccess'.
# @return [Boolean] true if the specified user has a policy attached that
#   provides administrator privileges; otherwise, false.
# @example
#   client = Aws::IAM::Client.new
#   users = client.get_account_authorization_details(filter: ['User']).user_detail_list
#   exit 1 unless user_has_attached_policy?(users[0], 'AdministratorAccess')

Determines whether the specified user in
AWS Identity and Access Management (IAM) has a policy attached that
provides administrator privileges.

The existing user in IAM.
Determines whether the specified user in AWS Identity and Access Management ( IAM ) has a policy attached that provides administrator privileges . The existing user in IAM .
def user_has_attached_policy?(user, admin_access)
  attached_policies = user.attached_managed_policies
  attached_policies.each do |p|
    return true if p.policy_name == admin_access
  end
  return false
end
def user_has_attached_policy? ( user , admin_access ) attached_policies = user . attached_managed_policies attached_policies . each do | p | return true if p . policy_name == admin_access end return false end
Determines whether the specified user in
AWS Identity and Access Management (IAM) has a policy attached that
provides administrator privileges.
Determines whether the specified user in AWS Identity and Access Management ( IAM ) has a policy attached that provides administrator privileges .
true if the specified user has a policy attached that provides administrator privileges; otherwise, false.
true if the specified user has a policy attached that provides administrator privileges ; otherwise false .
Boolean
user
The specified user.
The specified user .
admin_access
The name of the administrator-related policy to search for, for example 'AdministratorAccess'.
The name of the administrator - related policy to search for for example ' AdministratorAccess ' .
example
client = Aws::IAM::Client.new users = client.get_account_authorization_details(filter: ['User']).user_detail_list exit 1 unless user_has_attached_policy?(users[0], 'AdministratorAccess')
client = Aws :: IAM :: Client . new users = client . get_account_authorization_details ( filter : [ ' User ' ] ) . user_detail_list exit 1 unless user_has_attached_policy? ( users [ 0 ] ' AdministratorAccess ' )