Module: Roda::RodaPlugins::IpShield

Defined in:
lib/ip_shield.rb

Defined Under Namespace

Modules: RequestMethods Classes: InvalidIP, UnauthorisedIP

Class Method Summary collapse

Class Method Details

.configure(app, *ip_addrs) ⇒ Object

Note:

Auto configure ip_shield plugin. Set IPs when the plugin is loaded. The provided IP will be authorize automatically as long as they as are valid IPv4 or IPv6. There are two ways to set IP.

  1. As a string. Ex; ‘0.0.0.0’

  2. As an array of low and high boundaries. Ex; [‘0.0.0.0’, ‘0.0.0.7’]

boundaries should be an array with two string elements - IP. The first element must be low IP and the second should be high.

Examples:

plugin :ip_shield, '0.0.0.0', ['128.0.0.0', '128.0.0.5']

Parameters:

  • app (Object)

    App

  • ip_addrs (Array)

    list of aip addresses



32
33
34
35
# File 'lib/ip_shield.rb', line 32

def self.configure(app, *ip_addrs)
  ip_addrs = app.opts[:ip_shield] || ip_addrs
  ip_addrs.each { |ip_addr| IPValidator.instance.add_ip(ip_addr) } unless ip_addrs.nil? || ip_addrs.empty?
end