Sha256: 8aa234a5eb4d1f974efcfcd1401e8836f2658e5f4e2ac6d991dd4642f556bbe8
Contents?: true
Size: 1.38 KB
Versions: 18
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true module Aserto class Authorization attr_reader :config def initialize(app, options = {}) @app = app @config = Aserto.config(options) yield @config if block_given? end def call(env) request = Rack::Request.new(env) allowed = if enabled?(request) Aserto.logger.debug("Aserto authorization enabled") client = Aserto::AuthClient.new(request) res = client.is Aserto.logger.debug("Aserto authorization result -> allowed: #{res}") res else Aserto.logger.debug("Aserto authorization not enabled") true end return @app.call env if allowed config.on_unauthorized.call(env) end private def route(request) if defined? ::Rails require_relative "rails/utils" Aserto::Rails::Utils.route(request) elsif defined? ::Sinatra require_relative "sinatra/utils" Aserto::Sinatra::Utils.route(request) end end def enabled?(request) route_info = route(request) if route_info config.enabled && config.disabled_for.none? do |hash| hash[:path] == route_info[:path] && hash[:actions].include?(route_info[:action]) end else config.enabled end end end end
Version data entries
18 entries across 18 versions & 1 rubygems