Sha256: 2550a1eff608909104487a8e62e93fa163b74013c9c7d59b8bce5d2646963a60
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
module Hcheck module ApplicationHelpers # Sinatra app controller helpers module Responders module_function def h_status authenticate!(params) if secured_access_enabled? @status = Hcheck.status if @status.find { |s| s[:status] == 'bad' } status 503 else status 200 end haml :index rescue Hcheck::Errors::InvalidAuthentication, Hcheck::Errors::IncompleteAuthSetup => e status 401 @msg = e.message haml :error end def respond_with(message, status_code, view) status status_code @msg = message haml view end private def secured_access_enabled? ENV['HCHECK_SECURE'] end def authenticate!(params) @token = params[:token] access_precheck! raise Hcheck::Errors::InvalidAuthentication unless ENV['HCHECK_ACCESS_TOKEN'].eql?(@token) end def access_precheck! # throw error when hcheck secure is enabled but token is not set yet raise Hcheck::Errors::IncompleteAuthSetup unless ENV['HCHECK_ACCESS_TOKEN'].present? # throw error when token is not sent raise Hcheck::Errors::InvalidAuthentication unless @token.present? end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hcheck-0.1.1 | lib/hcheck/application/helpers/responders.rb |
hcheck-0.1.0 | lib/hcheck/application/helpers/responders.rb |