Module: Awspec::Helper::Finder::Iam

Included in:
Awspec::Helper::Finder
Defined in:
lib/awspec/helper/finder/iam.rb

Instance Method Summary collapse

Instance Method Details

#select_all_attached_policiesObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/awspec/helper/finder/iam.rb', line 64

def select_all_attached_policies
  selected = []
  res = iam_client.list_policies

  loop do
    selected += res.policies.select { |p| p.attachment_count > 0 }
    break unless res.is_truncated
    res = iam_client.list_policies({
                                     marker: res.marker
                                   })
  end

  selected
end

#select_all_iam_groupsObject



105
106
107
108
109
# File 'lib/awspec/helper/finder/iam.rb', line 105

def select_all_iam_groups
  iam_client.list_groups.map do |response|
    response.groups
  end.flatten
end

#select_all_iam_rolesObject



111
112
113
114
115
# File 'lib/awspec/helper/finder/iam.rb', line 111

def select_all_iam_roles
  iam_client.list_roles.map do |response|
    response.roles
  end.flatten
end

#select_all_iam_usersObject



99
100
101
102
103
# File 'lib/awspec/helper/finder/iam.rb', line 99

def select_all_iam_users
  iam_client.list_users.map do |response|
    response.users
  end.flatten
end

#select_attached_entities(policy_id) ⇒ Object



79
80
81
82
# File 'lib/awspec/helper/finder/iam.rb', line 79

def select_attached_entities(policy_id)
  policy = find_iam_policy(policy_id)
  iam_client.list_entities_for_policy(policy_arn: policy[:arn])
end

#select_attached_groups(policy_id) ⇒ Object



89
90
91
92
# File 'lib/awspec/helper/finder/iam.rb', line 89

def select_attached_groups(policy_id)
  entities = select_attached_entities(policy_id)
  entities.policy_groups
end

#select_attached_roles(policy_id) ⇒ Object



94
95
96
97
# File 'lib/awspec/helper/finder/iam.rb', line 94

def select_attached_roles(policy_id)
  entities = select_attached_entities(policy_id)
  entities.policy_roles
end

#select_attached_users(policy_id) ⇒ Object



84
85
86
87
# File 'lib/awspec/helper/finder/iam.rb', line 84

def select_attached_users(policy_id)
  entities = select_attached_entities(policy_id)
  entities.policy_users
end

#select_iam_group_by_user_name(user_name) ⇒ Object



39
40
41
42
43
44
# File 'lib/awspec/helper/finder/iam.rb', line 39

def select_iam_group_by_user_name(user_name)
  res = iam_client.list_groups_for_user({
                                          user_name: user_name
                                        })
  res.groups
end

#select_policy_evaluation_results(policy_arn, action_name, resource_arn = nil, context_entries = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/awspec/helper/finder/iam.rb', line 27

def select_policy_evaluation_results(policy_arn, action_name, resource_arn = nil, context_entries = nil)
  options = {
    policy_source_arn: policy_arn,
    action_names: [action_name]
  }
  options[:resource_arns] = [resource_arn] if resource_arn
  options[:context_entries] = context_entries if context_entries

  res = iam_client.simulate_principal_policy(options)
  res.evaluation_results
end