Class: Fog::AWS::IAM::Policies
- Inherits:
-
Collection
- Object
- Array
- Collection
- Fog::AWS::IAM::Policies
- Defined in:
- lib/fog/aws/models/iam/policies.rb
Instance Attribute Summary
Attributes inherited from Collection
Instance Method Summary collapse
- #all ⇒ Object
- #get(identity) ⇒ Object
-
#initialize(attributes = {}) ⇒ Policies
constructor
A new instance of Policies.
- #new(attributes = {}) ⇒ Object
Methods inherited from Collection
#clear, #create, #destroy, #inspect, #load, model, #model, #reload, #table, #to_json
Methods included from Fog::Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Fog::Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Policies
Returns a new instance of Policies.
12 13 14 15 16 |
# File 'lib/fog/aws/models/iam/policies.rb', line 12 def initialize(attributes = {}) @username = attributes[:username] raise ArgumentError.new("Can't get a policy's user without a username") unless @username super end |
Instance Method Details
#all ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/aws/models/iam/policies.rb', line 19 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 = service.list_user_policies(@username).body['PolicyNames'] # it returns an array policies = [] policy_names.each do |policy_name| policies << service.get_user_policy(policy_name,@username).body['Policy'] end load(policies) # data is an array of attribute hashes end |
#get(identity) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/fog/aws/models/iam/policies.rb', line 30 def get(identity) data = service.get_user_policy(identity,@username).body['Policy'] new(data) # data is an attribute hash rescue Fog::AWS::IAM::NotFound nil end |
#new(attributes = {}) ⇒ Object
37 38 39 |
# File 'lib/fog/aws/models/iam/policies.rb', line 37 def new(attributes = {}) super({ :username => @username }.merge!(attributes)) end |