Sha256: 5ff632606d53bd3bca41213b952a44ab302bdce8748e52463492379dbd96018b
Contents?: true
Size: 1.18 KB
Versions: 9
Compression:
Stored size: 1.18 KB
Contents
require 'sinatra/base' module Patriot module Worker module Servlet class APIServletBase < Sinatra::Base set :show_exceptions, :after_handler ### Helper Methods helpers do # require authorization for updating def protected! return if authorized? headers['WWW-Authenticate'] = 'Basic Realm="Admin Only"' halt 401, "Not Authorized" end # authorize user (basic authentication) def authorized? @auth ||= Rack::Auth::Basic::Request.new(request.env) return @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [@@username, @@password] end end # @param worker [Patriot::Wokrer::Base] # @param config [Patriot::Util::Config::Base] def self.configure(worker, config) @@worker = worker @@config = config @@username = config.get(Patriot::Util::Config::USERNAME_KEY, "") @@password = config.get(Patriot::Util::Config::PASSWORD_KEY, "") end before do content_type 'application/json;charset=utf8' end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems