diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1a9cb3fdaee..9fc2fbe132b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -122,13 +122,6 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 14 -# Offense count: 875 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 200 - # Offense count: 23 # Configuration parameters: CountComments. Metrics/ModuleLength: diff --git a/app/lib/katello/resources/registry.rb b/app/lib/katello/resources/registry.rb index 8c88b72568c..cbe08cad827 100644 --- a/app/lib/katello/resources/registry.rb +++ b/app/lib/katello/resources/registry.rb @@ -12,22 +12,38 @@ def self.logger def self.get(path, headers = {:accept => :json}) logger.debug "Sending GET request to Registry: #{path}" - client = RegistryResource.rest_client(Net::HTTP::Get, :get, path) + client = RegistryResource.load_class.rest_client(Net::HTTP::Get, :get, path) client.get(headers) end end class RegistryResource < HttpResource - if SETTINGS[:katello][:container_image_registry] - cfg = SETTINGS[:katello][:container_image_registry] - url = cfg[:crane_url] - uri = URI.parse(url) - self.prefix = uri.path - self.site = "#{uri.scheme}://#{uri.host}:#{uri.port}" - self.ca_cert_file = cfg[:crane_ca_cert_file] - end + extend Concerns::SmartProxyExtensions class << self + def load_class + container_config = SETTINGS.dig(:katello, :container_image_registry) + registry_url = nil + + if container_config + crane_url = container_config[:crane_url] + pulp_registry_url = container_config[:pulp_registry_url] + registry_url = crane_url if crane_url + # pulp 3 acts as its own registry + if pulp_registry_url && content_pulp3_support?(::Katello::DockerBlob::CONTENT_TYPE) + registry_url = pulp_registry_url + end + end + + logger.send(:error, "No container registry url specified") unless registry_url + + uri = URI.parse(registry_url) + self.prefix = uri.path + self.site = "#{uri.scheme}://#{uri.host}:#{uri.port}" + self.ca_cert_file = container_config[:registry_ca_cert_file] + self + end + def process_response(response) debug_level = response.code >= 400 ? :error : :debug logger.send(debug_level, "Registry request returned with code #{response.code}") diff --git a/test/lib/resources/registry_test.rb b/test/lib/resources/registry_test.rb new file mode 100644 index 00000000000..6465dc739bc --- /dev/null +++ b/test/lib/resources/registry_test.rb @@ -0,0 +1,26 @@ +require 'katello_test_helper' + +module Katello + module Resources + class RegistryTest < ActiveSupport::TestCase + before do + SETTINGS[:katello][:container_image_registry] = { + crane_url: "https://localhost:5000", + pulp_registry_url: "http://localhost:24816" + } + end + + def test_pulp3_registry_url + Registry::RegistryResource.expects(:content_pulp3_support?).returns(true) + pulp_registry_url = SETTINGS[:katello][:container_image_registry][:pulp_registry_url] + assert_equal Registry::RegistryResource.load_class.site, pulp_registry_url + end + + def test_crane_registry_url + Registry::RegistryResource.expects(:content_pulp3_support?).returns(false) + crane_url = SETTINGS[:katello][:container_image_registry][:crane_url] + assert_equal Registry::RegistryResource.load_class.site, crane_url + end + end + end +end