Class: OCI::Apigateway::Models::CorsPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/oci/apigateway/models/cors_policy.rb

Overview

Enable CORS (Cross-Origin-Resource-Sharing) request handling.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ CorsPolicy

Initializes the object

Parameters:

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

    Model attributes in the form of hash

Options Hash (attributes):

  • :allowed_origins (Array<String>)

    The value to assign to the #allowed_origins property

  • :allowed_methods (Array<String>)

    The value to assign to the #allowed_methods property

  • :allowed_headers (Array<String>)

    The value to assign to the #allowed_headers property

  • :exposed_headers (Array<String>)

    The value to assign to the #exposed_headers property

  • :is_allow_credentials_enabled (BOOLEAN)

    The value to assign to the #is_allow_credentials_enabled property

  • :max_age_in_seconds (Integer)

    The value to assign to the #max_age_in_seconds property



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/oci/apigateway/models/cors_policy.rb', line 88

def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

  self.allowed_origins = attributes[:'allowedOrigins'] if attributes[:'allowedOrigins']

  raise 'You cannot provide both :allowedOrigins and :allowed_origins' if attributes.key?(:'allowedOrigins') && attributes.key?(:'allowed_origins')

  self.allowed_origins = attributes[:'allowed_origins'] if attributes[:'allowed_origins']

  self.allowed_methods = attributes[:'allowedMethods'] if attributes[:'allowedMethods']

  raise 'You cannot provide both :allowedMethods and :allowed_methods' if attributes.key?(:'allowedMethods') && attributes.key?(:'allowed_methods')

  self.allowed_methods = attributes[:'allowed_methods'] if attributes[:'allowed_methods']

  self.allowed_headers = attributes[:'allowedHeaders'] if attributes[:'allowedHeaders']

  raise 'You cannot provide both :allowedHeaders and :allowed_headers' if attributes.key?(:'allowedHeaders') && attributes.key?(:'allowed_headers')

  self.allowed_headers = attributes[:'allowed_headers'] if attributes[:'allowed_headers']

  self.exposed_headers = attributes[:'exposedHeaders'] if attributes[:'exposedHeaders']

  raise 'You cannot provide both :exposedHeaders and :exposed_headers' if attributes.key?(:'exposedHeaders') && attributes.key?(:'exposed_headers')

  self.exposed_headers = attributes[:'exposed_headers'] if attributes[:'exposed_headers']

  self.is_allow_credentials_enabled = attributes[:'isAllowCredentialsEnabled'] unless attributes[:'isAllowCredentialsEnabled'].nil?
  self.is_allow_credentials_enabled = false if is_allow_credentials_enabled.nil? && !attributes.key?(:'isAllowCredentialsEnabled') # rubocop:disable Style/StringLiterals

  raise 'You cannot provide both :isAllowCredentialsEnabled and :is_allow_credentials_enabled' if attributes.key?(:'isAllowCredentialsEnabled') && attributes.key?(:'is_allow_credentials_enabled')

  self.is_allow_credentials_enabled = attributes[:'is_allow_credentials_enabled'] unless attributes[:'is_allow_credentials_enabled'].nil?
  self.is_allow_credentials_enabled = false if is_allow_credentials_enabled.nil? && !attributes.key?(:'isAllowCredentialsEnabled') && !attributes.key?(:'is_allow_credentials_enabled') # rubocop:disable Style/StringLiterals

  self.max_age_in_seconds = attributes[:'maxAgeInSeconds'] if attributes[:'maxAgeInSeconds']

  raise 'You cannot provide both :maxAgeInSeconds and :max_age_in_seconds' if attributes.key?(:'maxAgeInSeconds') && attributes.key?(:'max_age_in_seconds')

  self.max_age_in_seconds = attributes[:'max_age_in_seconds'] if attributes[:'max_age_in_seconds']
end

Instance Attribute Details

#allowed_headersArray<String>

The list of headers that will be allowed from the client via the Access-Control-Allow-Headers header. '*' will allow all headers.

Returns:

  • (Array<String>)


29
30
31
# File 'lib/oci/apigateway/models/cors_policy.rb', line 29

def allowed_headers
  @allowed_headers
end

#allowed_methodsArray<String>

The list of allowed HTTP methods that will be returned for the preflight OPTIONS request in the Access-Control-Allow-Methods header. '*' will allow all methods.

Returns:

  • (Array<String>)


23
24
25
# File 'lib/oci/apigateway/models/cors_policy.rb', line 23

def allowed_methods
  @allowed_methods
end

#allowed_originsArray<String>

[Required] The list of allowed origins that the CORS handler will use to respond to CORS requests. The gateway will send the Access-Control-Allow-Origin header with the best origin match for the circumstances. '*' will match any origins, and 'null' will match queries from 'file:' origins. All other origins must be qualified with the scheme, full hostname, and port if necessary.

Returns:

  • (Array<String>)


17
18
19
# File 'lib/oci/apigateway/models/cors_policy.rb', line 17

def allowed_origins
  @allowed_origins
end

#exposed_headersArray<String>

The list of headers that the client will be allowed to see from the response as indicated by the Access-Control-Expose-Headers header. '*' will expose all headers.

Returns:

  • (Array<String>)


35
36
37
# File 'lib/oci/apigateway/models/cors_policy.rb', line 35

def exposed_headers
  @exposed_headers
end

#is_allow_credentials_enabledBOOLEAN

Whether to send the Access-Control-Allow-Credentials header to allow CORS requests with cookies.

Returns:

  • (BOOLEAN)


40
41
42
# File 'lib/oci/apigateway/models/cors_policy.rb', line 40

def is_allow_credentials_enabled
  @is_allow_credentials_enabled
end

#max_age_in_secondsInteger

The time in seconds for the client to cache preflight responses. This is sent as the Access-Control-Max-Age if greater than 0.

Returns:

  • (Integer)


46
47
48
# File 'lib/oci/apigateway/models/cors_policy.rb', line 46

def max_age_in_seconds
  @max_age_in_seconds
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/oci/apigateway/models/cors_policy.rb', line 49

def self.attribute_map
  {
    # rubocop:disable Style/SymbolLiteral
    'allowed_origins': :'allowedOrigins',
    'allowed_methods': :'allowedMethods',
    'allowed_headers': :'allowedHeaders',
    'exposed_headers': :'exposedHeaders',
    'is_allow_credentials_enabled': :'isAllowCredentialsEnabled',
    'max_age_in_seconds': :'maxAgeInSeconds'
    # rubocop:enable Style/SymbolLiteral
  }
end

.swagger_typesObject

Attribute type mapping.



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/oci/apigateway/models/cors_policy.rb', line 63

def self.swagger_types
  {
    # rubocop:disable Style/SymbolLiteral
    'allowed_origins': :'Array<String>',
    'allowed_methods': :'Array<String>',
    'allowed_headers': :'Array<String>',
    'exposed_headers': :'Array<String>',
    'is_allow_credentials_enabled': :'BOOLEAN',
    'max_age_in_seconds': :'Integer'
    # rubocop:enable Style/SymbolLiteral
  }
end

Instance Method Details

#==(other) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • other (Object)

    the other object to be compared



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/oci/apigateway/models/cors_policy.rb', line 140

def ==(other)
  return true if equal?(other)

  self.class == other.class &&
    allowed_origins == other.allowed_origins &&
    allowed_methods == other.allowed_methods &&
    allowed_headers == other.allowed_headers &&
    exposed_headers == other.exposed_headers &&
    is_allow_credentials_enabled == other.is_allow_credentials_enabled &&
    max_age_in_seconds == other.max_age_in_seconds
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/oci/apigateway/models/cors_policy.rb', line 175

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)

  self.class.swagger_types.each_pair do |key, type|
    if type =~ /^Array<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        public_method("#{key}=").call(
          attributes[self.class.attribute_map[key]]
            .map { |v| OCI::Internal::Util.convert_to_type(Regexp.last_match(1), v) }
        )
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      public_method("#{key}=").call(
        OCI::Internal::Util.convert_to_type(type, attributes[self.class.attribute_map[key]])
      )
    end
    # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(other) ⇒ Boolean

Parameters:

  • other (Object)

    the other object to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


155
156
157
# File 'lib/oci/apigateway/models/cors_policy.rb', line 155

def eql?(other)
  self == other
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



164
165
166
# File 'lib/oci/apigateway/models/cors_policy.rb', line 164

def hash
  [allowed_origins, allowed_methods, allowed_headers, exposed_headers, is_allow_credentials_enabled, max_age_in_seconds].hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



208
209
210
211
212
213
214
215
216
217
# File 'lib/oci/apigateway/models/cors_policy.rb', line 208

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = public_method(attr).call
    next if value.nil? && !instance_variable_defined?("@#{attr}")

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



202
203
204
# File 'lib/oci/apigateway/models/cors_policy.rb', line 202

def to_s
  to_hash.to_s
end