Module: Inventory::Iam::Shared
Constant Summary collapse
- @@groups =
{}
Instance Method Summary collapse
-
#all_users ⇒ Object
{ “tung”: [“admin”, “developers”], “vuon”: [“admin”], “bob”: [“developers”] }.
- #group_names(user) ⇒ Object
- #groupless_users ⇒ Object
- #groups ⇒ Object
- #groups_for(user) ⇒ Object
- #user_count(group) ⇒ Object
- #user_names(group) ⇒ Object
- #users ⇒ Object
-
#users_in_group(group_name) ⇒ Object
iam.list_groups does not show the users in the groups.
Instance Method Details
#all_users ⇒ Object
"tung": ["admin", "developers"],
"vuon": ["admin"],
"bob": ["developers"]
37 38 39 40 41 42 |
# File 'lib/inventory/iam/shared.rb', line 37 def all_users @all_users ||= users.inject({}) do |result, user| result[user.user_name] = group_names(user) result end end |
#group_names(user) ⇒ Object
2 3 4 5 |
# File 'lib/inventory/iam/shared.rb', line 2 def group_names(user) groups = groups_for(user) groups.map(&:group_name) end |
#groupless_users ⇒ Object
25 26 27 28 29 30 |
# File 'lib/inventory/iam/shared.rb', line 25 def groupless_users selected_users = all_users.select do |user_name, group_names| group_names.empty? end selected_users.map { |a| a[0] } end |
#groups ⇒ Object
59 60 61 |
# File 'lib/inventory/iam/shared.rb', line 59 def groups @groups ||= iam.list_groups.groups end |
#groups_for(user) ⇒ Object
8 9 10 11 12 |
# File 'lib/inventory/iam/shared.rb', line 8 def groups_for(user) return @@groups[user.user_name] if @@groups[user.user_name] @@groups[user.user_name] = iam.list_groups_for_user(user_name: user.user_name).groups end |
#user_count(group) ⇒ Object
44 45 46 |
# File 'lib/inventory/iam/shared.rb', line 44 def user_count(group) group_counts[group.group_name] end |
#user_names(group) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/inventory/iam/shared.rb', line 48 def user_names(group) users.each do |user| result[user.user_name] = group_names(user) result end end |
#users ⇒ Object
55 56 57 |
# File 'lib/inventory/iam/shared.rb', line 55 def users @users ||= iam.list_users.users end |
#users_in_group(group_name) ⇒ Object
iam.list_groups does not show the users in the groups. so users_in_groups returns an Array of the user_names in the specified group
16 17 18 19 20 21 22 23 |
# File 'lib/inventory/iam/shared.rb', line 16 def users_in_group(group_name) # user_name is a String # group_names is an Array of Strings selected_users = all_users.select do |user_name, group_names| group_names.include?(group_name) end selected_users.map { |a| a[0] } end |