You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::S3::CORSRule

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/s3/cors_rule.rb

Overview

Represents a single CORS rule for an S3 Bucket.

Examples:


rule = bucket.cors.first
rule.allowed_methods #=> ['GET', 'HEAD']
rule.allowed_origins #=> ['*']

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CORSRule

Returns a new instance of CORSRule

Parameters:

  • options (Hash) (defaults to: {})

    A hash of the rule details.

Options Hash (options):

  • :id (String)

    A unique identifier for the rule. The ID value can be up to 255 characters long. The IDs help you find a rule in the configuration.

  • :allowed_methods (required, Array<String>)

    A list of HTTP methods that you want to allow the origin to execute. Each rule must identify at least one method.

  • :allowed_origins (required, Array<String>)

    A list of origins you want to allow cross-domain requests from. This can contain at most one * wild character.

  • :allowed_headers (Array<String>)

    A list of headers allowed in a pre-flight OPTIONS request via the Access-Control-Request-Headers header. Each header name specified in the Access-Control-Request-Headers header must have a corresponding entry in the rule.

    Amazon S3 will send only the allowed headers in a response that were requested. This can contain at most one '*' wild character.

  • :max_age_seconds (Array<String>)

    The time in seconds that your browser is to cache the pre-flight response for the specified resource.

  • :expose_headers (Array<String>)

    One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object).



61
62
63
64
65
66
67
68
# File 'lib/aws/s3/cors_rule.rb', line 61

def initialize options = {}
  @id = options[:id]
  @allowed_methods = options[:allowed_methods] || []
  @allowed_origins = options[:allowed_origins] || []
  @allowed_headers = options[:allowed_headers] || []
  @max_age_seconds = options[:max_age_seconds]
  @expose_headers = options[:expose_headers] || []
end

Instance Attribute Details

#allowed_headersArray<String> (readonly)

Returns A list of headers allowed in the pre-flight OPTIONS request.

Returns:

  • (Array<String>)

    A list of headers allowed in the pre-flight OPTIONS request.



84
85
86
# File 'lib/aws/s3/cors_rule.rb', line 84

def allowed_headers
  @allowed_headers
end

#allowed_methodsArray<String> (readonly)

Returns A list of HTTP methods (GET, POST, etc) this role authorizes.

Returns:

  • (Array<String>)

    A list of HTTP methods (GET, POST, etc) this role authorizes.



76
77
78
# File 'lib/aws/s3/cors_rule.rb', line 76

def allowed_methods
  @allowed_methods
end

#allowed_originsArray<String> (readonly)

Returns The list of origins allowed to make cross-domain requests to the bucket.

Returns:

  • (Array<String>)

    The list of origins allowed to make cross-domain requests to the bucket.



80
81
82
# File 'lib/aws/s3/cors_rule.rb', line 80

def allowed_origins
  @allowed_origins
end

#expose_headersArray<String> (readonly)

Returns The headers that may be accessed cross-domain.

Returns:

  • (Array<String>)

    The headers that may be accessed cross-domain.



91
92
93
# File 'lib/aws/s3/cors_rule.rb', line 91

def expose_headers
  @expose_headers
end

#idString? (readonly)

Returns A user supplied unique identifier for this role. Set this when you set or add roles via AWS::S3::CORSRuleCollection.

Returns:

  • (String, nil)

    A user supplied unique identifier for this role. Set this when you set or add roles via AWS::S3::CORSRuleCollection.



72
73
74
# File 'lib/aws/s3/cors_rule.rb', line 72

def id
  @id
end

#max_age_secondsInteger? (readonly)

Returns The time in seconds the browser may cache the pre-flight response.

Returns:

  • (Integer, nil)

    The time in seconds the browser may cache the pre-flight response.



88
89
90
# File 'lib/aws/s3/cors_rule.rb', line 88

def max_age_seconds
  @max_age_seconds
end

Instance Method Details

#to_hHash

Returns:

  • (Hash)


94
95
96
97
98
99
100
101
102
103
# File 'lib/aws/s3/cors_rule.rb', line 94

def to_h
  h = {}
  h[:id] = id if id
  h[:allowed_methods] = allowed_methods
  h[:allowed_origins] = allowed_origins
  h[:allowed_headers] = allowed_headers unless allowed_headers.empty?
  h[:max_age_seconds] = max_age_seconds if max_age_seconds
  h[:expose_headers] = expose_headers unless expose_headers.empty?
  h
end