Class: DeepHealthCheck::BasicAuthHealthCheck

Inherits:
Rack::Auth::Basic
  • Object
show all
Defined in:
lib/deep_health_check/basic_auth_health_check.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/deep_health_check/basic_auth_health_check.rb', line 5

def call(env)
  auth = ::Rack::Auth::Basic::Request.new(env)
  if env['PATH_INFO'].match(/^\/((db|tcp|http)_)?(dependencies_)?health$/)
    return unauthorized unless auth.provided?
    return bad_request unless auth.basic?

    if valid?(auth)
      env['REMOTE_USER'] = auth.username
      health_check = HealthCheckBuilder.build env['PATH_INFO']
      return (health_check&.call || @app.call(env))
    end

    unauthorized
  else
    @app.call(env)
  end
end