Class: AWS::IAM::GroupCollection
- Inherits:
-
Object
- Object
- AWS::IAM::GroupCollection
- Includes:
- Collection::WithPrefix
- Defined in:
- lib/aws/iam/group_collection.rb
Overview
A collection that provides access to IAM groups belonging to this account.
iam = AWS::IAM.new
groups = iam.groups
Creating a Group
You can create a group using the #create method:
group = iam.groups.create("Developers")
Getting a Group by Name
You can get a reference to a server certificate using array notation:
group = iam.groups["Developers"]
Enumerating Groups
Group collections can also be used to enumerate groups:
groups.each do |group|
puts group.name
end
You can limit the groups returned by passing a :prefix
option to any of the enumerator methods. When you pass a prefix, only the certificates whose paths start with the given string will be returned.
Instance Attribute Summary
Attributes included from Collection::WithPrefix
Instance Method Summary collapse
-
#[](name) ⇒ Group
Returns a reference to the group with the given name:.
-
#create(name, options = {}) ⇒ Object
Creates a group.
-
#each(options = {}) {|group| ... } ⇒ nil
Yields once for each group.
-
#enumerator(options = {}) ⇒ Enumerator
Returns an enumerable object for this collection.
Methods included from Collection::WithPrefix
Methods included from Core::Collection
#each_batch, #enum, #first, #in_groups_of, #page
Instance Method Details
#[](name) ⇒ Group
Returns a reference to the group with the given name:
group = iam.groups['groupname']
111 112 113 |
# File 'lib/aws/iam/group_collection.rb', line 111 def [] name Group.new(name, :config => config) end |
#create(name, options = {}) ⇒ Object
Creates a group.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/aws/iam/group_collection.rb', line 59 def create(name, = {}) client_opts = { :group_name => name }.merge() if path = client_opts[:path] client_opts[:path] = "/#{path}/". sub(%r{^//}, "/"). sub(%r{//$}, "/") end resp = client.create_group(client_opts) Group.new(resp.group.group_name, :config => config) end |
#each(options = {}) {|group| ... } ⇒ nil
Yields once for each group.
You can limit the number of groups yielded using :limit
and :path_prefix
.
88 89 90 |
# File 'lib/aws/iam/group_collection.rb', line 88 def each = {}, &block super(, &block) end |
#enumerator(options = {}) ⇒ Enumerator
Returns an enumerable object for this collection. This can be useful if you want to call an enumerable method that does not accept options (e.g. collect
, first
, etc).
groups.enumerator(:path_prefix => '/admin').collect(&:name)
101 102 103 |
# File 'lib/aws/iam/group_collection.rb', line 101 def enumerator = {} super() end |