Class: Tassadar::Server::Whitelist

Inherits:
Object
  • Object
show all
Defined in:
lib/tassadar/server/whitelist.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, addresses) ⇒ Whitelist

Returns a new instance of Whitelist.



4
5
6
7
# File 'lib/tassadar/server/whitelist.rb', line 4

def initialize(app, addresses)
  @app = app
  @whitelist = addresses
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/tassadar/server/whitelist.rb', line 9

def call(env)
  if white_listed?(env)
    @app.call(env)
  else
    [ 403,
      { 'Content-Type' => 'text/plain; charset=utf-8' },
      Array( "IP #{remote_ip(env)} is not whitelisted" )
    ]
  end
end

#remote_ip(env) ⇒ Object



20
21
22
# File 'lib/tassadar/server/whitelist.rb', line 20

def remote_ip(env)
  Rack::Request.new(env).ip
end

#white_listed?(env) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/tassadar/server/whitelist.rb', line 24

def white_listed?(env)
  @whitelist.include? remote_ip(env)
end