Class: Aikido::Zen::RuntimeSettings::Endpoints

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/runtime_settings/endpoints.rb

Overview

Wraps the list of endpoint protection settings, providing an interface for checking the settings for any given route. If the route has no configured settings, that will return the singleton ProtectionSettings.none.

Examples:

endpoint = runtime_settings.endpoints[request.route]
block_request unless endpoint.allows?(request.ip)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Endpoints

Returns a new instance of Endpoints.



28
29
30
31
# File 'lib/aikido/zen/runtime_settings/endpoints.rb', line 28

def initialize(data = {})
  @endpoints = data
  @endpoints.default = RuntimeSettings::ProtectionSettings.none
end

Class Method Details

.from_json(data) ⇒ Aikido::Zen::RuntimeSettings::Endpoints

Parameters:

  • data (Array<Hash>)

Returns:



18
19
20
21
22
23
24
25
26
# File 'lib/aikido/zen/runtime_settings/endpoints.rb', line 18

def self.from_json(data)
  data = Array(data).map { |item|
    route = Route.new(verb: item["method"], path: item["route"])
    settings = RuntimeSettings::ProtectionSettings.from_json(item)
    [route, settings]
  }.to_h

  new(data)
end

Instance Method Details

#[](route) ⇒ Aikido::Zen::RuntimeSettings::ProtectionSettings



35
36
37
# File 'lib/aikido/zen/runtime_settings/endpoints.rb', line 35

def [](route)
  @endpoints[route]
end