<commit_before>module Rack::Authorize
  class Authorizer
    def initialize(app, opts = {}, &block)
      @app = app
      @no_auth_routes = opts[:excludes] || {}
      @auth_definition = opts[:auth_definition] || "scopes"
      @block = block
    end

    def call(env)
      #puts env
      if authorizable_route?(env)
        method = env["REQUEST_METHOD"]
        path = env["PATH_INFO"]
        # The JWT payload is saved in rack.jwt.session the scopes key is scopes
        #puts "----------------------------"
        #puts env
        #puts "----------------------------"
        scopes = Oj.load(env.fetch("rack.jwt.session", {})[@auth_definition])
        return [403, {}, ["Access Forbidden"]] unless @block.call(method, path, scopes)
      end
      @app.call(env)
    end

    private

    def authorizable_route?(env)
      if @no_auth_routes.length > 0
        !@no_auth_routes.find { |route| route =~ /#{env['PATH_INFO']}/ }
      end
    end
  end
end<commit_msg>debugg<commit_after>module Rack::Authorize
  class Authorizer
    def initialize(app, opts = {}, &block)
      @app = app
      @no_auth_routes = opts[:excludes] || {}
      puts @no_auth_routes
      @auth_definition = opts[:auth_definition] || "scopes"
      @block = block
    end

    def call(env)
      #puts env
      if authorizable_route?(env)
        method = env["REQUEST_METHOD"]
        path = env["PATH_INFO"]
        # The JWT payload is saved in rack.jwt.session the scopes key is scopes
        #puts "----------------------------"
        #puts env
        #puts "----------------------------"
        scopes = Oj.load(env.fetch("rack.jwt.session", {})[@auth_definition])
        return [403, {}, ["Access Forbidden"]] unless @block.call(method, path, scopes)
      end
      @app.call(env)
    end

    private

    def authorizable_route?(env)
      if @no_auth_routes.length > 0
        puts !@no_auth_routes.find { |route| route =~ /#{env['PATH_INFO']}/ }
        !@no_auth_routes.find { |route| route =~ /#{env['PATH_INFO']}/ }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.18221574344023322, 'fraction_numerical': 0.003887269193391642, 'mean_word_length': 2.027941176470588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '950138', 'n_tokens_mistral': 658, 'n_tokens_neox': 662, 'n_words': 150}