From 6653f96c23ff461bc4cadf5184a95e1c9142f7e6 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Sun, 15 Sep 2019 20:07:23 -0400 Subject: [PATCH] 13647: Move ...Controller.from_config_or_db to KeepService.all. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- .../arvados/v1/keep_services_controller.rb | 19 +++---------------- services/api/app/models/keep_service.rb | 19 +++++++++++++++++-- .../v1/keep_services_controller_test.rb | 3 ++- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/services/api/app/controllers/arvados/v1/keep_services_controller.rb b/services/api/app/controllers/arvados/v1/keep_services_controller.rb index 865f9c942f..c6e8894352 100644 --- a/services/api/app/controllers/arvados/v1/keep_services_controller.rb +++ b/services/api/app/controllers/arvados/v1/keep_services_controller.rb @@ -10,29 +10,16 @@ class Arvados::V1::KeepServicesController < ApplicationController def find_objects_for_index # all users can list all keep services - @objects = from_config_or_db + @objects = KeepService.all super end def accessible if request.headers['X-External-Client'] == '1' - @objects = from_config_or_db.where('service_type=?', 'proxy') + @objects = KeepService.where('service_type=?', 'proxy') else - @objects = from_config_or_db.where('service_type<>?', 'proxy') + @objects = KeepService.where('service_type<>?', 'proxy') end render_list end - - private - - # return the set of keep services from the database (if this is an - # older installation or test system where entries have been added - # manually) or, preferably, the cluster config file. - def from_config_or_db - if KeepService.all.count == 0 - KeepService.from_config - else - KeepService.all - end - end end diff --git a/services/api/app/models/keep_service.rb b/services/api/app/models/keep_service.rb index f9dd01837c..777f6bfb22 100644 --- a/services/api/app/models/keep_service.rb +++ b/services/api/app/models/keep_service.rb @@ -20,6 +20,21 @@ class KeepService < ArvadosModel api_accessible :superuser, :extend => :user do |t| end + # return the set of keep services from the database (if this is an + # older installation or test system where entries have been added + # manually) or, preferably, the cluster config file. + def self.all *args + if super.count == 0 + from_config + else + super + end + end + + def self.where *args + all.where *args + end + protected def permission_to_create @@ -45,10 +60,10 @@ class KeepService < ArvadosModel end if values.length == 0 # return empty set as AR relation - return where('1=0') + return unscoped.where('1=0') else sql = "(values #{values.join(", ")}) as keep_services (id, uuid, service_host, service_port, service_ssl_flag, service_type, read_only, created_at, modified_at, owner_uuid, modified_by_user_uuid, modified_by_client_uuid)" - return KeepService.from(sql) + return unscoped.from(sql) end end diff --git a/services/api/test/functional/arvados/v1/keep_services_controller_test.rb b/services/api/test/functional/arvados/v1/keep_services_controller_test.rb index 33c8aad3ea..f41a1d679c 100644 --- a/services/api/test/functional/arvados/v1/keep_services_controller_test.rb +++ b/services/api/test/functional/arvados/v1/keep_services_controller_test.rb @@ -37,7 +37,7 @@ class Arvados::V1::KeepServicesControllerTest < ActionController::TestCase end test "report configured servers if db is empty" do - KeepService.all.delete_all + KeepService.unscoped.all.delete_all expect_rvz = {} n = 0 Rails.configuration.Services.Keepstore.InternalURLs.each do |k,v| @@ -57,6 +57,7 @@ class Arvados::V1::KeepServicesControllerTest < ActionController::TestCase get :index, params: {:format => :json}, headers: auth(:active) + assert_response :success json_response['items'].each do |svc| url = "#{svc['service_ssl_flag'] ? 'https' : 'http'}://#{svc['service_host']}:#{svc['service_port']}" assert_equal true, expect_rvz.has_key?(url), "#{url} does not match any configured service: expecting #{expect_rvz}" -- 2.30.2