class AWS::IAM::GroupCollection

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.

Public Instance Methods

[](name) click to toggle source

Returns a reference to the group with the given name:

group = iam.groups['groupname']

@param [String] name Name of the group to return a reference for. @return [Group] Returns a reference to the named group.

# File lib/aws/iam/group_collection.rb, line 111
def [] name
  Group.new(name, :config => config)
end
create(name, options = {}) click to toggle source

Creates a group.

@param [String] name Name of the group to create. Do not

include the path in this value.

@param [Hash] options Options for creating the group.

@option options [String] :path The path to the group.

# File lib/aws/iam/group_collection.rb, line 59
def create(name, options = {})
  client_opts = { :group_name => name }.merge(options)
  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 = {}) click to toggle source

Yields once for each group.

You can limit the number of groups yielded using :limit and :path_prefix.

@param [Hash] options

@option options [String] :path_prefix (‘/’) A path prefix that

filters according to the path of the group.

@option options [Integer] :limit The maximum number of groups

to yield.

@option options [Integer] :batch_size The maximum number of

groups to retrieve in each service request.

@yieldparam [Group] group @return [nil]

# File lib/aws/iam/group_collection.rb, line 88
def each options = {}, &block
  super(options, &block)
end
enumerator(options = {}) click to toggle source

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)

@param (see each) @option (see each) @return [Enumerator]

# File lib/aws/iam/group_collection.rb, line 101
def enumerator options = {}
  super(options)
end

Protected Instance Methods

each_item(response) { |group| ... } click to toggle source

@private

# File lib/aws/iam/group_collection.rb, line 117
def each_item response, &block
  response.groups.each do |item|

    group = Group.new_from(:list_groups, item,
                           item.group_name,
                           :config => config)

    yield(group)

  end
end