Sha256: 92bfe0b80aeb55c522ce1947a9da00eb1e136ddbbabadae268c091ae359b5781

Contents?: true

Size: 1.61 KB

Versions: 22

Compression:

Stored size: 1.61 KB

Contents

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

        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)
                 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_policies(options={})
          body = service.list_policies(page_params(options)).body
          merge_attributes(body)

          body['Policies']
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
fog-aws-1.1.0 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-1.0.0 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.13.0 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.12.0 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.11.0 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.10.0 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.9.4 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.9.3 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.9.2 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.9.1 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.9.0 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.8.1 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.8.0 lib/fog/aws/models/iam/managed_policies.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-aws-0.7.5/lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.7.6 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.7.5 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.7.4 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.7.3 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.7.2 lib/fog/aws/models/iam/managed_policies.rb
fog-aws-0.6.0 lib/fog/aws/models/iam/managed_policies.rb