2012-06-02 11:04:17 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/aws/models/iam/user'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class IAM
|
|
|
|
|
|
|
|
class Users < Fog::Collection
|
|
|
|
|
2012-07-23 16:47:25 -04:00
|
|
|
attribute :is_truncated, :aliases => 'IsTruncated'
|
|
|
|
attribute :marker, :aliases => 'Marker'
|
|
|
|
|
2012-06-02 11:04:17 -04:00
|
|
|
model Fog::AWS::IAM::User
|
|
|
|
|
2012-07-23 16:47:25 -04:00
|
|
|
def all(options = {})
|
|
|
|
merge_attributes(options)
|
2012-12-22 18:30:34 -05:00
|
|
|
data = service.list_users(options).body
|
2012-07-23 16:47:25 -04:00
|
|
|
merge_attributes('IsTruncated' => data['IsTruncated'], 'Marker' => data['Marker'])
|
|
|
|
load(data['Users']) # data is an array of attribute hashes
|
2012-06-02 11:04:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(identity)
|
2012-12-22 18:30:34 -05:00
|
|
|
data = service.get_user(identity).body['User']
|
2012-06-02 11:04:17 -04:00
|
|
|
new(data) # data is an attribute hash
|
|
|
|
rescue Fog::AWS::IAM::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2012-07-23 16:47:25 -04:00
|
|
|
alias :each_user_this_page :each
|
|
|
|
|
|
|
|
def each
|
|
|
|
if !block_given?
|
|
|
|
self
|
|
|
|
else
|
|
|
|
subset = dup.all
|
|
|
|
|
|
|
|
subset.each_user_this_page {|f| yield f}
|
|
|
|
while subset.is_truncated
|
|
|
|
subset = subset.all('Marker' => subset.marker, 'MaxItems' => 1000)
|
|
|
|
subset.each_user_this_page {|f| yield f}
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
2012-06-02 11:04:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-07-23 16:47:25 -04:00
|
|
|
end
|