Class: Fastly::RateLimiter
- Inherits:
-
Object
- Object
- Fastly::RateLimiter
- Defined in:
- lib/fastly/models/rate_limiter.rb
Defined Under Namespace
Classes: EnumAttributeValidator
Instance Attribute Summary collapse
-
#action ⇒ Object
The action to take when a rate limiter violation is detected.
-
#client_key ⇒ Object
Array of VCL variables used to generate a counter key to identify a client.
-
#feature_revision ⇒ Object
Revision number of the rate limiting feature implementation.
-
#http_methods ⇒ Object
Array of HTTP methods to apply rate limiting to.
-
#logger_type ⇒ Object
Name of the type of logging endpoint to be used when action is ‘log_only`.
-
#name ⇒ Object
A human readable name for the rate limiting rule.
-
#penalty_box_duration ⇒ Object
Length of time in minutes that the rate limiter is in effect after the initial violation is detected.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_object_name ⇒ Object
Name of existing response object.
-
#rps_limit ⇒ Object
Upper limit of requests per second allowed by the rate limiter.
-
#uri_dictionary_name ⇒ Object
The name of an Edge Dictionary containing URIs as keys.
-
#window_size ⇒ Object
Number of seconds during which the RPS limit must be exceeded in order to trigger a violation.
Class Method Summary collapse
-
.acceptable_attributes ⇒ Object
Returns all the JSON keys this model knows about.
-
.attribute_map ⇒ Object
Attribute mapping from ruby-style variable name to JSON key.
-
.build_from_hash(attributes) ⇒ Object
Builds the object from hash.
-
.fastly_nullable ⇒ Object
List of attributes with nullable: true.
-
.fastly_types ⇒ Object
Attribute type mapping.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Checks equality by comparing each attribute.
-
#_deserialize(type, value) ⇒ Object
Deserializes the data based on type.
-
#_to_hash(value) ⇒ Hash
Outputs non-array value in the form of hash For object, use to_hash.
-
#build_from_hash(attributes) ⇒ Object
Builds the object from hash.
- #eql?(o) ⇒ Boolean
-
#hash ⇒ Integer
Calculates hash code according to all attributes.
-
#initialize(attributes = {}) ⇒ RateLimiter
constructor
Initializes the object.
-
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons.
-
#to_body ⇒ Hash
to_body is an alias to to_hash (backward compatibility).
-
#to_hash ⇒ Hash
Returns the object in the form of hash.
-
#to_s ⇒ String
Returns the string representation of the object.
-
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid.
Constructor Details
#initialize(attributes = {}) ⇒ RateLimiter
Initializes the object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/fastly/models/rate_limiter.rb', line 125 def initialize(attributes = {}) if (!attributes.is_a?(Hash)) fail ArgumentError, "The input argument (attributes) must be a hash in `Fastly::RateLimiter` initialize method" end # check to see if the attribute exists and convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| if (!self.class.attribute_map.key?(k.to_sym)) fail ArgumentError, "`#{k}` is not a valid attribute in `Fastly::RateLimiter`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect end h[k.to_sym] = v } if attributes.key?(:'name') self.name = attributes[:'name'] end if attributes.key?(:'uri_dictionary_name') self.uri_dictionary_name = attributes[:'uri_dictionary_name'] end if attributes.key?(:'http_methods') if (value = attributes[:'http_methods']).is_a?(Array) self.http_methods = value end end if attributes.key?(:'rps_limit') self.rps_limit = attributes[:'rps_limit'] end if attributes.key?(:'window_size') self.window_size = attributes[:'window_size'] end if attributes.key?(:'client_key') if (value = attributes[:'client_key']).is_a?(Array) self.client_key = value end end if attributes.key?(:'penalty_box_duration') self.penalty_box_duration = attributes[:'penalty_box_duration'] end if attributes.key?(:'action') self.action = attributes[:'action'] end if attributes.key?(:'response') self.response = attributes[:'response'] end if attributes.key?(:'response_object_name') self.response_object_name = attributes[:'response_object_name'] end if attributes.key?(:'logger_type') self.logger_type = attributes[:'logger_type'] end if attributes.key?(:'feature_revision') self.feature_revision = attributes[:'feature_revision'] end end |
Instance Attribute Details
#action ⇒ Object
The action to take when a rate limiter violation is detected.
38 39 40 |
# File 'lib/fastly/models/rate_limiter.rb', line 38 def action @action end |
#client_key ⇒ Object
Array of VCL variables used to generate a counter key to identify a client. Example variables include ‘req.http.Fastly-Client-IP`, `req.http.User-Agent`, or a custom header like `req.http.API-Key`.
32 33 34 |
# File 'lib/fastly/models/rate_limiter.rb', line 32 def client_key @client_key end |
#feature_revision ⇒ Object
Revision number of the rate limiting feature implementation. Defaults to the most recent revision.
49 50 51 |
# File 'lib/fastly/models/rate_limiter.rb', line 49 def feature_revision @feature_revision end |
#http_methods ⇒ Object
Array of HTTP methods to apply rate limiting to.
23 24 25 |
# File 'lib/fastly/models/rate_limiter.rb', line 23 def http_methods @http_methods end |
#logger_type ⇒ Object
Name of the type of logging endpoint to be used when action is ‘log_only`. The logging endpoint type is used to determine the appropriate log format to use when emitting log entries.
46 47 48 |
# File 'lib/fastly/models/rate_limiter.rb', line 46 def logger_type @logger_type end |
#name ⇒ Object
A human readable name for the rate limiting rule.
17 18 19 |
# File 'lib/fastly/models/rate_limiter.rb', line 17 def name @name end |
#penalty_box_duration ⇒ Object
Length of time in minutes that the rate limiter is in effect after the initial violation is detected.
35 36 37 |
# File 'lib/fastly/models/rate_limiter.rb', line 35 def penalty_box_duration @penalty_box_duration end |
#response ⇒ Object
Returns the value of attribute response.
40 41 42 |
# File 'lib/fastly/models/rate_limiter.rb', line 40 def response @response end |
#response_object_name ⇒ Object
Name of existing response object. Required if ‘action` is `response_object`. Note that the rate limiter response is only updated to reflect the response object content when saving the rate limiter configuration.
43 44 45 |
# File 'lib/fastly/models/rate_limiter.rb', line 43 def response_object_name @response_object_name end |
#rps_limit ⇒ Object
Upper limit of requests per second allowed by the rate limiter.
26 27 28 |
# File 'lib/fastly/models/rate_limiter.rb', line 26 def rps_limit @rps_limit end |
#uri_dictionary_name ⇒ Object
The name of an Edge Dictionary containing URIs as keys. If not defined or ‘null`, all origin URIs will be rate limited.
20 21 22 |
# File 'lib/fastly/models/rate_limiter.rb', line 20 def uri_dictionary_name @uri_dictionary_name end |
#window_size ⇒ Object
Number of seconds during which the RPS limit must be exceeded in order to trigger a violation.
29 30 31 |
# File 'lib/fastly/models/rate_limiter.rb', line 29 def window_size @window_size end |
Class Method Details
.acceptable_attributes ⇒ Object
Returns all the JSON keys this model knows about
92 93 94 |
# File 'lib/fastly/models/rate_limiter.rb', line 92 def self.acceptable_attributes attribute_map.values end |
.attribute_map ⇒ Object
Attribute mapping from ruby-style variable name to JSON key.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fastly/models/rate_limiter.rb', line 74 def self.attribute_map { :'name' => :'name', :'uri_dictionary_name' => :'uri_dictionary_name', :'http_methods' => :'http_methods', :'rps_limit' => :'rps_limit', :'window_size' => :'window_size', :'client_key' => :'client_key', :'penalty_box_duration' => :'penalty_box_duration', :'action' => :'action', :'response' => :'response', :'response_object_name' => :'response_object_name', :'logger_type' => :'logger_type', :'feature_revision' => :'feature_revision' } end |
.build_from_hash(attributes) ⇒ Object
Builds the object from hash
419 420 421 |
# File 'lib/fastly/models/rate_limiter.rb', line 419 def self.build_from_hash(attributes) new.build_from_hash(attributes) end |
.fastly_nullable ⇒ Object
List of attributes with nullable: true
115 116 117 118 119 120 121 |
# File 'lib/fastly/models/rate_limiter.rb', line 115 def self.fastly_nullable Set.new([ :'uri_dictionary_name', :'response', :'response_object_name', ]) end |
.fastly_types ⇒ Object
Attribute type mapping.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fastly/models/rate_limiter.rb', line 97 def self.fastly_types { :'name' => :'String', :'uri_dictionary_name' => :'String', :'http_methods' => :'Array<String>', :'rps_limit' => :'Integer', :'window_size' => :'Integer', :'client_key' => :'Array<String>', :'penalty_box_duration' => :'Integer', :'action' => :'String', :'response' => :'RateLimiterResponse1', :'response_object_name' => :'String', :'logger_type' => :'String', :'feature_revision' => :'Integer' } end |
Instance Method Details
#==(o) ⇒ Object
Checks equality by comparing each attribute.
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/fastly/models/rate_limiter.rb', line 387 def ==(o) return true if self.equal?(o) self.class == o.class && name == o.name && uri_dictionary_name == o.uri_dictionary_name && http_methods == o.http_methods && rps_limit == o.rps_limit && window_size == o.window_size && client_key == o.client_key && penalty_box_duration == o.penalty_box_duration && action == o.action && response == o.response && response_object_name == o.response_object_name && logger_type == o.logger_type && feature_revision == o.feature_revision end |
#_deserialize(type, value) ⇒ Object
Deserializes the data based on type
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/fastly/models/rate_limiter.rb', line 449 def _deserialize(type, value) case type.to_sym when :Time Time.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f when :Boolean if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else false end when :Object # generic object (usually a Hash), return directly value when /\AArray<(?<inner_type>.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/ k_type = Regexp.last_match[:k_type] v_type = Regexp.last_match[:v_type] {}.tap do |hash| value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model # models (e.g. Pet) or oneOf klass = Fastly.const_get(type) klass.respond_to?(:fastly_one_of) ? klass.build(value) : klass.build_from_hash(value) end end |
#_to_hash(value) ⇒ Hash
Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value
520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/fastly/models/rate_limiter.rb', line 520 def _to_hash(value) if value.is_a?(Array) value.compact.map { |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end |
#build_from_hash(attributes) ⇒ Object
Builds the object from hash
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/fastly/models/rate_limiter.rb', line 426 def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) self.class.fastly_types.each_pair do |key, type| if attributes[self.class.attribute_map[key]].nil? && self.class.fastly_nullable.include?(key) self.send("#{key}=", nil) elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not if attributes[self.class.attribute_map[key]].is_a?(Array) self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) end elsif !attributes[self.class.attribute_map[key]].nil? self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) end end self end |
#eql?(o) ⇒ Boolean
406 407 408 |
# File 'lib/fastly/models/rate_limiter.rb', line 406 def eql?(o) self == o end |
#hash ⇒ Integer
Calculates hash code according to all attributes.
412 413 414 |
# File 'lib/fastly/models/rate_limiter.rb', line 412 def hash [name, uri_dictionary_name, http_methods, rps_limit, window_size, client_key, penalty_box_duration, action, response, response_object_name, logger_type, feature_revision].hash end |
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons. Usually used together with valid?
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/fastly/models/rate_limiter.rb', line 193 def list_invalid_properties invalid_properties = Array.new if !@name.nil? && @name.to_s.length > 255 invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 255.') end if !@name.nil? && @name.to_s.length < 1 invalid_properties.push('invalid value for "name", the character length must be great than or equal to 1.') end if !@uri_dictionary_name.nil? && @uri_dictionary_name.to_s.length > 255 invalid_properties.push('invalid value for "uri_dictionary_name", the character length must be smaller than or equal to 255.') end if !@uri_dictionary_name.nil? && @uri_dictionary_name.to_s.length < 1 invalid_properties.push('invalid value for "uri_dictionary_name", the character length must be great than or equal to 1.') end if !@http_methods.nil? && @http_methods.length < 1 invalid_properties.push('invalid value for "http_methods", number of items must be greater than or equal to 1.') end if !@rps_limit.nil? && @rps_limit > 10000 invalid_properties.push('invalid value for "rps_limit", must be smaller than or equal to 10000.') end if !@rps_limit.nil? && @rps_limit < 10 invalid_properties.push('invalid value for "rps_limit", must be greater than or equal to 10.') end if !@client_key.nil? && @client_key.length < 1 invalid_properties.push('invalid value for "client_key", number of items must be greater than or equal to 1.') end if !@penalty_box_duration.nil? && @penalty_box_duration > 60 invalid_properties.push('invalid value for "penalty_box_duration", must be smaller than or equal to 60.') end if !@penalty_box_duration.nil? && @penalty_box_duration < 1 invalid_properties.push('invalid value for "penalty_box_duration", must be greater than or equal to 1.') end if !@action.nil? && @action.to_s.length < 1 invalid_properties.push('invalid value for "action", the character length must be great than or equal to 1.') end if !@response_object_name.nil? && @response_object_name.to_s.length > 255 invalid_properties.push('invalid value for "response_object_name", the character length must be smaller than or equal to 255.') end if !@response_object_name.nil? && @response_object_name.to_s.length < 1 invalid_properties.push('invalid value for "response_object_name", the character length must be great than or equal to 1.') end invalid_properties end |
#to_body ⇒ Hash
to_body is an alias to to_hash (backward compatibility)
496 497 498 |
# File 'lib/fastly/models/rate_limiter.rb', line 496 def to_body to_hash end |
#to_hash ⇒ Hash
Returns the object in the form of hash
502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/fastly/models/rate_limiter.rb', line 502 def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? is_nullable = self.class.fastly_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end hash[param] = _to_hash(value) end hash end |
#to_s ⇒ String
Returns the string representation of the object
490 491 492 |
# File 'lib/fastly/models/rate_limiter.rb', line 490 def to_s to_hash.to_s end |
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/fastly/models/rate_limiter.rb', line 252 def valid? return false if !@name.nil? && @name.to_s.length > 255 return false if !@name.nil? && @name.to_s.length < 1 return false if !@uri_dictionary_name.nil? && @uri_dictionary_name.to_s.length > 255 return false if !@uri_dictionary_name.nil? && @uri_dictionary_name.to_s.length < 1 return false if !@http_methods.nil? && @http_methods.length < 1 return false if !@rps_limit.nil? && @rps_limit > 10000 return false if !@rps_limit.nil? && @rps_limit < 10 window_size_validator = EnumAttributeValidator.new('Integer', [1, 10, 60]) return false unless window_size_validator.valid?(@window_size) return false if !@client_key.nil? && @client_key.length < 1 return false if !@penalty_box_duration.nil? && @penalty_box_duration > 60 return false if !@penalty_box_duration.nil? && @penalty_box_duration < 1 action_validator = EnumAttributeValidator.new('String', ["response", "response_object", "log_only"]) return false unless action_validator.valid?(@action) return false if !@action.nil? && @action.to_s.length < 1 return false if !@response_object_name.nil? && @response_object_name.to_s.length > 255 return false if !@response_object_name.nil? && @response_object_name.to_s.length < 1 logger_type_validator = EnumAttributeValidator.new('String', ["azureblob", "bigquery", "cloudfiles", "datadog", "digitalocean", "elasticsearch", "ftp", "gcs", "googleanalytics", "heroku", "honeycomb", "http", "https", "kafka", "kinesis", "logentries", "loggly", "logshuttle", "newrelic", "openstack", "papertrail", "pubsub", "s3", "scalyr", "sftp", "splunk", "stackdriver", "sumologic", "syslog"]) return false unless logger_type_validator.valid?(@logger_type) true end |