Sha256: f049d9568e4f0b00574ea0f01b3102e076994148ca50de35d5a6685f6b8c2491

Contents?: true

Size: 739 Bytes

Versions: 3

Compression:

Stored size: 739 Bytes

Contents

require_relative 'guard'

# Public: Balrog routes middleware that redirects the user to a security
# gate unless the session includes { 'balrog' => 'authenticated' }.
# 
# In order to protect SideKiq Web you would do something like this: 
#
# require 'sidekiq/web'
#
# Sidekiq::Web.disable(:sessions)
# Sidekiq::Web.use Balrog::RoutesMiddleware
#
# mount Sidekiq::Web => '/sidekiq'

class Balrog::RoutesMiddleware
  include Balrog::Guard

  def initialize(app)
    @app = app
  end

  def call(env)
    unless authenticated?(env['rack.session']['balrog'])
      html = ApplicationController.renderer.render 'balrog/gate', layout: 'balrog'
      return [200, {"Content-Type" => "text/html"}, [html]]  
    end
    @app.call(env)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
balrog-2.0.1 lib/balrog/routes_middleware.rb
balrog-2.0.0 lib/balrog/routes_middleware.rb
balrog-1.1.0 lib/balrog/routes_middleware.rb