From 9b1e23489c659655134a7e208a012d5d8d05bd07 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Wed, 19 Sep 2018 14:52:54 -0400 Subject: [PATCH] 10865: Add enable_legacy_jobs_api configuration option Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- services/api/config/application.default.yml | 7 ++++ .../config/initializers/legacy_jobs_api.rb | 42 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 services/api/config/initializers/legacy_jobs_api.rb diff --git a/services/api/config/application.default.yml b/services/api/config/application.default.yml index 5a1c229513..a76a567ee7 100644 --- a/services/api/config/application.default.yml +++ b/services/api/config/application.default.yml @@ -293,6 +293,13 @@ common: # Example: ["jobs.create", "pipeline_instances.create"] disable_api_methods: [] + # Enable the legacy Jobs API. + # auto -- (default) enable the Jobs API only if it has been used before + # (i.e., there are job records in the database) + # true -- enable the Jobs API despite lack of existing records. + # false -- disable the Jobs API despite presence of existing records. + enable_legacy_jobs_api: auto + ### ### Crunch, DNS & compute node management ### diff --git a/services/api/config/initializers/legacy_jobs_api.rb b/services/api/config/initializers/legacy_jobs_api.rb new file mode 100644 index 0000000000..00605725e8 --- /dev/null +++ b/services/api/config/initializers/legacy_jobs_api.rb @@ -0,0 +1,42 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + +# Config must be done before we files; otherwise they +# won't be able to use Rails.configuration.* to initialize their +# classes. +require_relative 'load_config.rb' + +Server::Application.configure do + if Rails.configuration.enable_legacy_jobs_api == false || + (Rails.configuration.enable_legacy_jobs_api == "auto" && + ActiveRecord::Base.connection.exec_query("select count(*) from jobs")[0] == 0) + Rails.configuration.disable_api_methods = ["jobs.create", + "pipeline_instances.create", + "pipeline_templates.create", + "jobs.get", + "pipeline_instances.get", + "pipeline_templates.get", + "jobs.list", + "pipeline_instances.list", + "pipeline_templates.list", + "jobs.index", + "pipeline_instances.index", + "pipeline_templates.index", + "jobs.update", + "pipeline_instances.update", + "pipeline_templates.update", + "jobs.queue", + "jobs.queue_size", + "job_tasks.create", + "job_tasks.get", + "job_tasks.list", + "job_tasks.index", + "job_tasks.update", + "jobs.show", + "pipeline_instances.show", + "pipeline_templates.show", + "jobs.show", + "job_tasks.show"] + end +end -- 2.39.5