Skip to content

Commit

Permalink
Fixes #10621: Refactor to use SETTINGS instead of Katello.config
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Oct 13, 2015
1 parent a14a523 commit 5582ee9
Show file tree
Hide file tree
Showing 78 changed files with 280 additions and 742 deletions.
2 changes: 1 addition & 1 deletion app/controllers/katello/api/v2/repositories_controller.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/katello/application_controller.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/katello/application_helper.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/katello/katello_urls_helper.rb
Expand Up @@ -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
10 changes: 5 additions & 5 deletions app/lib/actions/candlepin/listen_on_candlepin_events.rb
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/activation_key/create.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/content_view/environment_create.rb
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/organization/create.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/organization/destroy.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/lib/actions/katello/product/update.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/katello/repository/destroy.rb
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions app/lib/actions/katello/repository/discover.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/lib/actions/katello/repository/update.rb
Expand Up @@ -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,
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions app/lib/actions/katello/system/auto_attach_subscriptions.rb
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/lib/actions/katello/system/update.rb
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions app/lib/actions/pulp/repository/sync.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/pulp/repository/upload_file.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/lib/katello/http_resource.rb
Expand Up @@ -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.
Expand Down
24 changes: 12 additions & 12 deletions app/lib/katello/resources/candlepin.rb
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/lib/katello/resources/cdn.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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:"
Expand Down
14 changes: 7 additions & 7 deletions app/lib/katello/util/thread_session.rb
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/models/katello/activation_key.rb
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/models/katello/concerns/organization_extensions.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/concerns/user_extensions.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/katello/content_view_environment.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/content_view_erratum_filter_rule.rb
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/content_view_history.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/content_view_package_filter_rule.rb
Expand Up @@ -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",
Expand Down

0 comments on commit 5582ee9

Please sign in to comment.