ruby/example_code/iam/iam_ruby_example_show_admins.rb
def user_has_admin_from_group?(client, user, admin_access)
  resp = client.list_groups_for_user(
    user_name: user.user_name
  )

  resp.groups.each do |group|
    return true if group_has_admin_policy?(client, group, admin_access)
    return true if group_has_attached_policy?(client, group, admin_access)
  end

  return false
end
# Determines whether the specified user in
# AWS Identity and Access Management (IAM) is associated with a group
# that has administrator privileges.
#
# Prerequisites:
# - The existing user in IAM.
#
# @param client [Aws::IAM::Client] An initialized IAM client.
# @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 is associated with a group that
#   has 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_admin_from_group?(client, users[0], 'AdministratorAccess')

Determines whether the specified user in
AWS Identity and Access Management (IAM) is associated with a group
that has administrator privileges.

The existing user in IAM.
Determines whether the specified user in AWS Identity and Access Management ( IAM ) is associated with a group that has administrator privileges . The existing user in IAM .
def user_has_admin_from_group?(client, user, admin_access)
  resp = client.list_groups_for_user(
    user_name: user.user_name
  )
  resp.groups.each do |group|
    return true if group_has_admin_policy?(client, group, admin_access)
    return true if group_has_attached_policy?(client, group, admin_access)
  end
  return false
end
def user_has_admin_from_group? ( client , user , admin_access ) resp = client . list_groups_for_user ( user_name : user . user_name ) resp . groups . each do | group | return true if group_has_admin_policy? ( client , group , admin_access ) return true if group_has_attached_policy? ( client , group , admin_access ) end return false end
Determines whether the specified user in
AWS Identity and Access Management (IAM) is associated with a group
that has administrator privileges.
Determines whether the specified user in AWS Identity and Access Management ( IAM ) is associated with a group that has administrator privileges .
true if the specified user is associated with a group that has administrator privileges; otherwise, false.
true if the specified user is associated with a group that has administrator privileges ; otherwise false .
Boolean
client
An initialized IAM client.
An initialized IAM client .
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_admin_from_group?(client, users[0], 'AdministratorAccess')
client = Aws :: IAM :: Client . new users = client . get_account_authorization_details ( filter : [ ' User ' ] ) . user_detail_list exit 1 unless user_has_admin_from_group? ( client users [ 0 ] ' AdministratorAccess ' )