Class: Itsi::Server::Config::AllowList

Inherits:
Middleware
  • Object
show all
Includes:
Itsi::Server::CidrToRegex
Defined in:
lib/itsi/server/config/middleware/allow_list.rb

Instance Method Summary collapse

Methods included from Itsi::Server::CidrToRegex

#build_regex_from_parts, #cidr_to_regex, #part_to_range_regex, #range_to_regex

Methods inherited from Middleware

#build!

Methods included from ConfigHelpers

included, load_and_register, #normalize_keys!

Constructor Details

#initialize(location, params = {}) ⇒ AllowList

Returns a new instance of AllowList.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/itsi/server/config/middleware/allow_list.rb', line 27

def initialize(location, params={})
  params[:allowed_patterns] = Array(params[:allowed_patterns]).map do |pattern|
    if pattern.is_a?(Regexp)
      pattern.source
    elsif pattern =~ /\A\d{1,3}(?:\.\d{1,3}){3}\/\d{1,2}\z/
      cidr_to_regex(pattern).source
    else
      pattern
    end
  end
  super
end