Sha256: 9b845d611079afbd54620fe0e0bc671f101302180d108e19e8b51a52a2324e3f

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

# This class is meant to be overwritten in host applications
#
# Authorized Service Lookups interact with filters to limit the
# services which a user is allowed to see. This allows host
# applications to more easily implement authorization.
#
# For example, if your Whoops installation is used by many different
# teams, but you don't want the teams to see each others' data, you
# could create a mapping between the team members' email addresses and
# the services they're allowed to see.
#
# Since filters are used when viewing events or sending notifications,
# the authorized service lookup allows you to modify the filters to
# prevent the unauthorized services from being seen
class Whoops::AuthorizedServiceLookup

  # @param key the value used to look up authorized services
  def initialize(key)
    @key = key
  end

  # if there are services given, then show all services
  # however, if we're looking at authorized services, then "all
  # services" means "all authorized services"
  #
  # if there is a filter on service then only allow authorized
  # services
  # 
  # one thing to note is that if both services and authorized_services
  # are blank, then no filter will be applied to service at all
  def filter_authorized(services)
    matches = services.select{ |s| service_authorized?(s) }
    matches.empty? ? authorized_services : matches
  end

  # Overwrite this in your subclasses if you want to implement
  # authorized services
  def authorized_services
    []
  end

  def service_authorized?(service)
    authorized_services.blank? || /^(#{authorized_services.join("|")})/ =~ service
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
whoops-0.5.3 app/models/whoops/authorized_service_lookup.rb
whoops-0.5.2 app/models/whoops/authorized_service_lookup.rb
whoops-0.5.1 app/models/whoops/authorized_service_lookup.rb
whoops-0.5.0 app/models/whoops/authorized_service_lookup.rb