Module: AWS::IAM::PolicyCollection
- Includes:
- Collection
- Included in:
- GroupPolicyCollection, UserPolicyCollection
- Defined in:
- lib/aws/iam/policy_collection.rb
Overview
Shared methods exposing a collection of policy documents associated with an IAM resource (a User or a Group). Policy collections can be constructed using Group#policies and User#policies.
Instance Method Summary collapse
-
#[](name) ⇒ Policy
Retrieves a policy document by name.
-
#[]=(name, document) ⇒ Object
Adds or replaces a policy document.
-
#clear ⇒ Object
Removes all policies from the collection.
-
#delete(name) ⇒ Object
Deletes a policy by name.
- #each(opts = {}) {|name, policy| ... } ⇒ Object
-
#has_key?(name) ⇒ Boolean
(also: #include?, #key?, #member?)
True if there is a policy with the given name.
-
#keys ⇒ Enumerator<String>
(also: #names)
An enumerator for retrieving all the policy names that are currently associated with the resource.
-
#to_h ⇒ Hash
The contents of the collection as a hash.
-
#values ⇒ Enumerator<Policy>
An enumerator for retrieving all the policy documents that are currently associated with the resource.
-
#values_at(*names) ⇒ Array<Policy>
Retrieves multiple policy documents by name.
Methods included from Core::Collection
#each_batch, #enum, #first, #in_groups_of, #page
Instance Method Details
#[](name) ⇒ Policy
Retrieves a policy document by name.
33 34 35 36 37 38 |
# File 'lib/aws/iam/policy_collection.rb', line 33 def [] name resp = get_policy(:policy_name => name) Policy.from_json(URI.unescape(resp.policy_document)) rescue Errors::NoSuchEntity => e nil end |
#[]=(name, document) ⇒ Object
Adds or replaces a policy document.
48 49 50 51 52 53 |
# File 'lib/aws/iam/policy_collection.rb', line 48 def []= name, document document = document.to_json if document.respond_to?(:to_json) and !document.kind_of?(String) put_policy(:policy_name => name, :policy_document => document) end |
#clear ⇒ Object
Removes all policies from the collection.
95 96 97 |
# File 'lib/aws/iam/policy_collection.rb', line 95 def clear keys.each { |k| delete(k) } end |
#delete(name) ⇒ Object
Deletes a policy by name. This method is idempotent; if no policy exists with the given name, the method does nothing.
59 60 61 62 63 64 |
# File 'lib/aws/iam/policy_collection.rb', line 59 def delete(name) delete_policy(:policy_name => name) nil rescue Errors::NoSuchEntity => e nil end |
#each(opts = {}) {|name, policy| ... } ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/aws/iam/policy_collection.rb', line 118 def each opts = {}, &block opts = opts.dup names_only = opts.delete(:names_only) values_only = opts.delete(:values_only) super(client_opts(opts)) do |pn| case when names_only yield pn when values_only yield self[pn] when block.arity == 2 yield pn, self[pn] else yield [pn, self[pn]] end end end |
#has_key?(name) ⇒ Boolean Also known as: include?, key?, member?
Returns True if there is a policy with the given name.
102 103 104 105 106 107 |
# File 'lib/aws/iam/policy_collection.rb', line 102 def has_key? name get_policy(:policy_name => name) true rescue Errors::NoSuchEntity => e false end |
#keys ⇒ Enumerator<String> Also known as: names
Returns An enumerator for retrieving all the policy names that are currently associated with the resource.
82 83 84 |
# File 'lib/aws/iam/policy_collection.rb', line 82 def keys enumerator(:names_only => true) end |
#to_h ⇒ Hash
Returns The contents of the collection as a hash.
137 138 139 140 141 142 |
# File 'lib/aws/iam/policy_collection.rb', line 137 def to_h inject({}) do |hash, (name, policy)| hash[name] = policy hash end end |
#values ⇒ Enumerator<Policy>
Returns An enumerator for retrieving all the policy documents that are currently associated with the resource.
90 91 92 |
# File 'lib/aws/iam/policy_collection.rb', line 90 def values enumerator(:values_only => true) end |
#values_at(*names) ⇒ Array<Policy>
Retrieves multiple policy documents by name. This method makes one request to AWS IAM per argument.
75 76 77 |
# File 'lib/aws/iam/policy_collection.rb', line 75 def values_at(*names) names.map { |n| self[n] } end |