18794: Fix "check" command test.
[arvados.git] / apps / workbench / app / controllers / healthcheck_controller.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class HealthcheckController < ApplicationController
6   skip_around_action :thread_clear
7   skip_around_action :set_thread_api_token
8   skip_around_action :require_thread_api_token
9   skip_before_action :ensure_arvados_api_exists
10   skip_before_action :accept_uuid_as_id_param
11   skip_before_action :check_user_agreements
12   skip_before_action :check_user_profile
13   skip_before_action :load_filters_and_paging_params
14   skip_before_action :find_object_by_uuid
15
16   before_action :check_auth_header
17
18   def check_auth_header
19     mgmt_token = Rails.configuration.ManagementToken
20     auth_header = request.headers['Authorization']
21
22     if mgmt_token.empty?
23       render :json => {:errors => "disabled"}, :status => 404
24     elsif !auth_header
25       render :json => {:errors => "authorization required"}, :status => 401
26     elsif auth_header != 'Bearer '+mgmt_token
27       render :json => {:errors => "authorization error"}, :status => 403
28     end
29   end
30
31   def ping
32     resp = {"health" => "OK"}
33     render json: resp
34   end
35 end