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
Instance Method Details
#[](name) ⇒ User
Returns a reference to the user with the given name:
user = iam.users['username']
83 84 85 |
# File 'lib/aws/iam/user_collection.rb', line 83 def [] name User.new(name.to_s, :config => config) end |
#create(name, options = {}) ⇒ User
Returns the newly created user.
68 69 70 71 72 73 74 75 |
# File 'lib/aws/iam/user_collection.rb', line 68 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
.
104 105 106 |
# File 'lib/aws/iam/user_collection.rb', line 104 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)
117 118 119 |
# File 'lib/aws/iam/user_collection.rb', line 117 def enumerator = {} super() end |