You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.
Class: AWS::IAM::UserCollection
- Inherits:
-
Object
- Object
- AWS::IAM::UserCollection
- 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
Instance Method Summary collapse
-
#[](name) ⇒ User
Returns a reference to the user with the given name:.
-
#create(name, options = {}) ⇒ User
Returns the newly created user.
-
#each(options = {}) {|user| ... } ⇒ nil
Yields once for each user.
-
#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) ⇒ User
Returns a reference to the user with the given name:
user = iam.users['username']
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.
65 66 67 68 69 70 71 72 |
# File 'lib/aws/iam/user_collection.rb', line 65 def create name, = {} create_opts = {} create_opts[:user_name] = name create_opts[:path] = [:path] if [: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
.
101 102 103 |
# File 'lib/aws/iam/user_collection.rb', line 101 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).
users.enumerator(:path_prefix => '/admin').collect(&:name)
114 115 116 |
# File 'lib/aws/iam/user_collection.rb', line 114 def enumerator = {} super() end |