Class: Gitlab::Middleware::Go

Inherits:
Object
  • Object
show all
Includes:
ActionController::HttpAuthentication::Basic, ActionView::Helpers::TagHelper
Defined in:
lib/gitlab/middleware/go.rb

Constant Summary collapse

PROJECT_PATH_REGEX =
%r{\A(#{Gitlab::PathRegex.full_namespace_route_regex}/#{Gitlab::PathRegex.project_route_regex})/}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Go

Returns a new instance of Go.


13
14
15
# File 'lib/gitlab/middleware/go.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/middleware/go.rb', line 17

def call(env)
  request = ActionDispatch::Request.new(env)

  render_go_doc(request) || @app.call(env)
rescue Gitlab::Auth::IpBlacklisted
  Gitlab::AuthLogger.error(
    message: 'Rack_Attack',
    status: 403,
    env: :blocklist,
    remote_ip: request.ip,
    request_method: request.request_method,
    path: request.fullpath
  )
  Rack::Response.new('', 403).finish
rescue Gitlab::Auth::MissingPersonalAccessTokenError
  Rack::Response.new('', 401).finish
end