diff --git a/app/controllers/katello/concerns/api/v2/registration_controller_extensions.rb b/app/controllers/katello/concerns/api/v2/registration_controller_extensions.rb index 51bef441581..235b1a5151b 100644 --- a/app/controllers/katello/concerns/api/v2/registration_controller_extensions.rb +++ b/app/controllers/katello/concerns/api/v2/registration_controller_extensions.rb @@ -24,6 +24,31 @@ def host_setup_extension super end + + def context_urls + super.merge(rhsm_url: rhsm_url, pulp_content_url: pulp_content_url) + end + + private + + def smart_proxy + @smart_proxy ||= begin + proxy = params[:url] ? SmartProxy.find_by(url: params[:url]) : SmartProxy.pulp_primary + + fail Foreman::Exception, N_('Smart proxy content source not found!') unless proxy + fail Foreman::Exception, N_('Pulp 3 is not enabled on Smart proxy!') unless proxy.pulp3_enabled? + + proxy + end + end + + def rhsm_url + URI(smart_proxy.rhsm_url) + end + + def pulp_content_url + smart_proxy.setting(SmartProxy::PULP3_FEATURE, 'content_app_url') + end end end end diff --git a/app/models/katello/concerns/smart_proxy_extensions.rb b/app/models/katello/concerns/smart_proxy_extensions.rb index cd8b8d122ba..1ec26be50bc 100644 --- a/app/models/katello/concerns/smart_proxy_extensions.rb +++ b/app/models/katello/concerns/smart_proxy_extensions.rb @@ -401,6 +401,14 @@ def repos_pending_sync(environment = nil, content_view = nil) def smart_proxy_service @smart_proxy_service ||= Pulp::SmartProxyRepository.new(self) end + + def rhsm_url + if pulp_primary? + "https://#{URI.parse(url).host}/rhsm" + elsif pulp_mirror? + "https://#{URI.parse(url).host}:8443/rhsm" + end + end end end end diff --git a/test/models/concerns/smart_proxy_extensions_test.rb b/test/models/concerns/smart_proxy_extensions_test.rb index 37e307bd008..8c34fd845e3 100644 --- a/test/models/concerns/smart_proxy_extensions_test.rb +++ b/test/models/concerns/smart_proxy_extensions_test.rb @@ -58,6 +58,15 @@ def test_save_with_organization_location assert_equal @proxy.lifecycle_environments.all, Katello::KTEnvironment.all assert_equal @proxy_mirror.lifecycle_environments.all.count, 0 end + + def test_rhsm_url_pulp_primary + assert_includes @proxy.rhsm_url, "/rhsm" + assert_not_includes @proxy.rhsm_url, ":8443" + end + + def test_rhsm_url_pulp_mirror + assert_includes @proxy_mirror.rhsm_url, ":8443/rhsm" + end end class SmartProxyPulp3Test < ActiveSupport::TestCase