2015-05-21 12:30:27 -04:00
|
|
|
require 'fog/aws/models/iam/group'
|
2015-05-28 16:20:48 -04:00
|
|
|
require 'fog/aws/iam/paged_collection'
|
2015-05-21 12:30:27 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class IAM
|
2015-05-28 16:20:48 -04:00
|
|
|
class Groups < Fog::AWS::IAM::PagedCollection
|
2015-05-21 12:30:27 -04:00
|
|
|
|
|
|
|
attribute :username
|
|
|
|
|
|
|
|
model Fog::AWS::IAM::Group
|
|
|
|
|
|
|
|
def all(options = {})
|
|
|
|
data, records = if self.username
|
|
|
|
response = service.list_groups_for_user(self.username, options)
|
|
|
|
[response.body, response.body['GroupsForUser']]
|
|
|
|
else
|
|
|
|
response = service.list_groups(options)
|
|
|
|
[response.body, response.body['Groups']]
|
|
|
|
end
|
|
|
|
|
|
|
|
merge_attributes(data)
|
|
|
|
load(records)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(identity)
|
|
|
|
data = service.get_group(identity)
|
|
|
|
|
|
|
|
group = data.body['Group']
|
|
|
|
users = data.body['Users'].map { |u| service.users.new(u) }
|
|
|
|
|
|
|
|
new(group.merge(:users => users))
|
|
|
|
rescue Fog::AWS::IAM::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|