From 5582ee9f3ec8a08d39ecd8256e76c2f3c32f3f19 Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Wed, 27 May 2015 17:47:31 -0400 Subject: [PATCH] Fixes #10621: Refactor to use SETTINGS instead of Katello.config --- .../katello/api/v2/repositories_controller.rb | 2 +- .../katello/application_controller.rb | 2 +- app/helpers/katello/application_helper.rb | 2 +- app/helpers/katello/katello_urls_helper.rb | 2 +- .../candlepin/listen_on_candlepin_events.rb | 10 +- .../actions/katello/activation_key/create.rb | 2 +- .../content_view/environment_create.rb | 2 +- .../actions/katello/organization/create.rb | 2 +- .../actions/katello/organization/destroy.rb | 2 +- app/lib/actions/katello/product/update.rb | 4 +- app/lib/actions/katello/repository/destroy.rb | 2 +- .../actions/katello/repository/discover.rb | 11 +- app/lib/actions/katello/repository/update.rb | 6 +- .../system/auto_attach_subscriptions.rb | 4 +- app/lib/actions/katello/system/update.rb | 8 +- app/lib/actions/pulp/repository/sync.rb | 10 +- .../actions/pulp/repository/upload_file.rb | 2 +- app/lib/katello/http_resource.rb | 4 +- app/lib/katello/resources/candlepin.rb | 24 ++-- app/lib/katello/resources/cdn.rb | 12 +- app/lib/katello/util/thread_session.rb | 14 +- app/models/katello/activation_key.rb | 4 +- .../concerns/organization_extensions.rb | 4 +- .../katello/concerns/user_extensions.rb | 2 +- .../katello/content_view_environment.rb | 4 +- .../content_view_erratum_filter_rule.rb | 2 +- app/models/katello/content_view_history.rb | 2 +- .../content_view_package_filter_rule.rb | 2 +- .../content_view_package_group_filter_rule.rb | 2 +- .../content_view_puppet_environment.rb | 6 +- .../katello/content_view_puppet_module.rb | 2 +- app/models/katello/ext/indexed_model.rb | 2 +- .../elastic_search/backend_indexed_model.rb | 4 +- .../katello/glue/elastic_search/items.rb | 2 +- app/models/katello/glue/provider.rb | 4 +- app/models/katello/glue/pulp/repo.rb | 24 ++-- app/models/katello/gpg_key.rb | 2 +- app/models/katello/host_collection.rb | 2 +- app/models/katello/hypervisor.rb | 2 +- app/models/katello/job.rb | 2 +- app/models/katello/ping.rb | 6 +- app/models/katello/product.rb | 6 +- app/models/katello/provider.rb | 2 +- app/models/katello/pulp_sync_status.rb | 2 +- app/models/katello/pulp_task_status.rb | 2 +- app/models/katello/repository.rb | 6 +- app/models/katello/system.rb | 8 +- app/models/katello/task_status.rb | 2 +- .../organizations/_edit_override.html.erb | 2 +- .../katello/pulp/pulp_content_unit.rb | 6 +- .../api/v2/organizations/show.json.rabl | 2 +- config/initializers/runcible.rb | 2 +- config/katello.yaml.example | 80 +++++++++-- config/katello_defaults.yml | 94 ------------- db/seeds.rb | 2 +- .../lib/bastion_katello/engine.rb | 5 +- lib/katello.rb | 2 - lib/katello/app_config.rb | 10 -- lib/katello/configuration.rb | 58 -------- lib/katello/configuration/loader.rb | 99 ------------- lib/katello/configuration/node.rb | 133 ------------------ lib/katello/configuration/validator.rb | 73 ---------- lib/katello/engine.rb | 36 ++++- lib/katello/load_configuration.rb | 62 -------- spec/models/gpg_key_spec.rb | 2 +- spec/models/ping_spec.rb | 6 +- spec/models/provider_spec.rb | 2 +- spec/support/deferred_garbage_collection.rb | 18 --- .../candlepin/listen_on_events_test.rb | 2 +- test/actions/katello/content_view_test.rb | 4 +- test/actions/katello/foreman_test.rb | 4 +- .../api/v2/repositories_controller_test.rb | 4 +- .../vcr_cassettes/elasticsearch/package.yml | 60 ++++---- test/katello_test_helper.rb | 2 + .../authorization/authorization_base.rb | 1 - test/source_code_test.rb | 6 +- test/support/runcible.rb | 8 +- test/support/vcr.rb | 2 +- 78 files changed, 280 insertions(+), 742 deletions(-) delete mode 100644 lib/katello/app_config.rb delete mode 100644 lib/katello/configuration.rb delete mode 100644 lib/katello/configuration/loader.rb delete mode 100644 lib/katello/configuration/node.rb delete mode 100644 lib/katello/configuration/validator.rb delete mode 100644 lib/katello/load_configuration.rb delete mode 100644 spec/support/deferred_garbage_collection.rb diff --git a/app/controllers/katello/api/v2/repositories_controller.rb b/app/controllers/katello/api/v2/repositories_controller.rb index 489f253b60b..1ed7da9baa4 100644 --- a/app/controllers/katello/api/v2/repositories_controller.rb +++ b/app/controllers/katello/api/v2/repositories_controller.rb @@ -162,7 +162,7 @@ def destroy param 'task_id', String, :required => true end def sync_complete - if params[:token] != Rack::Utils.parse_query(URI(Katello.config.post_sync_url).query)['token'] + if params[:token] != Rack::Utils.parse_query(URI(SETTINGS[:katello][:post_sync_url]).query)['token'] fail Errors::SecurityViolation, _("Token invalid during sync_complete.") end diff --git a/app/controllers/katello/application_controller.rb b/app/controllers/katello/application_controller.rb index e60c60e3f4b..0fadf63d27c 100644 --- a/app/controllers/katello/application_controller.rb +++ b/app/controllers/katello/application_controller.rb @@ -491,7 +491,7 @@ def render_panel_direct(obj_class, panel_options, search, start, sort, search_op if search.nil? || search == '' all_rows = true - elsif search_options[:simple_query] && !Katello.config.simple_search_tokens.any? { |s| search.downcase.match(s) } + elsif search_options[:simple_query] && !SETTINGS[:katello][:simple_search_tokens].any? { |s| search.downcase.match(s) } search = search_options[:simple_query] end #search = Util::Search::filter_input search diff --git a/app/helpers/katello/application_helper.rb b/app/helpers/katello/application_helper.rb index 0d7f01f24c4..96949b69d9e 100644 --- a/app/helpers/katello/application_helper.rb +++ b/app/helpers/katello/application_helper.rb @@ -103,7 +103,7 @@ def one_panel(panel_id, collection, options) end def notification_polling_time - time = Katello.config.notification && Katello.config.notification.polling_seconds + time = 120 return time.to_i * 1_000 if time return 120_000 end diff --git a/app/helpers/katello/katello_urls_helper.rb b/app/helpers/katello/katello_urls_helper.rb index a9a38c9d6c3..f9f2d81330a 100644 --- a/app/helpers/katello/katello_urls_helper.rb +++ b/app/helpers/katello/katello_urls_helper.rb @@ -12,7 +12,7 @@ def subscription_manager_configuration_url(host = nil) Setting[:foreman_url].sub(/\Ahttps/, 'http') end - "#{prefix}/pub/#{Katello.config.consumer_cert_rpm}" + "#{prefix}/pub/#{SETTINGS[:katello][:consumer_cert_rpm]}" end end end diff --git a/app/lib/actions/candlepin/listen_on_candlepin_events.rb b/app/lib/actions/candlepin/listen_on_candlepin_events.rb index 2ca54cfc6aa..24484f0b0d1 100644 --- a/app/lib/actions/candlepin/listen_on_candlepin_events.rb +++ b/app/lib/actions/candlepin/listen_on_candlepin_events.rb @@ -165,16 +165,16 @@ def act_on_event(event) end def configured? - ::Katello.config.respond_to?(:qpid) && - ::Katello.config.qpid.respond_to?(:url) && - ::Katello.config.qpid.respond_to?(:subscriptions_queue_address) + SETTINGS[:katello].key?(:qpid) && + SETTINGS[:katello][:qpid].key?(:url) && + SETTINGS[:katello][:qpid].key?(:subscriptions_queue_address) end def initialize_listening_service(suspended_action) if configured? CandlepinListeningService.initialize(world.logger, - ::Katello.config.qpid.url, - ::Katello.config.qpid.subscriptions_queue_address) + SETTINGS[:katello][:qpid][:url], + SETTINGS[:katello][:qpid][:subscriptions_queue_address]) suspended_action.notify_not_connected("initialized...have not connected yet") else action_logger.error("katello has not been configured for qpid.url and qpid.subscriptions_queue_address") diff --git a/app/lib/actions/katello/activation_key/create.rb b/app/lib/actions/katello/activation_key/create.rb index adb7c71d923..691bbc1fb88 100644 --- a/app/lib/actions/katello/activation_key/create.rb +++ b/app/lib/actions/katello/activation_key/create.rb @@ -4,7 +4,7 @@ module ActivationKey class Create < Actions::EntryAction def plan(activation_key) activation_key.save! - if ::Katello.config.use_cp + if ::SETTINGS[:katello][:use_cp] cp_create = plan_action(Candlepin::ActivationKey::Create, organization_label: activation_key.organization.label, auto_attach: activation_key.auto_attach) diff --git a/app/lib/actions/katello/content_view/environment_create.rb b/app/lib/actions/katello/content_view/environment_create.rb index a8450d0fe5c..e3912d3cd5e 100644 --- a/app/lib/actions/katello/content_view/environment_create.rb +++ b/app/lib/actions/katello/content_view/environment_create.rb @@ -4,7 +4,7 @@ module ContentView class EnvironmentCreate < Actions::Base def plan(content_view_environment) content_view_environment.save! - if ::Katello.config.use_cp + if ::SETTINGS[:katello][:use_cp] content_view = content_view_environment.content_view plan_action(Candlepin::Environment::Create, organization_label: content_view.organization.label, diff --git a/app/lib/actions/katello/organization/create.rb b/app/lib/actions/katello/organization/create.rb index 7e323f79412..a293ecf1815 100644 --- a/app/lib/actions/katello/organization/create.rb +++ b/app/lib/actions/katello/organization/create.rb @@ -12,7 +12,7 @@ def plan(organization) organization.save! sequence do - if ::Katello.config.use_cp + if ::SETTINGS[:katello][:use_cp] cp_create = plan_action(Candlepin::Owner::Create, label: organization.label, name: organization.name) diff --git a/app/lib/actions/katello/organization/destroy.rb b/app/lib/actions/katello/organization/destroy.rb index bac2e16222f..fb11cb7cdd9 100644 --- a/app/lib/actions/katello/organization/destroy.rb +++ b/app/lib/actions/katello/organization/destroy.rb @@ -18,7 +18,7 @@ def plan(organization, current_org = nil) remove_environments(organization) destroy_contents(organization) plan_self - plan_action(Candlepin::Owner::Destroy, label: organization.label) if ::Katello.config.use_cp + plan_action(Candlepin::Owner::Destroy, label: organization.label) if ::SETTINGS[:katello][:use_cp] plan_action(Candlepin::Product::DeleteUnused, organization) end end diff --git a/app/lib/actions/katello/product/update.rb b/app/lib/actions/katello/product/update.rb index 9d6fcbe67ba..8adc084194f 100644 --- a/app/lib/actions/katello/product/update.rb +++ b/app/lib/actions/katello/product/update.rb @@ -9,10 +9,10 @@ def plan(product, product_params) plan_action(::Actions::Katello::Product::RepositoriesGpgReset, product) end - if ::Katello.config.use_cp && product.productContent_changed? + if ::SETTINGS[:katello][:use_cp] && product.productContent_changed? plan_action(::Actions::Candlepin::Product::Update, product) end - plan_action(::Actions::Pulp::Repos::Update, product) if ::Katello.config.use_pulp + plan_action(::Actions::Pulp::Repos::Update, product) if ::SETTINGS[:katello][:use_pulp] end end end diff --git a/app/lib/actions/katello/repository/destroy.rb b/app/lib/actions/katello/repository/destroy.rb index 3b218284d72..e1308a4b95c 100644 --- a/app/lib/actions/katello/repository/destroy.rb +++ b/app/lib/actions/katello/repository/destroy.rb @@ -28,7 +28,7 @@ def plan(repository, options = {}) repository.destroy! if planned_destroy - if !skip_environment_update && ::Katello.config.use_cp && view_env + if !skip_environment_update && ::SETTINGS[:katello][:use_cp] && view_env plan_action(ContentView::UpdateEnvironment, repository.content_view, repository.environment) end diff --git a/app/lib/actions/katello/repository/discover.rb b/app/lib/actions/katello/repository/discover.rb index 3f7c9722e8f..19930c1e821 100644 --- a/app/lib/actions/katello/repository/discover.rb +++ b/app/lib/actions/katello/repository/discover.rb @@ -48,11 +48,12 @@ def task_output def proxy proxy = {} - config = ::Katello.config.cdn_proxy - proxy[:proxy_host] = URI.parse(config.host).host if config.respond_to?(:host) - proxy[:proxy_port] = config.port if config.respond_to?(:port) - proxy[:proxy_user] = config.user if config.respond_to?(:user) - proxy[:proxy_password] = config.password if config.respond_to?(:password) + if (config = SETTINGS[:katello][:cdn_proxy]) + proxy[:proxy_host] = URI.parse(config[:host]).host if config.key?(:host) + proxy[:proxy_port] = config[:port] if config.key?(:port) + proxy[:proxy_user] = config[:user] if config.key?(:user) + proxy[:proxy_password] = config[:password] if config.key?(:password) + end proxy end diff --git a/app/lib/actions/katello/repository/update.rb b/app/lib/actions/katello/repository/update.rb index 1c211ec26e6..6f62973b742 100644 --- a/app/lib/actions/katello/repository/update.rb +++ b/app/lib/actions/katello/repository/update.rb @@ -6,7 +6,7 @@ def plan(repository, repo_params) action_subject repository repository.update_attributes!(repo_params) - if (::Katello.config.use_cp && ::Katello.config.use_pulp) && repository.library_instance? + if (SETTINGS[:katello][:use_cp] && SETTINGS[:katello][:use_pulp]) && repository.library_instance? plan_action(::Actions::Candlepin::Product::ContentUpdate, :content_id => repository.content_id, :name => repository.name, @@ -16,11 +16,11 @@ def plan(repository, repo_params) :type => repository.content_type) end - if ::Katello.config.use_pulp && repository.pulp_update_needed? + if SETTINGS[:katello][:use_pulp] && repository.pulp_update_needed? plan_action(::Actions::Pulp::Repository::Refresh, repository) end - if ::Katello.config.use_pulp && (repository.previous_changes.key?('unprotected') || + if SETTINGS[:katello][:use_pulp] && (repository.previous_changes.key?('unprotected') || repository.previous_changes.key?('checksum_type')) plan_self(:user_id => ::User.current.id, :pulp_id => repository.pulp_id, :distributor_type_id => distributor_type_id(repository.content_type)) diff --git a/app/lib/actions/katello/system/auto_attach_subscriptions.rb b/app/lib/actions/katello/system/auto_attach_subscriptions.rb index 8913f352d54..44c5c84dde3 100644 --- a/app/lib/actions/katello/system/auto_attach_subscriptions.rb +++ b/app/lib/actions/katello/system/auto_attach_subscriptions.rb @@ -7,8 +7,8 @@ class AutoAttachSubscriptions < Actions::EntryAction def plan(system) system.disable_auto_reindex! action_subject system - plan_action(::Actions::Candlepin::Consumer::AutoAttachSubscriptions, system) if ::Katello.config.use_cp - plan_action(ElasticSearch::Reindex, system) if ::Katello.config.use_elasticsearch + plan_action(::Actions::Candlepin::Consumer::AutoAttachSubscriptions, system) if ::SETTINGS[:katello][:use_cp] + plan_action(ElasticSearch::Reindex, system) if ::SETTINGS[:katello][:use_elasticsearch] end end end diff --git a/app/lib/actions/katello/system/update.rb b/app/lib/actions/katello/system/update.rb index c4a804f99ae..d5609c01362 100644 --- a/app/lib/actions/katello/system/update.rb +++ b/app/lib/actions/katello/system/update.rb @@ -10,14 +10,14 @@ def plan(system, sys_params) system.update_attributes!(sys_params) sequence do concurrence do - plan_action(::Actions::Pulp::Consumer::Update, system) if !system.hypervisor? && ::Katello.config.use_pulp - plan_action(::Actions::Candlepin::Consumer::Update, system) if ::Katello.config.use_cp + plan_action(::Actions::Pulp::Consumer::Update, system) if !system.hypervisor? && ::SETTINGS[:katello][:use_pulp] + plan_action(::Actions::Candlepin::Consumer::Update, system) if ::SETTINGS[:katello][:use_cp] end - if sys_params[:autoheal] && ::Katello.config.use_cp + if sys_params[:autoheal] && ::SETTINGS[:katello][:use_cp] plan_action(::Actions::Candlepin::Consumer::AutoAttachSubscriptions, system) end - plan_action(ElasticSearch::Reindex, system) if ::Katello.config.use_elasticsearch + plan_action(ElasticSearch::Reindex, system) if ::SETTINGS[:katello][:use_elasticsearch] end end end diff --git a/app/lib/actions/pulp/repository/sync.rb b/app/lib/actions/pulp/repository/sync.rb index 81d16e66ad6..4379101adcf 100644 --- a/app/lib/actions/pulp/repository/sync.rb +++ b/app/lib/actions/pulp/repository/sync.rb @@ -16,15 +16,15 @@ def invoke_external_task else sync_options = {} - if ::Katello.config.pulp.sync_KBlimit + if SETTINGS[:katello][:pulp][:sync_KBlimit] # set bandwidth limit - sync_options[:max_speed] ||= ::Katello.config.pulp.sync_KBlimit + sync_options[:max_speed] ||= SETTINGS[:katello][:pulp][:sync_KBlimit] end - if ::Katello.config.pulp.sync_threads + if SETTINGS[:katello][:pulp][:sync_threads] # set threads per sync - sync_options[:num_threads] ||= ::Katello.config.pulp.sync_threads + sync_options[:num_threads] ||= SETTINGS[:katello][:pulp][:sync_threads] end - sync_options[:validate] = !(::Katello.config.pulp.skip_checksum_validation) + sync_options[:validate] = !(SETTINGS[:katello][:pulp][:skip_checksum_validation]) output[:pulp_tasks] = pulp_tasks = pulp_resources.repository.sync(input[:pulp_id], override_config: sync_options) diff --git a/app/lib/actions/pulp/repository/upload_file.rb b/app/lib/actions/pulp/repository/upload_file.rb index 8bd8da79a8f..347d5cfd1a9 100644 --- a/app/lib/actions/pulp/repository/upload_file.rb +++ b/app/lib/actions/pulp/repository/upload_file.rb @@ -20,7 +20,7 @@ def run private def upload_chunk_size - ::Katello.config.pulp.upload_chunk_size + SETTINGS[:katello][:pulp][:upload_chunk_size] end end end diff --git a/app/lib/katello/http_resource.rb b/app/lib/katello/http_resource.rb index 886ef7f7e20..26fef69e55e 100644 --- a/app/lib/katello/http_resource.rb +++ b/app/lib/katello/http_resource.rb @@ -181,8 +181,8 @@ def rest_client(http_type, method, path) added_header = {'Authorization' => request['Authorization']} RestClient::Resource.new url, :headers => added_header, - :open_timeout => Katello.config.rest_client_timeout, - :timeout => Katello.config.rest_client_timeout + :open_timeout => SETTINGS[:katello][:rest_client_timeout], + :timeout => SETTINGS[:katello][:rest_client_timeout] end # Encode url element if its not nil. This helper method is used mainly in resource path methods. diff --git a/app/lib/katello/resources/candlepin.rb b/app/lib/katello/resources/candlepin.rb index 3282032049f..74279eec6c3 100644 --- a/app/lib/katello/resources/candlepin.rb +++ b/app/lib/katello/resources/candlepin.rb @@ -41,13 +41,13 @@ def self.path_with_cp_prefix(path) end class CandlepinResource < HttpResource - cfg = Katello.config.candlepin - url = cfg.url + cfg = SETTINGS[:katello][:candlepin] + url = cfg[:url] self.prefix = URI.parse(url).path self.site = url.gsub(self.prefix, "") - self.consumer_secret = cfg.oauth_secret - self.consumer_key = cfg.oauth_key - self.ca_cert_file = cfg.ca_cert_file + self.consumer_secret = cfg[:oauth_secret] + self.consumer_key = cfg[:oauth_key] + self.ca_cert_file = cfg[:ca_cert_file] def self.logger ::Foreman::Logging.logger('katello/cp_rest') @@ -287,15 +287,15 @@ def self.logger end def self.resource(url, client_cert, client_key, ca_file) - if Katello.config.cdn_proxy && Katello.config.cdn_proxy.host - proxy_config = Katello.config.cdn_proxy + if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host] + proxy_config = SETTINGS[:katello][:cdn_proxy] uri = URI('') - uri.scheme = URI.parse(proxy_config.host).scheme - uri.host = URI.parse(proxy_config.host).host - uri.port = proxy_config.port - uri.user = proxy_config.user - uri.password = proxy_config.password + uri.scheme = URI.parse(proxy_config[:host]).scheme + uri.host = URI.parse(proxy_config[:host]).host + uri.port = proxy_config[:port] + uri.user = proxy_config[:user] + uri.password = proxy_config[:password] RestClient.proxy = uri.to_s end diff --git a/app/lib/katello/resources/cdn.rb b/app/lib/katello/resources/cdn.rb index 02223ad82ec..eaa377c9ee1 100644 --- a/app/lib/katello/resources/cdn.rb +++ b/app/lib/katello/resources/cdn.rb @@ -49,7 +49,7 @@ def initialize(url, options = {}) # Run the following command in rails console to figure out other # valid constants in other ruby versions # "OpenSSL::SSL::SSLContext::METHODS" - @net.ssl_version = Katello.config.cdn_ssl_version if Katello.config.key?(:cdn_ssl_version) + @net.ssl_version = SETTINGS[:katello][:cdn_ssl_version] if SETTINGS[:katello].key?(:cdn_ssl_version) if (options[:verify_ssl] == false) || (options[:verify_ssl] == OpenSSL::SSL::VERIFY_NONE) @net.verify_mode = OpenSSL::SSL::VERIFY_NONE @@ -113,11 +113,11 @@ def net_http_class end def load_proxy_settings - if Katello.config.cdn_proxy && Katello.config.cdn_proxy.host - self.proxy_host = parse_host(Katello.config.cdn_proxy.host) - self.proxy_port = Katello.config.cdn_proxy.port - self.proxy_user = Katello.config.cdn_proxy.user - self.proxy_password = Katello.config.cdn_proxy.password + if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host] + self.proxy_host = parse_host(SETTINGS[:katello][:cdn_proxy][:host]) + self.proxy_port = SETTINGS[:katello][:cdn_proxy][:port] + self.proxy_user = SETTINGS[:katello][:cdn_proxy][:user] + self.proxy_password = SETTINGS[:katello][:cdn_proxy][:password] end rescue URI::Error => e Rails.logger.error "Could not parse cdn_proxy:" diff --git a/app/lib/katello/util/thread_session.rb b/app/lib/katello/util/thread_session.rb index 8ca329591fc..74425e0156a 100644 --- a/app/lib/katello/util/thread_session.rb +++ b/app/lib/katello/util/thread_session.rb @@ -44,26 +44,26 @@ def self.current=(o) end Thread.current[:user] = o - if Katello.config.use_cp && o.respond_to?(:cp_oauth_header) + if SETTINGS[:katello][:use_cp] && o.respond_to?(:cp_oauth_header) self.cp_config(o.cp_oauth_header) end - if Katello.config.use_pulp + if SETTINGS[:katello][:use_pulp] self.pulp_config(User.remote_user) end end def self.pulp_config(user_remote_id, &_block) - uri = URI.parse(Katello.config.pulp.url) + uri = URI.parse(SETTINGS[:katello][:pulp][:url]) Katello.pulp_server = Runcible::Instance.new( :url => "#{uri.scheme}://#{uri.host.downcase}", :api_path => uri.path, :user => user_remote_id, - :timeout => Katello.config.rest_client_timeout, - :open_timeout => Katello.config.rest_client_timeout, - :oauth => {:oauth_secret => Katello.config.pulp.oauth_secret, - :oauth_key => Katello.config.pulp.oauth_key }, + :timeout => SETTINGS[:katello][:rest_client_timeout], + :open_timeout => SETTINGS[:katello][:rest_client_timeout], + :oauth => {:oauth_secret => SETTINGS[:katello][:pulp][:oauth_secret], + :oauth_key => SETTINGS[:katello][:pulp][:oauth_key] }, :logging => {:logger => ::Foreman::Logging.logger('katello/pulp_rest'), :exception => true, :info => true, diff --git a/app/models/katello/activation_key.rb b/app/models/katello/activation_key.rb index a78e15d97d8..8e04ee40bf7 100644 --- a/app/models/katello/activation_key.rb +++ b/app/models/katello/activation_key.rb @@ -2,8 +2,8 @@ module Katello class ActivationKey < Katello::Model self.include_root_in_json = false - include Glue::Candlepin::ActivationKey if Katello.config.use_cp - include Glue if Katello.config.use_cp + include Glue::Candlepin::ActivationKey if SETTINGS[:katello][:use_cp] + include Glue if SETTINGS[:katello][:use_cp] include Katello::Authorization::ActivationKey include ForemanTasks::Concerns::ActionSubject diff --git a/app/models/katello/concerns/organization_extensions.rb b/app/models/katello/concerns/organization_extensions.rb index bec3d7a040e..2961338f728 100644 --- a/app/models/katello/concerns/organization_extensions.rb +++ b/app/models/katello/concerns/organization_extensions.rb @@ -8,8 +8,8 @@ module OrganizationExtensions include ForemanTasks::Concerns::ActionSubject include ForemanTasks::Concerns::ActionTriggering - include Glue::Candlepin::Owner if Katello.config.use_cp - include Glue if Katello.config.use_cp + include Glue::Candlepin::Owner if SETTINGS[:katello][:use_cp] + include Glue if SETTINGS[:katello][:use_cp] include Katello::Authorization::Organization include Ext::LabelFromName diff --git a/app/models/katello/concerns/user_extensions.rb b/app/models/katello/concerns/user_extensions.rb index 2c2a7da478b..66c20bd5619 100644 --- a/app/models/katello/concerns/user_extensions.rb +++ b/app/models/katello/concerns/user_extensions.rb @@ -12,7 +12,7 @@ module UserExtensions has_many :activation_keys, :dependent => :destroy, :class_name => "Katello::ActivationKey" def self.remote_user - Katello.config.pulp.default_login + SETTINGS[:katello][:pulp][:default_login] end def self.cp_oauth_header diff --git a/app/models/katello/content_view_environment.rb b/app/models/katello/content_view_environment.rb index 202eb1b37c4..1b82ef06284 100644 --- a/app/models/katello/content_view_environment.rb +++ b/app/models/katello/content_view_environment.rb @@ -3,8 +3,8 @@ class ContentViewEnvironment < Katello::Model self.include_root_in_json = false include ForemanTasks::Concerns::ActionSubject - include Glue::Candlepin::Environment if Katello.config.use_cp - include Glue if Katello.config.use_cp + include Glue::Candlepin::Environment if SETTINGS[:katello][:use_cp] + include Glue if SETTINGS[:katello][:use_cp] include Authorization::ContentViewEnvironment belongs_to :content_view, :class_name => "Katello::ContentView", :inverse_of => :content_view_environments diff --git a/app/models/katello/content_view_erratum_filter_rule.rb b/app/models/katello/content_view_erratum_filter_rule.rb index d3f52b58d36..c81827743ad 100644 --- a/app/models/katello/content_view_erratum_filter_rule.rb +++ b/app/models/katello/content_view_erratum_filter_rule.rb @@ -2,7 +2,7 @@ module Katello class ContentViewErratumFilterRule < Katello::Model self.include_root_in_json = false - include Glue::ElasticSearch::ContentViewErratumFilterRule if Katello.config.use_elasticsearch + include Glue::ElasticSearch::ContentViewErratumFilterRule if SETTINGS[:katello][:use_elasticsearch] belongs_to :filter, :class_name => "Katello::ContentViewErratumFilter", diff --git a/app/models/katello/content_view_history.rb b/app/models/katello/content_view_history.rb index ffc7e938e87..a3594bad958 100644 --- a/app/models/katello/content_view_history.rb +++ b/app/models/katello/content_view_history.rb @@ -2,7 +2,7 @@ module Katello class ContentViewHistory < Katello::Model include Katello::Authorization::ContentViewHistory - include Glue::ElasticSearch::ContentViewHistory if Katello.config.use_elasticsearch + include Glue::ElasticSearch::ContentViewHistory if SETTINGS[:katello][:use_elasticsearch] belongs_to :environment, :class_name => "Katello::KTEnvironment", :inverse_of => :content_view_histories, :foreign_key => :katello_environment_id diff --git a/app/models/katello/content_view_package_filter_rule.rb b/app/models/katello/content_view_package_filter_rule.rb index 513de4dbfcd..eaff5716d9a 100644 --- a/app/models/katello/content_view_package_filter_rule.rb +++ b/app/models/katello/content_view_package_filter_rule.rb @@ -2,7 +2,7 @@ module Katello class ContentViewPackageFilterRule < Katello::Model self.include_root_in_json = false - include Glue::ElasticSearch::ContentViewPackageFilterRule if Katello.config.use_elasticsearch + include Glue::ElasticSearch::ContentViewPackageFilterRule if SETTINGS[:katello][:use_elasticsearch] belongs_to :filter, :class_name => "Katello::ContentViewPackageFilter", diff --git a/app/models/katello/content_view_package_group_filter_rule.rb b/app/models/katello/content_view_package_group_filter_rule.rb index 21b7847a6d2..b10986c9fbc 100644 --- a/app/models/katello/content_view_package_group_filter_rule.rb +++ b/app/models/katello/content_view_package_group_filter_rule.rb @@ -2,7 +2,7 @@ module Katello class ContentViewPackageGroupFilterRule < Katello::Model self.include_root_in_json = false - include Glue::ElasticSearch::ContentViewPackageGroupFilterRule if Katello.config.use_elasticsearch + include Glue::ElasticSearch::ContentViewPackageGroupFilterRule if SETTINGS[:katello][:use_elasticsearch] belongs_to :filter, :class_name => "Katello::ContentViewPackageGroupFilter", diff --git a/app/models/katello/content_view_puppet_environment.rb b/app/models/katello/content_view_puppet_environment.rb index b8c0c8e0b15..8426e98ff7c 100644 --- a/app/models/katello/content_view_puppet_environment.rb +++ b/app/models/katello/content_view_puppet_environment.rb @@ -3,8 +3,8 @@ class ContentViewPuppetEnvironment < Katello::Model self.include_root_in_json = false include ForemanTasks::Concerns::ActionSubject - include Glue::Pulp::Repo if Katello.config.use_pulp - include Glue if Katello.config.use_pulp + include Glue::Pulp::Repo if SETTINGS[:katello][:use_pulp] + include Glue if SETTINGS[:katello][:use_pulp] belongs_to :environment, :class_name => "Katello::KTEnvironment", :inverse_of => :content_view_puppet_environments @@ -70,7 +70,7 @@ def archive? def generate_puppet_path # rubocop:disable Style/EmptyElse if self.environment - File.join(Katello.config.puppet_repo_root, generate_puppet_env_name, 'modules') + File.join(SETTINGS[:katello][:puppet_repo_root], generate_puppet_env_name, 'modules') else nil #don't generate archived content view puppet environments end diff --git a/app/models/katello/content_view_puppet_module.rb b/app/models/katello/content_view_puppet_module.rb index a98338689a8..b76cfa213a3 100644 --- a/app/models/katello/content_view_puppet_module.rb +++ b/app/models/katello/content_view_puppet_module.rb @@ -39,7 +39,7 @@ def computed_version private def set_attributes - return unless Katello.config.use_pulp + return unless SETTINGS[:katello][:use_pulp] if self.uuid.present? puppet_module = PuppetModule.with_identifiers(self.uuid).first fail Errors::NotFound, _("Couldn't find Puppet Module with id '%s'") % self.uuid unless puppet_module diff --git a/app/models/katello/ext/indexed_model.rb b/app/models/katello/ext/indexed_model.rb index fad9d13d70b..a1ce01f5527 100644 --- a/app/models/katello/ext/indexed_model.rb +++ b/app/models/katello/ext/indexed_model.rb @@ -13,7 +13,7 @@ def self.display_attributes if Rails.env.development? || Rails.env.production? include Tire::Model::Search include Tire::Model::Callbacks - index_name Katello.config.elastic_index + '_' + self.base_class.name.downcase + index_name SETTINGS[:katello][:elastic_index] + '_' + self.base_class.name.downcase #Shared analyzers. If you need a model-specific analyzer for some reason, # we'll need to refactor this to support that. diff --git a/app/models/katello/glue/elastic_search/backend_indexed_model.rb b/app/models/katello/glue/elastic_search/backend_indexed_model.rb index ca888f1c748..540809a698b 100644 --- a/app/models/katello/glue/elastic_search/backend_indexed_model.rb +++ b/app/models/katello/glue/elastic_search/backend_indexed_model.rb @@ -16,14 +16,14 @@ def index_all self.create_index total = 0 - pkgs = fetch_all(total, Katello.config.pulp.bulk_load_size) + pkgs = fetch_all(total, SETTINGS[:katello][:pulp][:bulk_load_size]) until pkgs.empty? #we can't know how many there are, so we have to keep looping until we get nothing Tire.index(self.index) do import pkgs end total += pkgs.length - pkgs = fetch_all(total, Katello.config.pulp.bulk_load_size) + pkgs = fetch_all(total, SETTINGS[:katello][:pulp][:bulk_load_size]) end total end diff --git a/app/models/katello/glue/elastic_search/items.rb b/app/models/katello/glue/elastic_search/items.rb index 2fe0744b60a..a7b6d367bc7 100644 --- a/app/models/katello/glue/elastic_search/items.rb +++ b/app/models/katello/glue/elastic_search/items.rb @@ -57,7 +57,7 @@ def retrieve(query_string = nil, offset = 0, search_options = {}) if query_string.blank? all_rows = true - elsif search_options[:simple_query] && !Katello.config.simple_search_tokens.any? { |s| search.downcase.match(s) } + elsif search_options[:simple_query] && !SETTINGS[:katello][:simple_search_tokens].any? { |s| search.downcase.match(s) } query_string = search_options[:simple_query] end diff --git a/app/models/katello/glue/provider.rb b/app/models/katello/glue/provider.rb index 4d6cd17a501..5a88c8c197f 100644 --- a/app/models/katello/glue/provider.rb +++ b/app/models/katello/glue/provider.rb @@ -221,7 +221,7 @@ def queue_import_manifest(options) # rubocop:disable MethodLength pre_queue.create(:name => "import of products in manifest #{zip_file_path}", :priority => 5, :action => [self, :import_products_from_cp]) pre_queue.create(:name => "refresh product repos", - :priority => 6, :action => [self, :refresh_existing_products]) if manifest_update && Katello.config.use_pulp + :priority => 6, :action => [self, :refresh_existing_products]) if manifest_update && SETTINGS[:katello][:use_pulp] self.save! rescue => error @@ -324,7 +324,7 @@ def queue_delete_manifest pre_queue.create(:name => "delete manifest for owner: #{self.organization.name}", :priority => 3, :action => [self, :exec_delete_manifest], :action_rollback => [self, :rollback_delete_manifest]) - if Katello.config.use_pulp + if SETTINGS[:katello][:use_pulp] pre_queue.create(:name => "refresh product repos for deletion", :priority => 6, :action => [self, :refresh_existing_products]) end diff --git a/app/models/katello/glue/pulp/repo.rb b/app/models/katello/glue/pulp/repo.rb index 0adf497aafd..0828ea59a4a 100644 --- a/app/models/katello/glue/pulp/repo.rb +++ b/app/models/katello/glue/pulp/repo.rb @@ -28,7 +28,7 @@ def self.included(base) def self.ensure_sync_notification resource = Katello.pulp_server.resources.event_notifier - url = Katello.config.post_sync_url + url = SETTINGS[:katello][:post_sync_url] type = Runcible::Resources::EventNotifier::EventTypes::REPO_SYNC_COMPLETE notifs = resource.list @@ -84,7 +84,7 @@ def initialize(attrs = nil, options = {}) end def uri - uri = URI.parse(Katello.config.pulp.url) + uri = URI.parse(SETTINGS[:katello][:pulp][:url]) "https://#{uri.host}/pulp/repos/#{relative_path}" end @@ -164,7 +164,7 @@ def generate_distributors dist.auto_publish = true [dist] when Repository::PUPPET_TYPE - repo_path = File.join(Katello.config.puppet_repo_root, + repo_path = File.join(SETTINGS[:katello][:puppet_repo_root], Environment.construct_name(self.organization, self.environment, self.content_view), @@ -336,7 +336,7 @@ def puppet_modules_json tmp_puppet_modules = [] #we fetch ids and then fetch errata by id, because repo errata # do not contain all the info we need (bz 854260) - self.puppet_module_ids.each_slice(Katello.config.pulp.bulk_load_size) do |sub_list| + self.puppet_module_ids.each_slice(SETTINGS[:katello][:pulp][:bulk_load_size]) do |sub_list| tmp_puppet_modules.concat(Katello.pulp_server.extensions.puppet_module.find_all_by_unit_ids(sub_list)) end tmp_puppet_modules @@ -346,7 +346,7 @@ def errata_json tmp_errata = [] #we fetch ids and then fetch errata by id, because repo errata # do not contain all the info we need (bz 854260) - self.errata_ids.each_slice(Katello.config.pulp.bulk_load_size) do |sub_list| + self.errata_ids.each_slice(SETTINGS[:katello][:pulp][:bulk_load_size]) do |sub_list| tmp_errata.concat(Katello.pulp_server.extensions.errata.find_all_by_unit_ids(sub_list)) end tmp_errata @@ -371,7 +371,7 @@ def package_group_json def rpms_json tmp_packages = [] - self.rpm_ids.each_slice(Katello.config.pulp.bulk_load_size) do |sub_list| + self.rpm_ids.each_slice(SETTINGS[:katello][:pulp][:bulk_load_size]) do |sub_list| tmp_packages.concat(Katello.pulp_server.extensions.rpm.find_all_by_unit_ids( sub_list, Pulp::Rpm::PULP_INDEXED_FIELDS)) end @@ -397,7 +397,7 @@ def docker_images_json repo_attrs = Katello.pulp_server.extensions.repository.retrieve_with_details(pulp_id) tags = repo_attrs.try(:[], :scratchpad).try(:[], :tags) || [] - docker_image_ids.each_slice(Katello.config.pulp.bulk_load_size) do |sub_list| + docker_image_ids.each_slice(SETTINGS[:katello][:pulp][:bulk_load_size]) do |sub_list| docker_images.concat(Katello.pulp_server.extensions.docker_image.find_all_by_unit_ids(sub_list)) end # add the docker tags in @@ -467,8 +467,8 @@ def pulp_update_needed? def sync(options = {}) sync_options = {} - sync_options[:max_speed] ||= Katello.config.pulp.sync_KBlimit if Katello.config.pulp.sync_KBlimit # set bandwidth limit - sync_options[:num_threads] ||= Katello.config.pulp.sync_threads if Katello.config.pulp.sync_threads # set threads per sync + sync_options[:max_speed] ||= SETTINGS[:katello][:pulp][:sync_KBlimit] if SETTINGS[:katello][:pulp][:sync_KBlimit] # set bandwidth limit + sync_options[:num_threads] ||= SETTINGS[:katello][:pulp][:sync_threads] if SETTINGS[:katello][:pulp][:sync_threads] # set threads per sync pulp_tasks = Katello.pulp_server.extensions.repository.sync(self.pulp_id, :override_config => sync_options) task = PulpSyncStatus.using_pulp_task(pulp_tasks) do |t| @@ -541,7 +541,7 @@ def unassociate_by_filter(content_type, filter_clauses) end def clear_contents - self.clear_content_indices if Katello.config.use_elasticsearch + self.clear_content_indices if SETTINGS[:katello][:use_elasticsearch] tasks = content_types.collect { |type| type.unassociate_from_repo(self.pulp_id, {}) }.flatten(1) tasks << Katello.pulp_server.extensions.repository.unassociate_units(self.pulp_id, @@ -674,7 +674,7 @@ def package_lists_for_publish names = [] filenames = [] rpm_list = [] - self.rpm_ids.each_slice(Katello.config.pulp.bulk_load_size) do |sub_list| + self.rpm_ids.each_slice(SETTINGS[:katello][:pulp][:bulk_load_size]) do |sub_list| rpm_list.concat(Katello.pulp_server.extensions.rpm.find_all_by_unit_ids( sub_list, %w(filename name), :include_repos => false)) end @@ -710,7 +710,7 @@ def _get_most_recent_sync_status end def full_path(smart_proxy = nil) - pulp_uri = URI.parse(smart_proxy ? smart_proxy.url : Katello.config.pulp.url) + pulp_uri = URI.parse(smart_proxy ? smart_proxy.url : SETTINGS[:katello][:pulp][:url]) scheme = (self.unprotected ? 'http' : 'https') if docker? "#{pulp_uri.host.downcase}:5000/#{pulp_id}" diff --git a/app/models/katello/gpg_key.rb b/app/models/katello/gpg_key.rb index 6bb6793bcde..5d13fa90d86 100644 --- a/app/models/katello/gpg_key.rb +++ b/app/models/katello/gpg_key.rb @@ -18,7 +18,7 @@ class GpgKey < Katello::Model validates :organization, :presence => true validates_with Validators::KatelloNameFormatValidator, :attributes => :name validates_with Validators::ContentValidator, :attributes => :content - validates_with Validators::GpgKeyContentValidator, :attributes => :content, :if => proc { Katello.config.gpg_strict_validation } + validates_with Validators::GpgKeyContentValidator, :attributes => :content, :if => proc { SETTINGS[:katello][:gpg_strict_validation] } scoped_search :on => :name, :complete_value => true scoped_search :on => :organization_id, :complete_value => true diff --git a/app/models/katello/host_collection.rb b/app/models/katello/host_collection.rb index c7c1fe8bcd7..2802fa59302 100644 --- a/app/models/katello/host_collection.rb +++ b/app/models/katello/host_collection.rb @@ -6,7 +6,7 @@ class HostCollection < Katello::Model define_hooks :add_system_hook, :remove_system_hook include Katello::Authorization::HostCollection - include Glue::ElasticSearch::HostCollection if Katello.config.use_elasticsearch + include Glue::ElasticSearch::HostCollection if SETTINGS[:katello][:use_elasticsearch] has_many :key_host_collections, :class_name => "Katello::KeyHostCollection", :dependent => :destroy has_many :activation_keys, :through => :key_host_collections diff --git a/app/models/katello/hypervisor.rb b/app/models/katello/hypervisor.rb index 0b861216c68..95946700450 100644 --- a/app/models/katello/hypervisor.rb +++ b/app/models/katello/hypervisor.rb @@ -1,6 +1,6 @@ module Katello class Hypervisor < System - use_index_of System if Katello.config.use_elasticsearch + use_index_of System if SETTINGS[:katello][:use_elasticsearch] validates_lengths_from_database UNSUPPORTED_ACTIONS = [:package_profile, :pulp_facts, :simple_packages, :errata, :del_pulp_consumer, :set_pulp_consumer, diff --git a/app/models/katello/job.rb b/app/models/katello/job.rb index f39037abed5..efe50c9f45c 100644 --- a/app/models/katello/job.rb +++ b/app/models/katello/job.rb @@ -3,7 +3,7 @@ class Job < Katello::Model self.include_root_in_json = false include Glue - include Glue::ElasticSearch::Job if Katello.config.use_elasticsearch + include Glue::ElasticSearch::Job if SETTINGS[:katello][:use_elasticsearch] belongs_to :job_owner, :polymorphic => true diff --git a/app/models/katello/ping.rb b/app/models/katello/ping.rb index 65b212f277f..e8f262c0649 100644 --- a/app/models/katello/ping.rb +++ b/app/models/katello/ping.rb @@ -29,7 +29,7 @@ def ping(services = SERVICES) # candlepin - ping without oauth if services.include?(:candlepin) - url = Katello.config.candlepin.url + url = SETTINGS[:katello][:candlepin][:url] exception_watch(result[:services][:candlepin]) do RestClient.get "#{url}/status" end @@ -37,7 +37,7 @@ def ping(services = SERVICES) # elasticsearch - ping without oauth if services.include?(:elasticsearch) - url = Katello.config.elastic_url + url = SETTINGS[:katello][:elastic_url] exception_watch(result[:services][:elasticsearch]) do RestClient.get "#{url}/_status" end @@ -111,7 +111,7 @@ def packages # because it returns empty string, which is not enough to say # pulp is the one that responded def pulp_without_oauth - body = RestClient.get("#{Katello.config.pulp.url}/status/") + body = RestClient.get("#{SETTINGS[:katello][:pulp][:url]}/status/") fail _("Pulp does not appear to be running.") if body.empty? json = JSON.parse(body) diff --git a/app/models/katello/product.rb b/app/models/katello/product.rb index 24963e31641..3f438f580b6 100644 --- a/app/models/katello/product.rb +++ b/app/models/katello/product.rb @@ -3,9 +3,9 @@ class Product < Katello::Model self.include_root_in_json = false include ForemanTasks::Concerns::ActionSubject - include Glue::Candlepin::Product if Katello.config.use_cp - include Glue::Pulp::Repos if Katello.config.use_pulp - include Glue if Katello.config.use_cp || Katello.config.use_pulp + include Glue::Candlepin::Product if SETTINGS[:katello][:use_cp] + include Glue::Pulp::Repos if SETTINGS[:katello][:use_pulp] + include Glue if SETTINGS[:katello][:use_cp] || SETTINGS[:katello][:use_pulp] include Katello::Authorization::Product diff --git a/app/models/katello/provider.rb b/app/models/katello/provider.rb index 4fbb4d03a3d..e1b9a43f28b 100644 --- a/app/models/katello/provider.rb +++ b/app/models/katello/provider.rb @@ -153,7 +153,7 @@ def related_resources protected def sanitize_repository_url - sanitize_url(:repository_url, Katello.config.redhat_repository_url) + sanitize_url(:repository_url, SETTINGS[:katello][:redhat_repository_url]) end def sanitize_url(attrib, default_value) diff --git a/app/models/katello/pulp_sync_status.rb b/app/models/katello/pulp_sync_status.rb index 209a0e0cd1e..f0a7db023e1 100644 --- a/app/models/katello/pulp_sync_status.rb +++ b/app/models/katello/pulp_sync_status.rb @@ -107,7 +107,7 @@ def parse_generic(details, errors) module Katello class PulpSyncStatus < PulpTaskStatus - use_index_of TaskStatus if Katello.config.use_elasticsearch + use_index_of TaskStatus if SETTINGS[:katello][:use_elasticsearch] HISTORY_ERROR = 'failed' HISTORY_SUCCESS = 'success' diff --git a/app/models/katello/pulp_task_status.rb b/app/models/katello/pulp_task_status.rb index 1f9d8e22e17..056c4e92843 100644 --- a/app/models/katello/pulp_task_status.rb +++ b/app/models/katello/pulp_task_status.rb @@ -1,6 +1,6 @@ module Katello class PulpTaskStatus < TaskStatus - use_index_of TaskStatus if Katello.config.use_elasticsearch + use_index_of TaskStatus if SETTINGS[:katello][:use_elasticsearch] WAIT_TIMES = [0.5, 1, 2, 4, 8, 16] WAIT_TIME_STEP = 5 diff --git a/app/models/katello/repository.rb b/app/models/katello/repository.rb index da3e19013f1..431f134face 100644 --- a/app/models/katello/repository.rb +++ b/app/models/katello/repository.rb @@ -7,10 +7,10 @@ class Repository < Katello::Model before_create :downcase_pulp_id include ForemanTasks::Concerns::ActionSubject - include Glue::Candlepin::Content if (Katello.config.use_cp && Katello.config.use_pulp) - include Glue::Pulp::Repo if Katello.config.use_pulp + include Glue::Candlepin::Content if (SETTINGS[:katello][:use_cp] && SETTINGS[:katello][:use_pulp]) + include Glue::Pulp::Repo if SETTINGS[:katello][:use_pulp] - include Glue if (Katello.config.use_cp || Katello.config.use_pulp) + include Glue if (SETTINGS[:katello][:use_cp] || SETTINGS[:katello][:use_pulp]) include Authorization::Repository include Ext::LabelFromName diff --git a/app/models/katello/system.rb b/app/models/katello/system.rb index 73ef4bf100d..4b32373d4d3 100644 --- a/app/models/katello/system.rb +++ b/app/models/katello/system.rb @@ -10,10 +10,10 @@ class System < Katello::Model :as_json_hook include ForemanTasks::Concerns::ActionSubject - include Glue::Candlepin::Consumer if Katello.config.use_cp - include Glue::Pulp::Consumer if Katello.config.use_pulp - include Glue if Katello.config.use_cp || Katello.config.use_pulp - include Glue::ElasticSearch::System if Katello.config.use_elasticsearch + include Glue::Candlepin::Consumer if SETTINGS[:katello][:use_cp] + include Glue::Pulp::Consumer if SETTINGS[:katello][:use_pulp] + include Glue if SETTINGS[:katello][:use_cp] || SETTINGS[:katello][:use_pulp] + include Glue::ElasticSearch::System if SETTINGS[:katello][:use_elasticsearch] include Authorization::System audited :on => [:create], :allow_mass_assignment => true diff --git a/app/models/katello/task_status.rb b/app/models/katello/task_status.rb index 42d7b2ba2be..8daf5bc52f2 100644 --- a/app/models/katello/task_status.rb +++ b/app/models/katello/task_status.rb @@ -16,7 +16,7 @@ class Status TIMED_OUT = :timed_out end - include Glue::ElasticSearch::TaskStatus if Katello.config.use_elasticsearch + include Glue::ElasticSearch::TaskStatus if SETTINGS[:katello][:use_elasticsearch] belongs_to :organization, :inverse_of => :task_statuses, :class_name => "Organization" belongs_to :user, :inverse_of => :task_statuses, :class_name => "::User" diff --git a/app/overrides/foreman/organizations/_edit_override.html.erb b/app/overrides/foreman/organizations/_edit_override.html.erb index f34adf5e8d1..167073f3b0d 100644 --- a/app/overrides/foreman/organizations/_edit_override.html.erb +++ b/app/overrides/foreman/organizations/_edit_override.html.erb @@ -4,7 +4,7 @@ <%= text_f f, :label, :disabled => true, :class => 'input-xlarge' %> - <% if ::Katello.config.use_cp %> + <% if ::SETTINGS[:katello][:use_cp] %> <%= selectable_f(f, :service_level, options_for_select(service_level_options, service_level_selected), {}, :label => _('Default System SLA')) %> <% end %> diff --git a/app/services/katello/pulp/pulp_content_unit.rb b/app/services/katello/pulp/pulp_content_unit.rb index beb16058a1b..f99f3d1b0f0 100644 --- a/app/services/katello/pulp/pulp_content_unit.rb +++ b/app/services/katello/pulp/pulp_content_unit.rb @@ -25,9 +25,9 @@ def self.unit_handler end def self.fetch_all - all_items = items = fetch(0, Katello.config.pulp.bulk_load_size) + all_items = items = fetch(0, SETTINGS[:katello][:pulp][:bulk_load_size]) until items.empty? #we can't know how many there are, so we have to keep looping until we get nothing - items = fetch(all_items.length, Katello.config.pulp.bulk_load_size) + items = fetch(all_items.length, SETTINGS[:katello][:pulp][:bulk_load_size]) all_items.concat(items) end all_items @@ -35,7 +35,7 @@ def self.fetch_all def self.fetch_by_uuids(uuids) items = [] - uuids.each_slice(Katello.config.pulp.bulk_load_size) do |sub_list| + uuids.each_slice(SETTINGS[:katello][:pulp][:bulk_load_size]) do |sub_list| items.concat(fetch(0, sub_list.length, sub_list)) end items diff --git a/app/views/katello/api/v2/organizations/show.json.rabl b/app/views/katello/api/v2/organizations/show.json.rabl index d984cf9f17d..c640754853a 100644 --- a/app/views/katello/api/v2/organizations/show.json.rabl +++ b/app/views/katello/api/v2/organizations/show.json.rabl @@ -4,7 +4,7 @@ extends "api/v2/taxonomies/show" attributes :task_id, :label, :owner_details, :redhat_repository_url -attributes :service_levels, :service_level if ::Katello.config.use_cp +attributes :service_levels, :service_level if ::SETTINGS[:katello][:use_cp] node :default_content_view_id do |org| org.default_content_view.id diff --git a/config/initializers/runcible.rb b/config/initializers/runcible.rb index 0fb603e4142..2e01a1c0e36 100644 --- a/config/initializers/runcible.rb +++ b/config/initializers/runcible.rb @@ -1,6 +1,6 @@ require 'katello/util/thread_session' -if Katello.config.use_pulp +if SETTINGS[:katello] && SETTINGS[:katello][:use_pulp] # override Runcible's default configuration error message module Runcible diff --git a/config/katello.yaml.example b/config/katello.yaml.example index 4e334083133..cb874d58754 100644 --- a/config/katello.yaml.example +++ b/config/katello.yaml.example @@ -1,22 +1,74 @@ -common: +:katello: + :use_cp: true # set to true/false if you want to override default + :use_pulp: true # set to true/false if you want to override default + :use_elasticsearch: true # set to true/false if you want to override default - rest_client_timeout: 120 + :rest_client_timeout: 30 + :gpg_strict_validation: false - post_sync_url: https://localhost/katello/api/v2/repositories/sync_complete?token=test + :puppet_repo_root: '/etc/puppet/environments/' - candlepin: - url: https://localhost:8443/candlepin - oauth_key: bb5uJCZSUdvRAcrrejP8RC8gYuFXDfr8 - oauth_secret: 4DdSEh7dGkGKC5DGoE4CdWdFXap36Dqa + :elastic_index: katello + :elastic_url: http://localhost:9200 - pulp: - url: https://katello-devel.example.com/pulp/api/v2/ - oauth_key: bb5uJCZSUdvRAcrrejP8RC8gYuFXDfr8 - oauth_secret: 4DdSEh7dGkGKC5DGoE4CdWdFXap36Dqa + :post_sync_url: "http://localhost:3000/katello/api/v2/repositories/sync_complete?token=katello" - qpid: - url: amqp:ssl:katello-devel.example.com:5671 - subscriptions_queue_address: katello_event_queue + :simple_search_tokens: [":", " and\\b", " or\\b", " not\\b"] + + :redhat_repository_url: https://cdn.redhat.com + + :consumer_cert_rpm: 'katello-ca-consumer-latest.noarch.rpm' + + # Setup your candlepin environment here + :candlepin: + # refers to the url of the candlepin + # example https://localhost:8443/candlepin + :url: https://localhost:8443/candlepin + + # Specify your oauth key and secret used to authenticate between Katello and Candlepin + :oauth_key: katello + :oauth_secret: katello + + # refers to the candlepin-ca.crt location that is needed + # to connect to candlepin over https.This is not necessary + # if the candlepin server is running on the same machine as katello + # but required if the server is on a different machine. + # In the different machine case the katello host needs to have a + # copy of /etc/candlepin/certs/candlepin-ca.crt copied from + # the candlepin host and the location of the copied file needs to be + # specified here.. + :ca_cert_file: + + # Setup your pulp environment here + :pulp: + # refers to the url of the pulp + # example https://localhost/pulp/api + :url: https://localhost/pulp/api/v2/ + + # Specify your oauth key and secret used to authenticate between Katello and Pulp + :oauth_key: katello + :oauth_secret: katello + + :sync_threads: 4 + :bulk_load_size: 100 + # refers to the apache certificate + # (typically /etc/pki/tls/certs/localhost.crt) location that is needed + # to connect to pulp over https. + :ca_cert_file: + :default_login: admin + :sync_KBlimit: + :upload_chunk_size: 1048575 # upload size in bytes to pulp. see SSLRenegBufferSize in apache + :skip_checksum_validation: false + + :qpid: + :url: amqp:ssl:katello-devel.example.com:5671 + :subscriptions_queue_address: katello_event_queue + + :cdn_proxy: + # :host: localhost + # :port: 3128 + # :user: login + # :password: password # Logging configuration can be changed by uncommenting the loggers # section and the logger configuration desired. diff --git a/config/katello_defaults.yml b/config/katello_defaults.yml index 1cf15e98300..e69de29bb2d 100644 --- a/config/katello_defaults.yml +++ b/config/katello_defaults.yml @@ -1,94 +0,0 @@ -# This file contains default values for Katello configuration. -# -# DO NOT EDIT THIS FILE -# -# Add `/etc/katello/katello.yml` (or `config/katello.yml` in development) to override default values, -# file is required even if it's blank. - -# Katello configuration -# -# :vim:sw=2:ts=2:et: - -# Common configuration -# -# The following configuration values are the same for production, test -# and development environments. Values can be overridden bellow. -# -common: - use_cp: # set to true/false if you want to override default - use_pulp: # set to true/false if you want to override default - use_elasticsearch: # set to true/false if you want to override default - - rest_client_timeout: 30 - gpg_strict_validation: false - - # Puppet publishing location - puppet_repo_root: '/etc/puppet/environments/' - - elastic_index: katello - elastic_url: http://localhost:9200 - - post_sync_url: "http://localhost:3000/katello/api/v2/repositories/sync_complete?token=katello" - - simple_search_tokens: [":", " and\\b", " or\\b", " not\\b"] - - redhat_repository_url: https://cdn.redhat.com - consumer_cert_rpm: 'katello-ca-consumer-latest.noarch.rpm' - - #setup how often you want - #your notifications to be checked - #for you to receive the right notifications - #default value = 45 seconds - # - notification: - polling_seconds: 120 - - # Setup your candlepin environment here - candlepin: - # refers to the url of the candlepin - # example https://localhost:8443/candlepin - url: https://localhost:8443/candlepin - - # Specify your oauth key and secret used to authenticate between Katello and Candlepin - oauth_key: katello - oauth_secret: katello - - # refers to the candlepin-ca.crt location that is needed - # to connect to candlepin over https.This is not necessary - # if the candlepin server is running on the same machine as katello - # but required if the server is on a different machine. - # In the different machine case the katello host needs to have a - # copy of /etc/candlepin/certs/candlepin-ca.crt copied from - # the candlepin host and the location of the copied file needs to be - # specified here.. - ca_cert_file: - - # Setup your pulp environment here - pulp: - # refers to the url of the pulp - # example https://localhost/pulp/api - url: https://localhost/pulp/api/v2/ - - # Specify your oauth key and secret used to authenticate between Katello and Pulp - oauth_key: katello - oauth_secret: katello - - sync_threads: 4 - bulk_load_size: 100 - # refers to the apache certificate - # (typically /etc/pki/tls/certs/localhost.crt) location that is needed - # to connect to pulp over https. - ca_cert_file: - default_login: admin - sync_KBlimit: - upload_chunk_size: 1048575 # upload size in bytes to pulp. see SSLRenegBufferSize in apache - skip_checksum_validation: false - - # Setup proxy to use when accessing CDN. - # Katello calls CDN to retrieve list of repositories for a product - # Uncomment in case you want this calls to go through your proxy - cdn_proxy: - # host: localhost - # port: 3128 - # user: login - # password: password diff --git a/db/seeds.rb b/db/seeds.rb index b6be811b63f..76dd9c89ce5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -27,7 +27,7 @@ def format_errors(model = nil) ::User.current = ::User.anonymous_api_admin -if Katello.config.use_pulp +if SETTINGS[:katello][:use_pulp] Katello::Repository.ensure_sync_notification end diff --git a/engines/bastion_katello/lib/bastion_katello/engine.rb b/engines/bastion_katello/lib/bastion_katello/engine.rb index d3585a08759..f12ae7e5346 100644 --- a/engines/bastion_katello/lib/bastion_katello/engine.rb +++ b/engines/bastion_katello/lib/bastion_katello/engine.rb @@ -15,6 +15,9 @@ class Engine < ::Rails::Engine end config.to_prepare do + consumer_cert_rpm = 'katello-ca-consumer-latest.noarch.rpm' + consumer_cert_rpm = SETTINGS[:katello][:consumer_cert_rpm] if SETTINGS.key?(:katello) + Bastion.register_plugin( :name => 'bastion_katello', :javascript => 'bastion_katello/bastion_katello', @@ -37,7 +40,7 @@ class Engine < ::Rails::Engine select_organization ), :config => { - 'consumerCertRPM' => Katello.config.consumer_cert_rpm + 'consumerCertRPM' => consumer_cert_rpm } ) end diff --git a/lib/katello.rb b/lib/katello.rb index 793cd7aaad4..c72347ca1b7 100644 --- a/lib/katello.rb +++ b/lib/katello.rb @@ -32,7 +32,5 @@ module Katello require "katello/version" require "katello/tire_bridge" - require "katello/app_config" require "katello/engine" - require "katello/load_configuration" end diff --git a/lib/katello/app_config.rb b/lib/katello/app_config.rb deleted file mode 100644 index ca501a67458..00000000000 --- a/lib/katello/app_config.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Katello - class AppConfigDeprecate - def method_missing(method, *args, &block) - warn "AppConfig is deprecated use Katello.config, called from: #{caller.first}" - Katello.config.__send__ method, *args, &block - end - end -end - -AppConfig = Katello::AppConfigDeprecate.new diff --git a/lib/katello/configuration.rb b/lib/katello/configuration.rb deleted file mode 100644 index d38736c08b0..00000000000 --- a/lib/katello/configuration.rb +++ /dev/null @@ -1,58 +0,0 @@ -module Katello - # Katello::Configuration module contains all necessary code for Katello configuration. - # Configuration is not dependent on any gem which allows loading configuration very early - # (even before Rails). Therefore this configuration can be used anywhere - # (Gemfile, boot scripts, stand-alone) - # - # Configuration access points are methods {Katello.config} and {Katello.early_config}, see method documentation. - # - # Default configuration values are stored in `src/config/katello_defaults.yml`. Default values can be overridden - # in configuration files (`config/katello.yml` or `/etc/katello/katello.yml`) - # - # Configuration is represented with tree-like-structure defined with {Katello::Configuration::Node}. Node has - # minimal Hash-like interface. Node is more strict than Hash. Differences: - # * If undefined key is accessed an error NoKey is raised (keys with nil values has to be - # defined explicitly). - # * Keys can be accessed by methods. `config.host` is equivalent to `config[:host]` - # * All keys has to be Symbols, otherwise you get an ArgumentError - # - # AppConfig will work for now, but warning is printed to `$stderr`. - # - # Some examples - # - # !!!txt - # # create by a Hash which is converted to Node instance - # irb> n = Katello::Configuration::Node.new 'a' => nil - # => # nil}> - # - # # assign a value, also converted - # irb> n[:a] = {'a' => 12} - # => {:a => 12} - # irb> n - # => # # 12}>}> - # - # # accessing a key - # irb> n['a'] - # ArgumentError: "a" should be a Symbol - # irb> n[:a] - # => # 12}> - # irb> n[:not] - # Katello::Configuration::Node::NoKey: missing key 'not' in configuration - # - # # supports deep_merge and #to_hash - # irb> n.deep_merge!('a' => {:b => 34}) - # => # # 12, :b => 34}>}> - # irb> n.to_hash - # => {:a => {:a => 12, :b => 34}} - # - module Configuration - path = File.expand_path(File.join(File.dirname(__FILE__), '..')) - $LOAD_PATH << path unless $LOAD_PATH.include? path - - require 'katello/configuration/node' - require 'katello/configuration/validator' - require 'katello/configuration/loader' - end -end diff --git a/lib/katello/configuration/loader.rb b/lib/katello/configuration/loader.rb deleted file mode 100644 index 6da2c90cc92..00000000000 --- a/lib/katello/configuration/loader.rb +++ /dev/null @@ -1,99 +0,0 @@ -require 'yaml' -require 'erb' - -module Katello - module Configuration - # processes configuration loading from config_files - class Loader - attr_reader :config_file_paths, - :validation, - :default_config_file_path, - :config_post_process, - :load_yml_post_process - - # @param [Hash] options - # @option options [Array] :config_file_paths paths to look for configuration files (first one is used) - # @option options [String] :default_config_file_path path to file with default configuration values - # @option options [Proc] :validation validating the configuration - # @option options [Proc] :config_post_process called on each full configuration after it's constructed - # e.g. to add config[:katello?] = lambda { config.app_mode == 'katello' } - # @option options [Proc] :load_yml_post_process called on each configuration loaded from yaml file - # e.g. to decrypt db password - def initialize(options = {}) - @config_file_paths = options[:config_file_paths] || fail(ArgumentError) - @default_config_file_path = options[:default_config_file_path] || fail(ArgumentError) - @validation = options[:validation] || fail(ArgumentError) - @config_post_process = options[:config_post_process] - @load_yml_post_process = options[:load_yml_post_process] - end - - # raw config data from katello.yml represented with Node - def config_data - @config_data ||= Node.new.tap do |c| - c.deep_merge! default_config_data - c.deep_merge! load_yml_file(config_file_path) - end - end - - # raw config data from katello_defaults.yml represented with Node - def default_config_data - @default_config_data ||= load_yml_file default_config_file_path - end - - # access point for Katello configuration - def config - @config ||= load(environment) - end - - # Configuration without environment applied, use in early stages (before Rails are loaded) - # like Gemfile and other scripts - def early_config - @early_config ||= load - end - - private - - def load(environment = nil) - Node.new.tap do |c| - load_config_file c - config_post_process.call c, environment if config_post_process - validate c, environment - end - end - - def load_yml_file(file_path) - raw_parsed_yml = YAML.load(ERB.new(File.read(file_path)).result(Object.new.send(:binding))) - hash_parsed_yml = case raw_parsed_yml - when Hash - raw_parsed_yml - when nil, false, '' - {} - else - fail "malformed yml file '#{file_path}'" - end - - Node.new(hash_parsed_yml).tap do |config| - load_yml_post_process.call(config) if load_yml_post_process - end - end - - def environment - Rails.env.to_sym rescue raise 'Rails.env is not accessible, try to use #early_config instead' - end - - def load_config_file(config) - config.deep_merge! config_data[:common] - end - - def validate(config, environment) - Validator.new config, environment, &validation - end - - def config_file_path - @config_file_path ||= config_file_paths.find { |path| File.exist? path } - fail "no config file found, candidates: #{config_file_paths.join ' '}" unless @config_file_path - @config_file_path - end - end - end -end diff --git a/lib/katello/configuration/node.rb b/lib/katello/configuration/node.rb deleted file mode 100644 index 24ed18d336c..00000000000 --- a/lib/katello/configuration/node.rb +++ /dev/null @@ -1,133 +0,0 @@ -# rubocop:disable HashMethods -module Katello - module Configuration - # Hash like container for configuration - # @example allows access by method - # Node.new('a' => {:b => 2}).a.b # => 2 - class Node - class NoKey < StandardError - def initialize(message = nil) - #noinspection RubyArgCount - super(" missing key '#{message}' in configuration") - end - end - - def initialize(data = {}) - @data = convert_hash data - end - - include Enumerable - - def each(&block) - @data.each(&block) - end - - # get configuration for `key` - # @param [Symbol, String] key - # @raise [NoKye] when key is missing - def [](key) - key = key.to_s - - if key? key - @data[key].is_a?(Proc) ? @data[key].call : @data[key] - else - fail NoKey, key - end - end - - # converts `value` to Config - # @see #convert - def []=(key, value) - @data[key.to_s] = convert value - end - - def key?(key) - @data.key? key.to_s - end - alias_method :has_key?, :key? - - # @example does node contain value at `node[:key1][:key2]` - # node.present? :key1, :key2 - def present?(*keys) - key, rest = keys.first, keys[1..-1] - fail ArgumentError, 'supply at least one key' unless key - key?(key) && self[key] && if rest.empty? - true - elsif self[key].is_a?(Node) - self[key].present?(*rest) - else - false - end - end - - # allows access keys by method call - # @raise [NoKye] when `key` is missing - def method_missing(method, *args, &block) - if key?(method) - self[method] - else - begin - super - rescue NoMethodError - raise NoKey, method.to_s - end - end - end - - # respond to implementation according to method missing - def respond_to?(method, include_private = false) - key?(method) || super - end - - # does not supports Hashes in Arrays - def deep_merge!(hash_or_config) - return self if hash_or_config.nil? - other_config = convert hash_or_config - other_config.each do |key, other_value| - value = key?(key) && self[key] - self[key] = if value.is_a?(Node) && other_value.is_a?(Node) - value.deep_merge!(other_value) - elsif value.is_a?(Node) && other_value.nil? - self[key] - else - other_value - end - end - self - end - - def to_hash - @data.inject({}) do |hash, (k, v)| - hash.update k => (v.is_a?(Node) ? v.to_hash : v) - end - end - - private - - # converts config like deep structure by finding Hashes deeply and converting them to Config - def convert(obj) - case obj - when Node - obj - when Hash - Node.new convert_hash obj - when Array - obj.map { |o| convert o } - else - obj - end - end - - # converts Hash by symbolizing keys and allowing only symbols as keys - def convert_hash(hash) - fail ArgumentError, "#{hash.inspect} is not a Hash" unless hash.is_a?(Hash) - - hash.keys.each do |key| - hash[key.to_s] = convert hash.delete(key) - end - - hash - end - end - end -end diff --git a/lib/katello/configuration/validator.rb b/lib/katello/configuration/validator.rb deleted file mode 100644 index 520aacb1258..00000000000 --- a/lib/katello/configuration/validator.rb +++ /dev/null @@ -1,73 +0,0 @@ -# rubocop:disable CaseEquality, HashMethods -module Katello - module Configuration - # defines small dsl for validating configuration - class Validator - attr_reader :config, :environment, :path - - # @param [Node] config - # @param [nil, Symbol] environment use nil for early or Symbol for environment - # @yield block with validations - def initialize(config, environment, path = [], &validations) - @config, @environment, @path = config, environment, path - instance_eval(&validations) - end - - private - - def early? - !environment - end - - # validate sub key - # @yield block with validations - def validate(key, &block) - Validator.new config[key] || Node.new, environment, (self.path + [key]), &block - end - - def booleans?(*keys) - keys.each { |key| boolean?(key) } - end - - def boolean?(key) - values?(key, [true, false]) - end - - def type?(key, *types) - unless types.any? { |type| type === config[key] } - fail error_format(key.to_sym, "has to be one of #{types.inspect} types") - end - end - - def values?(key, values, options = {}) - values << nil if options[:allow_nil] - return true if values.include?(config[key]) - fail ArgumentError, error_format(key, "should be one of #{values.inspect}, but was #{config[key].inspect}") - end - - def keys?(*keys) - keys.each { |key| key? key } - end - - def key?(key) - unless config.key? key.to_sym - fail error_format(key.to_sym, 'is required') - end - end - - private - - def error_format(key, message) - key_path = (path + [key]).join('.') - env = environment ? "'#{environment}' environment" : 'early configuration' - "Key: '#{key_path}' in #{env} #{message}" - end - - def not_empty?(key) - if config[key].nil? || config[key].empty? - fail error_format(key.to_sym, "must not be empty") - end - end - end - end -end diff --git a/lib/katello/engine.rb b/lib/katello/engine.rb index 807e9e89a8e..ebd84f71672 100644 --- a/lib/katello/engine.rb +++ b/lib/katello/engine.rb @@ -7,6 +7,40 @@ class Engine < ::Rails::Engine end initializer 'katello.load_default_settings', :before => :load_config_initializers do + default_settings = { + :use_pulp => true, + :use_cp => true, + :use_elasticsearch => true, + :rest_client_timeout => 30, + :gpg_strict_validation => false, + :puppet_repo_root => '/etc/puppet/environments/', + :redhat_repository_url => 'https://cdn.redhat.com', + :post_sync_url => 'http://localhost:3000/katello/api/v2/repositories/sync_complete?token=katello', + :elastic_index => 'katello', + :elastic_url => 'http://localhost:9200', + :simple_search_tokens => [":", " and\\b", " or\\b", " not\\b"], + :consumer_cert_rpm => 'katello-ca-consumer-latest.noarch.rpm', + :pulp => { + :default_login => 'admin', + :url => 'https://localhost/pulp/api/v2/', + :oauth_key => 'katello', + :oauth_secret => 'katello', + :bulk_load_size => 100, + :skip_checksum_validation => false, + :upload_chunk_size => 1_048_575, # upload size in bytes to pulp. see SSLRenegBufferSize in apache + :sync_threads => 4, + :sync_KBlimit => nil + }, + :candlepin => { + :url => 'https://localhost:8443/candlepin', + :oauth_key => 'katello', + :oauth_secret => 'katello', + :ca_cert_file => nil + } + } + + SETTINGS[:katello] = default_settings.deep_merge(SETTINGS[:katello] || {}) + require_dependency File.expand_path('../../../app/models/setting/katello.rb', __FILE__) if (Setting.table_exists? rescue(false)) end @@ -151,7 +185,7 @@ class Engine < ::Rails::Engine require 'katello/plugin' require 'katello/permissions' - Tire::Configuration.url(Katello.config.elastic_url) + Tire::Configuration.url(SETTINGS[:katello][:elastic_url]) bridge = Katello::TireBridge.new(::Foreman::Logging.logger('katello/tire_rest')) Tire.configure { logger bridge, :level => bridge.level } end diff --git a/lib/katello/load_configuration.rb b/lib/katello/load_configuration.rb deleted file mode 100644 index 2e5ba5fb97a..00000000000 --- a/lib/katello/load_configuration.rb +++ /dev/null @@ -1,62 +0,0 @@ -path = File.expand_path(File.join(File.dirname(__FILE__), '..')) -$LOAD_PATH << path unless $LOAD_PATH.include? path - -require 'katello/configuration' -require 'katello/app_config' - -module Katello - # TODO: clean up this method - # rubocop:disable MethodLength, BlockAlignment, HashMethods - # @return [Configuration::Loader] configured for Katello - def self.configuration_loader - root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) - - @configuration_loader ||= Configuration::Loader.new( - :config_file_paths => %W(#{root}/config/katello.yml - #{Rails.root}/config/settings.plugins.d/katello.yaml - /etc/katello/katello.yml), - :default_config_file_path => "#{root}/config/katello_defaults.yml", - - :validation => lambda do |*_| - keys?(*%w(candlepin notification - use_cp simple_search_tokens - use_pulp cdn_proxy - redhat_repository_url - elastic_url rest_client_timeout elastic_index - pulp - consumer_cert_rpm)) - - booleans? :use_cp, :use_pulp, :use_elasticsearch - end, - - :config_post_process => lambda do |config, _environment| - config[:use_cp] = true if config[:use_cp].nil? - config[:use_pulp] = true if config[:use_pulp].nil? - config[:use_elasticsearch] = true if config[:use_elasticsearch].nil? - end) - end - - class << self - delegate :config, :to => :configuration_loader - delegate :early_config, :to => :configuration_loader - end - - def self.can_do_shell_command?(cmd) - system("which #{cmd.to_s} >/dev/null 2>&1") - end - - def self.git_checkout? - can_do_shell_command?(:git) && system("cd #{File.dirname(__FILE__)} && git rev-parse --git-dir >/dev/null 2>&1") - end - - def self.git_commit_hash - hash = `cd #{File.dirname(__FILE__)} && git rev-parse HEAD 2>/dev/null`.chop - $?.exitstatus.zero? ? "git: #{hash}" : N_("Unknown") # rubocop:disable SpecialGlobalVars - end - - def self.rpm_package_name(_config) - package = 'katello' - rpm = `rpm -q #{package} --queryformat '%{VERSION}-%{RELEASE}' 2>&1` - $?.exitstatus.zero? ? rpm : N_("Unknown") # rubocop:disable SpecialGlobalVars - end -end diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb index 748f9fa34e5..c2474f78bdd 100644 --- a/spec/models/gpg_key_spec.rb +++ b/spec/models/gpg_key_spec.rb @@ -41,7 +41,7 @@ module Katello it "should be unsuccessful without proper gpg key" do gpg_key = GpgKey.new(:name => "Gpg Key 1", :content => "foo-bar-baz", :organization => @organization) - if Katello.config.gpg_strict_validation + if SETTINGS[:katello][:gpg_strict_validation] gpg_key.wont_be :valid? else gpg_key.must_be :valid? diff --git a/spec/models/ping_spec.rb b/spec/models/ping_spec.rb index e3d7ac3eadd..7b4a5191b0b 100644 --- a/spec/models/ping_spec.rb +++ b/spec/models/ping_spec.rb @@ -6,10 +6,10 @@ module Katello before do Katello::Ping.unstub(:ping) # candlepin - without oauth - stub_request(:get, "#{Katello.config.candlepin.url}/status") + stub_request(:get, "#{SETTINGS[:katello][:candlepin][:url]}/status") # elastic search - without oauth - stub_request(:get, "#{Katello.config.elastic_url}/_status") + stub_request(:get, "#{SETTINGS[:katello][:elastic_url]}/_status") # candlepin - with oauth Resources::Candlepin::CandlepinPing.stubs(:ping).returns @@ -19,7 +19,7 @@ module Katello subject { Ping.ping[:status] } it "(katello)" do # pulp - without oauth - stub_request(:get, "#{Katello.config.pulp.url}/services/status/") # gotta have that trailing slash + stub_request(:get, "#{SETTINGS[:katello][:pulp][:url]}/services/status/") # gotta have that trailing slash # pulp - with oauth Katello.pulp_server.resources.user.stubs(:retrieve_all).returns([]) diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 2dfacc3179d..140ce7bdb77 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -284,7 +284,7 @@ def set_upstream_releases(product, releases) @provider.name = "url test" @provider.provider_type = Provider::REDHAT @default_url = "http://boo.com" - Katello.config.stubs(:redhat_repository_url).returns(@default_url) + SETTINGS[:katello].stubs(:redhat_repository_url).returns(@default_url) end describe "should accept" do diff --git a/spec/support/deferred_garbage_collection.rb b/spec/support/deferred_garbage_collection.rb deleted file mode 100644 index 4a4ab106297..00000000000 --- a/spec/support/deferred_garbage_collection.rb +++ /dev/null @@ -1,18 +0,0 @@ -class DeferredGarbageCollection - DEFERRED_GC_THRESHOLD = Katello.config.rspec_gc_defer_time.to_f - - @last_gc_run = Time.now - - def self.start - GC.disable if DEFERRED_GC_THRESHOLD > 0 - end - - def self.reconsider - if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD - GC.enable - GC.start - GC.disable - @last_gc_run = Time.now - end - end -end diff --git a/test/actions/candlepin/listen_on_events_test.rb b/test/actions/candlepin/listen_on_events_test.rb index 672278e1137..693362b9ef0 100644 --- a/test/actions/candlepin/listen_on_events_test.rb +++ b/test/actions/candlepin/listen_on_events_test.rb @@ -14,7 +14,7 @@ class Actions::Candlepin::ListenOnCandlepinEventsTest < ActiveSupport::TestCase ::Actions::Candlepin::CandlepinListeningService.stubs(:new).at_least_once action_class.stubs(:connect_listening_service) - Katello.config[:qpid] = {:url => 'url', :subscriptions_queue_address => 'addr'} + SETTINGS[:katello][:qpid] = {:url => 'url', :subscriptions_queue_address => 'addr'} ::Actions::Candlepin::ListenOnCandlepinEvents.any_instance.stubs(:configured?).returns(true) run_action planned_action end diff --git a/test/actions/katello/content_view_test.rb b/test/actions/katello/content_view_test.rb index 40d53c3cd47..fe92630864f 100644 --- a/test/actions/katello/content_view_test.rb +++ b/test/actions/katello/content_view_test.rb @@ -54,7 +54,7 @@ class EnvironmentCreateTest < TestBase end it 'plans' do - Katello::Configuration::Node.any_instance.stubs(:use_cp).returns(true) + SETTINGS[:katello].stubs(:use_cp).returns(true) content_view_environment.expects(:save!) plan_action(action, content_view_environment) content_view = content_view_environment.content_view @@ -75,7 +75,7 @@ class CreateTest < TestBase end it 'plans' do - Katello::Configuration::Node.any_instance.stubs(:use_elasticsearch).returns(true) + SETTINGS[:katello].stubs(:use_elasticsearch).returns(true) content_view.expects(:save!) plan_action(action, content_view) end diff --git a/test/actions/katello/foreman_test.rb b/test/actions/katello/foreman_test.rb index f115e691d00..5348a1d1a57 100644 --- a/test/actions/katello/foreman_test.rb +++ b/test/actions/katello/foreman_test.rb @@ -25,8 +25,8 @@ class Actions::Katello::Foreman::ContentUpdateTest < ActiveSupport::TestCase action.input.must_equal("environment_id" => environment.id, "content_view_id" => content_view.id, "repository_id" => nil, - "remote_user" => Katello.config.pulp.default_login, - "remote_cp_user" => Katello.config.pulp.default_login) + "remote_user" => SETTINGS[:katello][:pulp][:default_login], + "remote_cp_user" => SETTINGS[:katello][:pulp][:default_login]) end it 'updates the foreman content' do diff --git a/test/controllers/api/v2/repositories_controller_test.rb b/test/controllers/api/v2/repositories_controller_test.rb index 71d53d7ebeb..6f8c7443d31 100644 --- a/test/controllers/api/v2/repositories_controller_test.rb +++ b/test/controllers/api/v2/repositories_controller_test.rb @@ -477,7 +477,7 @@ def test_sync def test_sync_complete token = 'imalittleteapotshortandstout' - Katello.config[:post_sync_url] = "http://foo.com/foo?token=#{token}" + SETTINGS[:katello][:post_sync_url] = "http://foo.com/foo?token=#{token}" Repository.stubs(:where).returns([@repository]) assert_async_task ::Actions::Katello::Repository::Sync do |repo, task_id| @@ -493,7 +493,7 @@ def test_sync_complete def test_sync_complete_bad_token token = 'super_secret' - Katello.config[:post_sync_url] = "http://foo.com/foo?token=attacker_key" + SETTINGS[:katello][:post_sync_url] = "http://foo.com/foo?token=attacker_key" post :sync_complete, :token => token, :payload => {:repo_id => @repository.pulp_id}, :call_report => {} assert_response 403 diff --git a/test/fixtures/vcr_cassettes/elasticsearch/package.yml b/test/fixtures/vcr_cassettes/elasticsearch/package.yml index 25b9c4ec9ae..da4bb5efa63 100644 --- a/test/fixtures/vcr_cassettes/elasticsearch/package.yml +++ b/test/fixtures/vcr_cassettes/elasticsearch/package.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: delete - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -29,7 +29,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:57 GMT - request: method: post - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: UTF-8 string: "{\"settings\":{\"index\":{\"analysis\":{\"filter\":{\"ngram_filter\":{\"type\":\"edgeNGram\",\"side\":\"front\",\"min_gram\":1,\"max_gram\":30}},\"analyzer\":{\"kt_name_analyzer\":{\"type\":\"custom\",\"tokenizer\":\"keyword\"},\"autcomplete_name_analyzer\":{\"type\":\"custom\",\"tokenizer\":\"keyword\",\"filter\":[\"standard\",\"lowercase\",\"ngram_filter\"]}}}}},\"mappings\":{\"package\":{\"properties\":{\"id\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"name\":{\"type\":\"string\",\"analyzer\":\"kt_name_analyzer\"},\"name_autocomplete\":{\"type\":\"string\",\"analyzer\":\"autcomplete_name_analyzer\"},\"nvrea_autocomplete\":{\"type\":\"string\",\"analyzer\":\"autcomplete_name_analyzer\"},\"nvrea\":{\"type\":\"string\",\"analyzer\":\"kt_name_analyzer\"},\"nvrea_sort\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"nvra\":{\"type\":\"string\",\"analyzer\":\"kt_name_analyzer\"},\"filename\":{\"type\":\"string\",\"analyzer\":\"kt_name_analyzer\"},\"nvra_sort\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"repoids\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"sortable_version\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"sortable_release\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}}}" @@ -58,7 +58,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:57 GMT - request: method: post - uri: http://localhost:9200/katello_package/_bulk + uri: http://localhost:9200/katello_test_package/_bulk body: encoding: UTF-8 string: | @@ -104,7 +104,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: post - uri: http://localhost:9200/katello_package/_refresh + uri: http://localhost:9200/katello_test_package/_refresh body: encoding: ASCII-8BIT string: "" @@ -133,7 +133,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -160,7 +160,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -250,7 +250,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -277,7 +277,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -367,7 +367,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: post - uri: http://localhost:9200/katello_package/_bulk + uri: http://localhost:9200/katello_test_package/_bulk body: encoding: UTF-8 string: | @@ -413,7 +413,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: post - uri: http://localhost:9200/katello_package/_refresh + uri: http://localhost:9200/katello_test_package/_refresh body: encoding: ASCII-8BIT string: "" @@ -442,7 +442,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -469,7 +469,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -543,7 +543,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -570,7 +570,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -644,7 +644,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -671,7 +671,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -761,7 +761,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -788,7 +788,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -878,7 +878,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: post - uri: http://localhost:9200/katello_package/_bulk + uri: http://localhost:9200/katello_test_package/_bulk body: encoding: UTF-8 string: | @@ -924,7 +924,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: post - uri: http://localhost:9200/katello_package/_refresh + uri: http://localhost:9200/katello_test_package/_refresh body: encoding: ASCII-8BIT string: "" @@ -953,7 +953,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -980,7 +980,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -1039,7 +1039,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: post - uri: http://localhost:9200/katello_package/_bulk + uri: http://localhost:9200/katello_test_package/_bulk body: encoding: UTF-8 string: | @@ -1085,7 +1085,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: post - uri: http://localhost:9200/katello_package/_refresh + uri: http://localhost:9200/katello_test_package/_refresh body: encoding: ASCII-8BIT string: "" @@ -1114,7 +1114,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -1141,7 +1141,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -1242,7 +1242,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -1269,7 +1269,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | @@ -1370,7 +1370,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: head - uri: http://localhost:9200/katello_package + uri: http://localhost:9200/katello_test_package body: encoding: US-ASCII string: "" @@ -1397,7 +1397,7 @@ http_interactions: recorded_at: Thu, 05 Jun 2014 19:58:58 GMT - request: method: get - uri: http://localhost:9200/katello_package/_search?from=0&size=8 + uri: http://localhost:9200/katello_test_package/_search?from=0&size=8 body: encoding: UTF-8 string: | diff --git a/test/katello_test_helper.rb b/test/katello_test_helper.rb index 501d8e4056e..4b79f001359 100644 --- a/test/katello_test_helper.rb +++ b/test/katello_test_helper.rb @@ -31,6 +31,8 @@ FactoryGirl.definition_file_paths = ["#{Katello::Engine.root}/test/factories"] FactoryGirl.find_definitions +SETTINGS[:katello][:elastic_index] = 'katello_test' + module MiniTest::Expectations infect_an_assertion :assert_redirected_to, :must_redirect_to infect_an_assertion :assert_template, :must_render_template diff --git a/test/models/authorization/authorization_base.rb b/test/models/authorization/authorization_base.rb index 7432335d175..6e5609e5fad 100644 --- a/test/models/authorization/authorization_base.rb +++ b/test/models/authorization/authorization_base.rb @@ -5,7 +5,6 @@ class AuthorizationTestBase < ActiveSupport::TestCase include Katello::AuthorizationSupportMethods def setup - Katello.config[:warden] = 'database' @no_perms_user = User.find(users(:restricted)) @admin = User.find(users(:admin)) @acme_corporation = get_organization diff --git a/test/source_code_test.rb b/test/source_code_test.rb index a4bf35bf487..27b92b08343 100644 --- a/test/source_code_test.rb +++ b/test/source_code_test.rb @@ -82,11 +82,7 @@ def self.token_is_keyword?(str, lex, index, token) %r{test/support/runcible\.rb}, %r{test/katello_test_runner\.rb}, # TODO: clean up minitest_helper %r{app/services/katello/authentication/client_authentication\.rb}, - %r{lib/util/puppet\.rb}). - check_lines(<<-DOC) { |line| (line !~ /ENV\[[^\]]+\]/) ? true : line =~ /#\s?ok/ } -Katello.config or Katello.early_config should be always used instead of ENV variables, Katello.config is -the single entry point to configuration. ENV variables are processed there. - DOC + %r{lib/util/puppet\.rb}) end end diff --git a/test/support/runcible.rb b/test/support/runcible.rb index 6ea46672f6e..1deeec6db9d 100644 --- a/test/support/runcible.rb +++ b/test/support/runcible.rb @@ -1,12 +1,12 @@ def configure_runcible - if Katello.config[:use_pulp] - uri = URI.parse(Katello.config.pulp.url) + if SETTINGS[:katello][:use_pulp] + uri = URI.parse(SETTINGS[:katello][:pulp][:url]) runcible_config = { :url => "#{uri.scheme}://#{uri.host}", :api_path => uri.path, :user => "admin", - :oauth => {:oauth_secret => Katello.config.pulp.oauth_secret, - :oauth_key => Katello.config.pulp.oauth_key } + :oauth => {:oauth_secret => SETTINGS[:katello][:pulp][:oauth_secret], + :oauth_key => SETTINGS[:katello][:pulp][:oauth_key] } } runcible_config[:logger] = 'stdout' if ENV['logging'] == "true" diff --git a/test/support/vcr.rb b/test/support/vcr.rb index 0ff2b013e02..ccb5124b46d 100644 --- a/test/support/vcr.rb +++ b/test/support/vcr.rb @@ -55,7 +55,7 @@ def configure_vcr c.hook_into :webmock if ENV['record'] == "false" && mode != :none - uri = URI.parse(Katello.config.pulp.url) + uri = URI.parse(SETTINGS[:katello][:pulp][:url]) c.ignore_hosts uri.host end