health_check_controller.rb 572 Bytes
Newer Older
1 2 3
class HealthCheckController < HealthCheck::HealthCheckController
  before_action :validate_health_check_access!

4
  private
5 6

  def validate_health_check_access!
7 8 9 10 11 12 13 14 15 16
    render_404 unless token_valid?
  end

  def token_valid?
    token = params[:token].presence || request.headers['TOKEN']
    token.present? &&
      ActiveSupport::SecurityUtils.variable_size_secure_compare(
        token,
        current_application_settings.health_check_access_token
      )
17 18 19
  end

  def render_404
20
    render file: Rails.root.join('public', '404'), layout: false, status: '404'
21 22
  end
end