[ARVADOS] created: ffc117651144b197c9d650039a5403e972d54b7c

Git user git at public.curoverse.com
Tue Jul 18 17:57:25 EDT 2017


        at  ffc117651144b197c9d650039a5403e972d54b7c (commit)


commit ffc117651144b197c9d650039a5403e972d54b7c
Author: radhika <radhika at curoverse.com>
Date:   Tue Jul 18 17:40:21 2017 -0400

    11906: healthcheck ping for workbench
    
    Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>

diff --git a/apps/workbench/app/controllers/healthcheck_controller.rb b/apps/workbench/app/controllers/healthcheck_controller.rb
new file mode 100644
index 0000000..18daee4
--- /dev/null
+++ b/apps/workbench/app/controllers/healthcheck_controller.rb
@@ -0,0 +1,35 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class HealthcheckController < ApplicationController
+  skip_around_filter :thread_clear
+  skip_around_filter :set_thread_api_token
+  skip_around_filter :require_thread_api_token
+  skip_before_filter :ensure_arvados_api_exists
+  skip_before_filter :accept_uuid_as_id_param
+  skip_before_filter :check_user_agreements
+  skip_before_filter :check_user_profile
+  skip_before_filter :load_filters_and_paging_params
+  skip_before_filter :find_object_by_uuid
+
+  before_filter :check_auth_header
+
+  def check_auth_header
+    mgmt_token = Rails.configuration.management_token
+      auth_header = request.headers['Authorization']
+
+    if !mgmt_token
+      render :json => {:errors => "disabled"}, :status => 404
+    elsif !auth_header
+      render :json => {:errors => "authorization required"}, :status => 401
+    elsif auth_header != 'Bearer '+mgmt_token
+      render :json => {:errors => "authorization error"}, :status => 403
+    end
+  end
+
+  def ping
+    resp = {"health" => "OK"}
+    render json: resp
+  end
+end
diff --git a/apps/workbench/config/application.default.yml b/apps/workbench/config/application.default.yml
index 6998b17..943432d 100644
--- a/apps/workbench/config/application.default.yml
+++ b/apps/workbench/config/application.default.yml
@@ -295,3 +295,7 @@ common:
   # to suppress these properties
   show_recent_collections_on_dashboard: true
   show_user_notifications: true
+
+  # Token to be included in all healthcheck requests. Disabled by default.
+  # Workbench expects request header of the format "Authorization: Bearer xxx"
+  management_token: false
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index f2387f1..a3644e5 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -126,6 +126,8 @@ ArvadosWorkbench::Application.routes.draw do
 
   root :to => 'projects#index'
 
+  match '/_health/ping', to: 'healthcheck#ping', via: [:get]
+
   # Send unroutable requests to an arbitrary controller
   # (ends up at ApplicationController#render_not_found)
   match '*a', to: 'links#render_not_found', via: [:get, :post]
diff --git a/services/api/test/functional/arvados/v1/healthcheck_controller_test.rb b/apps/workbench/test/controllers/healthcheck_controller_test.rb
similarity index 87%
copy from services/api/test/functional/arvados/v1/healthcheck_controller_test.rb
copy to apps/workbench/test/controllers/healthcheck_controller_test.rb
index 10d493b..9254593 100644
--- a/services/api/test/functional/arvados/v1/healthcheck_controller_test.rb
+++ b/apps/workbench/test/controllers/healthcheck_controller_test.rb
@@ -4,7 +4,7 @@
 
 require 'test_helper'
 
-class Arvados::V1::HealthcheckControllerTest < ActionController::TestCase
+class HealthcheckControllerTest < ActionController::TestCase
   [
     [false, nil, 404, 'disabled'],
     [true, nil, 401, 'authorization required'],
@@ -23,7 +23,7 @@ class Arvados::V1::HealthcheckControllerTest < ActionController::TestCase
       if error_code == 200
         assert_equal(JSON.load('{"health":"OK"}'), resp)
       else
-        assert_includes(resp['errors'], error_msg)
+        assert_equal(resp['errors'], error_msg)
       end
     end
   end
diff --git a/services/api/app/controllers/arvados/v1/healthcheck_controller.rb b/services/api/app/controllers/arvados/v1/healthcheck_controller.rb
index e10b393..3986af9 100644
--- a/services/api/app/controllers/arvados/v1/healthcheck_controller.rb
+++ b/services/api/app/controllers/arvados/v1/healthcheck_controller.rb
@@ -20,11 +20,11 @@ class Arvados::V1::HealthcheckController < ApplicationController
     auth_header = request.headers['Authorization']
 
     if !mgmt_token
-      send_error("disabled", status: 404)
+      send_json ({"errors" => "disabled"}), status: 404
     elsif !auth_header
-      send_error("authorization required", status: 401)
+      send_json ({"errors" => "authorization required"}), status: 401
     elsif auth_header != 'Bearer '+mgmt_token
-      send_error("authorization error", status: 403)
+      send_json ({"errors" => "authorization error"}), status: 403
     end
   end
 
diff --git a/services/api/test/functional/arvados/v1/healthcheck_controller_test.rb b/services/api/test/functional/arvados/v1/healthcheck_controller_test.rb
index 10d493b..282bdf1 100644
--- a/services/api/test/functional/arvados/v1/healthcheck_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/healthcheck_controller_test.rb
@@ -23,7 +23,7 @@ class Arvados::V1::HealthcheckControllerTest < ActionController::TestCase
       if error_code == 200
         assert_equal(JSON.load('{"health":"OK"}'), resp)
       else
-        assert_includes(resp['errors'], error_msg)
+        assert_equal(error_msg, resp['errors'])
       end
     end
   end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list