ruby/example_code/iam/iam_ruby_example_show_admins.rb
# Determines whether the specified group in
# AWS Identity and Access Management (IAM) is associated with a policy that
# provides administrator privileges.
#
# Prerequisites:
# - The existing group in IAM.
#
# @param client [Aws::IAM::Client] An initialized IAM client.
# @param group [Aws::IAM::Group] The specified group.
# @param admin_access [String] The name of the administrator-related policy
#   to search for, for example 'AdministratorAccess'.
# @return [Boolean] true if the specified group is associated with a policy that
#   provides administrator privileges; otherwise, false.
# @example
#   client = Aws::IAM::Client.new
#   groups = client.list_groups_for_user(user_name: 'Mary')
#   exit 1 unless group_has_admin_policy?(client, groups[0], 'AdministratorAccess')

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

The existing group in IAM.
Determines whether the specified group in AWS Identity and Access Management ( IAM ) is associated with a policy that provides administrator privileges . The existing group in IAM .
def group_has_admin_policy?(client, group, admin_access)
  resp = client.list_group_policies(
    group_name: group.group_name
  )
  resp.policy_names.each do |name|
    return true if name == admin_access
  end
  return false
end
def group_has_admin_policy? ( client , group , admin_access ) resp = client . list_group_policies ( group_name : group . group_name ) resp . policy_names . each do | name | return true if name == admin_access end return false end
Determines whether the specified group in
AWS Identity and Access Management (IAM) is associated with a policy that
provides administrator privileges.
Determines whether the specified group in AWS Identity and Access Management ( IAM ) is associated with a policy that provides administrator privileges .
true if the specified group is associated with a policy that provides administrator privileges; otherwise, false.
true if the specified group is associated with a policy that provides administrator privileges ; otherwise false .
Boolean
client
An initialized IAM client.
An initialized IAM client .
group
The specified group.
The specified group .
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 groups = client.list_groups_for_user(user_name: 'Mary') exit 1 unless group_has_admin_policy?(client, groups[0], 'AdministratorAccess')
client = Aws :: IAM :: Client . new groups = client . list_groups_for_user ( user_name : ' Mary ' ) exit 1 unless group_has_admin_policy? ( client groups [ 0 ] ' AdministratorAccess ' )