1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
require 'fog/aws/models/iam/managed_policy'
require 'fog/aws/iam/paged_collection'
module Fog
module AWS
class IAM
class ManagedPolicies < Fog::AWS::IAM::PagedCollection
attribute :username
attribute :group_name
attribute :role_name
model Fog::AWS::IAM::ManagedPolicy
def all(options={})
data = if self.username
all_by_user(self.username, options)
elsif self.group_name
all_by_group(self.group_name, options)
elsif self.role_name
all_by_role(self.role_name, options)
else
all_policies(options)
end
load(data)
end
def get(identity)
response = service.get_policy(identity)
new(response.body['Policy'])
rescue Fog::AWS::IAM::NotFound
nil
end
protected
def all_by_user(username, options={})
body = service.list_attached_user_policies(username, page_params(options)).body
merge_attributes(body)
body['Policies'].map do |policy|
service.get_policy(policy['PolicyArn']).body['Policy']
end
end
def all_by_group(group_name, options={})
body = service.list_attached_group_policies(group_name, page_params(options)).body
merge_attributes(body)
body['Policies'].map do |policy|
service.get_policy(policy['PolicyArn']).body['Policy']
end
end
def all_by_role(role_name, options={})
body = service.list_attached_role_policies(role_name, page_params(options)).body
merge_attributes(body)
body['Policies'].map do |policy|
service.get_policy(policy['PolicyArn']).body['Policy']
end
end
def all_policies(options={})
body = service.list_policies(page_params(options)).body
merge_attributes(body)
body['Policies']
end
end
end
end
end
|