class Google::Cloud::Storage::Bucket::Cors::Rule
Represents a website CORS rule for a bucket. Accessed via {Bucket#cors}.
@see cloud.google.com/storage/docs/cross-origin Cross-Origin
Resource Sharing (CORS)
@attr [String] origin The [origin](tools.ietf.org/html/rfc6454)
or origins permitted for cross origin resource sharing with the bucket. Note: "*" is permitted in the list of origins, and means "any Origin".
@attr [String] methods The list of HTTP methods permitted in cross
origin resource sharing with the bucket. (GET, OPTIONS, POST, etc) Note: "*" is permitted in the list of methods, and means "any method".
@attr [String] headers The list of header field names to send in the
Access-Control-Allow-Headers header in the preflight response. Indicates the custom request headers that may be used in the actual request.
@attr [String] max_age
The value to send in the
Access-Control-Max-Age header in the preflight response. Indicates how many seconds the results of a preflight request can be cached in a preflight result cache. The default value is `1800` (30 minutes.)
@example Retrieving the bucket's CORS rules.
require "google/cloud/storage" storage = Google::Cloud::Storage.new bucket = storage.bucket "my-bucket" bucket.cors.size #=> 2 rule = bucket.cors.first rule.origin #=> ["http://example.org"] rule.methods #=> ["GET","POST","DELETE"] rule.headers #=> ["X-My-Custom-Header"] rule.max_age #=> 3600
Attributes
headers[RW]
max_age[RW]
methods[RW]
origin[RW]
Public Class Methods
from_gapi(gapi)
click to toggle source
@private
# File lib/google/cloud/storage/bucket/cors.rb, line 197 def self.from_gapi gapi new gapi.origin.dup, gapi.http_method.dup, \ headers: gapi.response_header.dup, max_age: gapi.max_age_seconds end
new(origin, methods, headers: nil, max_age: nil)
click to toggle source
@private
# File lib/google/cloud/storage/bucket/cors.rb, line 181 def initialize origin, methods, headers: nil, max_age: nil @origin = Array(origin) @methods = Array(methods) @headers = Array(headers) @max_age = (max_age || 1800) end
Public Instance Methods
freeze()
click to toggle source
@private
Calls superclass method
# File lib/google/cloud/storage/bucket/cors.rb, line 204 def freeze @origin.freeze @methods.freeze @headers.freeze super end
to_gapi()
click to toggle source
@private
# File lib/google/cloud/storage/bucket/cors.rb, line 189 def to_gapi Google::Apis::StorageV1::Bucket::CorsConfiguration.new( origin: Array(origin).dup, http_method: Array(methods).dup, response_header: Array(headers).dup, max_age_seconds: max_age ) end