Class | AWS::S3::CORSRuleCollection |
In: |
lib/aws/s3/cors_rule_collection.rb
|
Parent: | Object |
Manages the CORS rules for a single bucket.
## Getting Rules
To get the CORS rules for a bucket, use the {Bucket#cors} method. This returns a CORSRuleCollection for the bucket. The collection is enumerable.
# enumerating all rules for a buck bucket.cors.each do |rule| # rule is a CORSRule object end
## Setting Rules
You can set the rules for a bucket (replacing all existing rules) using the {set} method.
# accepts a list of one or more rules bucket.rules.set(rule1, rule2) # rules can be an array of rules bucket.rules.set(rules) # passing an empty list or array removes all rules bucket.rules.set([]) bucket.rules.clear # does the same thing
Each rule can be a Hash, a {CORSRule} or another {CORSRuleCollection}. See {Client#put_bucket_cors} for a list of keys for a rule hash.
## Adding Rules
Adding rules is the same as setting rules. Rules you add will be appended to the end of the existing list of rules.
# add one or more rules bucket.rules.add(rules)
## Deleting Rules
To remove a rule, use the {delete_if} method.
# delete rules that allow access from any domain bucket.cors.delete_if{|rule| rule.allowed_origins.include?('*')
bucket | [R] | @return [Bucket] |
Add one or more CORS rules to this bucket.
# adding a single rule as a hash bucket.cors.add( :allowed_methods => %w(GET HEAD), :allowed_origins => %w(*), :max_age_seconds => 3600)
You can add multiple rules in a single call:
# each rule may be a hash, CORSRule or a CORSRuleCollection, bucket.cors.add(rules) # alternatively you can pass a list of rules bucket.cors.add(rule1, rule2, ...)
Removes all CORS rules attached to this bucket.
@example
bucket.cors.count #=> 3 bucket.cors.clear bucket.cors.count #=> 0
@return [nil]
Deletes every rule for which the block evaluates to `true`.
@example Remove all rules that are open to the ‘world‘
bucket.cors.delete_if{|rule| rule.allowed_origins.include?('*') }
@yield [rule] @yieldparam [CORSRule] rule @yieldreturn [Boolean] Return `true` for each rule you want to delete. @return (see set)
Replaces the CORS rules attached to this bucket. You can pass one or more rules as an array or a list.
# replace all exisitng rules with a single rule bucket.cors.set( :allowed_methods => %w(GET), :allowed_origins => %w(http://*.mydomain.com), :max_age_seconds => 3600)
If you pass an empty array, all of the rules will be removed from the bucket.
# these two lines are equivilent bucket.cors.clear bucket.cors.set([])
@param [Hash,CORSRule,CORSRuleCollection] rules A list or array
of one or more rules to set. Each rule may be a Hash, a CORSRule or a CORSRuleCollection.
@return [nil]