Class: AWS::IAM::GroupCollection

Inherits:
Object
  • Object
show all
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

#prefix

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from Collection::WithPrefix

#initialize, #with_prefix

Methods included from Core::Collection::Limitable

#each_batch

Methods included from Core::Collection

#each_batch, #enum, #first, #in_groups_of, #page

Methods included from Core::Model

#client, #config_prefix, #initialize, #inspect

Instance Method Details

#[](name) ⇒ Group

Returns a reference to the group with the given name:

group = iam.groups['groupname']

Parameters:

  • name (String)

    Name of the group to return a reference for.

Returns:

  • (Group)

    Returns a reference to the named group.


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.

Parameters:

  • name (String)

    Name of the group to create. Do not include the path in this value.

  • options (Hash) (defaults to: {})

    Options for creating the group.

Options Hash (options):

  • :path (String)

    The path to the group.


59
60
61
62
63
64
65
66
67
68
# 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 = {}) {|group| ... } ⇒ nil

Yields once for each group.

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

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :path_prefix (String) — default: '/'

    A path prefix that filters according to the path of the group.

  • :limit (Integer)

    The maximum number of groups to yield.

  • :batch_size (Integer)

    The maximum number of groups to retrieve in each service request.

Yield Parameters:

Returns:

  • (nil)

88
89
90
# File 'lib/aws/iam/group_collection.rb', line 88

def each options = {}, &block
  super(options, &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)

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :path_prefix (String) — default: '/'

    A path prefix that filters according to the path of the group.

  • :limit (Integer)

    The maximum number of groups to yield.

  • :batch_size (Integer)

    The maximum number of groups to retrieve in each service request.

Returns:

  • (Enumerator)

101
102
103
# File 'lib/aws/iam/group_collection.rb', line 101

def enumerator options = {}
  super(options)
end