Sha256: 7244269a85013f4323c51928c71bfa83a13b5f7f7dfae4a9890a52bae523692e

Contents?: true

Size: 1.38 KB

Versions: 13

Compression:

Stored size: 1.38 KB

Contents

require 'fog/core/collection'
require 'fog/aws/models/iam/policy'

module Fog
  module AWS
    class IAM

      class Policies < Fog::Collection
                
        model Fog::AWS::IAM::Policy
        
        def initialize(attributes = {})
          @username = attributes[:username]
          raise ArgumentError.new("Can't get a policy's user without a username") unless @username
          super
        end
        

        def all
          # AWS method get_user_policy only returns an array of policy names, this is kind of useless, 
          # that's why it has to loop through the list to get the details of each element. I don't like it because it makes this method slow
          policy_names = connection.list_user_policies(@username).body['PolicyNames'] # it returns an array
          policies = []
          policy_names.each do |policy_name|
            policies << connection.get_user_policy(policy_name,@username).body['Policy']
          end
          load(policies) # data is an array of attribute hashes
        end

        def get(identity)
          data = connection.get_user_policy(identity,@username).body['Policy']
          new(data) # data is an attribute hash
        rescue Fog::AWS::IAM::NotFound
          nil
        end
        
        def new(attributes = {})
          super({ :username => @username }.merge!(attributes))
        end
        
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 7 rubygems

Version Path
fog-nirvanix-1.8.2 lib/fog/aws/models/iam/policies.rb
fog-nirvanix-1.8.1 lib/fog/aws/models/iam/policies.rb
fog-parser-fix-1.6.1 lib/fog/aws/models/iam/policies.rb
fog-test-again-1.6.0 lib/fog/aws/models/iam/policies.rb
fog-parser-fix-1.6.0 lib/fog/aws/models/iam/policies.rb
ey-vendored-backup-3.0.27 vendor/gems/fog/lib/fog/aws/models/iam/policies.rb
fog-sgonyea-1.8.1 lib/fog/aws/models/iam/policies.rb
fog-1.8.0 lib/fog/aws/models/iam/policies.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/aws/models/iam/policies.rb
fog-1.7.0 lib/fog/aws/models/iam/policies.rb
fog-1.6.0 lib/fog/aws/models/iam/policies.rb
fog-1.5.0 lib/fog/aws/models/iam/policies.rb
fog-1.4.0 lib/fog/aws/models/iam/policies.rb