Class: AWS::IAM::UserCollection

Inherits:
Object
  • Object
show all
Includes:
Collection::WithPrefix
Defined in:
lib/aws/iam/user_collection.rb

Overview

A collection that provides access to IAM users belonging to this account.

iam = AWS::IAM.new
users = iam.users

Creating A User

To create an IAM user you need only provide a user name.

user = users.create('username')

You can also provide an optional :path that can be used to organize users.

user = users.create('johndoe', :path => '/staff/customer_support/')

Getting a User by Name

You can get a referene to a user by using array notation:

user = users['username']

Enumerating Users

A user collection can also be used to enumerate users:

users.each do |user|
  puts user.name
end

Path Prefixes

You can also find/enumerate users who’s path begins with a given prefix:

users.each(:path_prefix => '/staff/developers/ruby').each do |ruby_dev|
  puts "#{ruby_dev.name} is awesome!"
end

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) ⇒ User

Returns a reference to the user with the given name:

user = iam.users['username']

Parameters:

  • name (String)

    Name of the user to return a reference for.

Returns:

  • (User)

    Returns a reference to the named user.



80
81
82
# File 'lib/aws/iam/user_collection.rb', line 80

def [] name
  User.new(name.to_s, :config => config)
end

#create(name, options = {}) ⇒ User

Returns the newly created user.

Parameters:

  • name (String)

    Name of the user to create.

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

    a customizable set of options

Options Hash (options):

Returns:

  • (User)

    Returns the newly created user.



65
66
67
68
69
70
71
72
# File 'lib/aws/iam/user_collection.rb', line 65

def create name, options = {}
  create_opts = {}
  create_opts[:user_name] = name
  create_opts[:path] = options[:path] if options[:path]
  resp = client.create_user(create_opts)
  User.new_from(:create_user, resp.user, 
    resp.user.user_name, :config => config)
end

#each(options = {}) {|user| ... } ⇒ nil

Yields once for each user.

You can limit the number of users 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 user.

  • :limit (Integer)

    The maximum number of users to yield.

  • :batch_size (Integer)

    The maximum number of users to retrieve with each service request.

Yield Parameters:

Returns:

  • (nil)


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

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).

users.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 user.

  • :limit (Integer)

    The maximum number of users to yield.

  • :batch_size (Integer)

    The maximum number of users to retrieve with each service request.

Returns:

  • (Enumerator)


114
115
116
# File 'lib/aws/iam/user_collection.rb', line 114

def enumerator options = {}
  super(options)
end