13647: Merge branch 'master' into 13647-keepstore-config
[arvados.git] / services / api / app / controllers / arvados / v1 / healthcheck_controller.rb
index 41f7175f926f56106c42b105b694e5585a2c48d6..6c3822437607ae0fd6dce94a7e20ea8731c04232 100644 (file)
@@ -3,35 +3,33 @@
 # SPDX-License-Identifier: AGPL-3.0
 
 class Arvados::V1::HealthcheckController < ApplicationController
-  skip_before_filter :catch_redirect_hint
-  skip_before_filter :find_objects_for_index
-  skip_before_filter :find_object_by_uuid
-  skip_before_filter :load_filters_param
-  skip_before_filter :load_limit_offset_order_params
-  skip_before_filter :load_read_auths
-  skip_before_filter :load_where_param
-  skip_before_filter :render_404_if_no_object
-  skip_before_filter :require_auth_scope
+  skip_before_action :catch_redirect_hint
+  skip_before_action :find_objects_for_index
+  skip_before_action :find_object_by_uuid
+  skip_before_action :load_filters_param
+  skip_before_action :load_limit_offset_order_params
+  skip_before_action :load_read_auths
+  skip_before_action :load_where_param
+  skip_before_action :render_404_if_no_object
+  skip_before_action :require_auth_scope
 
-  before_filter :check_auth_header
+  before_action :check_auth_header
 
   def check_auth_header
-    mgmt_token = Rails.configuration.management_token
+    mgmt_token = Rails.configuration.ManagementToken
+    auth_header = request.headers['Authorization']
 
-    if !mgmt_token
-      send_error("disabled", status: 404)
-    else
-      auth_header = request.headers['Authorization']
-      if !auth_header
-        send_error("authorization required", status: 401)
-      elsif auth_header != 'Bearer '+mgmt_token
-        send_error("authorization error", status: 403)
-      end
+    if mgmt_token == ""
+      send_json ({"errors" => "disabled"}), status: 404
+    elsif !auth_header
+      send_json ({"errors" => "authorization required"}), status: 401
+    elsif auth_header != 'Bearer '+mgmt_token
+      send_json ({"errors" => "authorization error"}), status: 403
     end
   end
 
   def ping
-    resp = {"health": "OK"}
+    resp = {"health" => "OK"}
     send_json resp
   end
 end