[ARVADOS] updated: 3f7bde601546dc898975fbe7d56957794985fe43
Git user
git at public.curoverse.com
Wed Jul 19 10:11:48 EDT 2017
Summary of changes:
.../app/controllers/healthcheck_controller.rb | 35 ++++++++++++++++++++++
apps/workbench/config/application.default.yml | 4 +++
apps/workbench/config/routes.rb | 2 ++
.../controllers}/healthcheck_controller_test.rb | 4 +--
.../arvados/v1/healthcheck_controller.rb | 6 ++--
.../arvados/v1/healthcheck_controller_test.rb | 2 +-
6 files changed, 47 insertions(+), 6 deletions(-)
create mode 100644 apps/workbench/app/controllers/healthcheck_controller.rb
copy {services/api/test/functional/arvados/v1 => apps/workbench/test/controllers}/healthcheck_controller_test.rb (87%)
via 3f7bde601546dc898975fbe7d56957794985fe43 (commit)
via ed27ef88210f7fd23f0eafc55a44babd5f6c55fe (commit)
from 818daa27b9911bb360d80662b3beb86d1ca2188d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 3f7bde601546dc898975fbe7d56957794985fe43
Merge: 818daa2 ed27ef8
Author: radhika <radhika at curoverse.com>
Date: Wed Jul 19 10:10:59 2017 -0400
refs #11906
Merge branch '11906-wb-ping'
Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>
commit ed27ef88210f7fd23f0eafc55a44babd5f6c55fe
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..8cf6b93
--- /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