Skip to content

Commit

Permalink
Fixes #32835 - Add RHSM and content URL as info providers
Browse files Browse the repository at this point in the history
This introduces two Smart Proxy extension methods and exposes them as
info providers. This allows clients to use the ENC API to (re)configure
subscription-manager.

First of all, this implements logic to determine the RHSM URL. This is
constructed by looking at Pulp. While this is really the wrong way,
there is currently no alternative.

Ideally this would be exposed as a setting as well. There is a plan to
align everything on port 443. If the Smart Proxy exposes a setting,
Katello doesn't need to guess and a smooth migration can be realized.

This all becomes more important when the host subscription RPM is phased
out.

Then it also introduces pulp_content_url which is already a setting
that's exposed via the Smart Proxy Pulp feature. This is also used in
the various places where it's needed.

It does highlight a missing setting for pulp_ansible content. Again,
Katello should not have to guess URLs but discover it from the
infrastructure.

Another potential use case that this allows is using REX to move a host
from one content source to another.
  • Loading branch information
ekohl committed Jun 18, 2021
1 parent 2a9c018 commit 6fa02c5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
10 changes: 4 additions & 6 deletions app/helpers/katello/katello_urls_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,16 @@ def subscription_manager_configuration_url(host = nil, rpm = true, hostname: nil
end
def repository_url(content_path, _content_type = nil, schema = 'http')
return content_path if content_path =~ %r|^([\w\-\+]+)://|
url = if @host.content_source
"#{schema}://#{@host.content_source.hostname}"
else
foreman_settings_url(schema)
end

url = @host.content_source.pulp_content_url
url.schema = schema
content_path = content_path.sub(%r|^/|, '')
if @host.content_view && !@host.content_view.default?
content_path = [@host.content_view.label, content_path].join('/')
end
path = ::Katello::Glue::Pulp::Repos.repo_path_from_content_path(
@host.lifecycle_environment, content_path)
"#{url}/pulp/content/#{path}"
"#{url}/#{path}"
end
end
end
2 changes: 1 addition & 1 deletion app/lib/katello/resources/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def load_class

# Pulp 3 has its own registry
if pulp_primary&.pulp3_repository_type_support?(::Katello::Repository::DOCKER_TYPE)
uri = URI(pulp_primary.setting(SmartProxy::PULP3_FEATURE, 'content_app_url'))
uri = URI(pulp_primary.pulp_content_url)
uri.path = "/pulpcore_registry/"
registry_url = uri.to_s

Expand Down
14 changes: 14 additions & 0 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,25 @@ def container_gateway_users
::User.where(login: usernames['users'])
end

def rhsm_url
# TODO: We shouldn't relate this to the Pulp feature and also expose it
# as a setting
if pulp_mirror?
"https://#{URI.parse(url).host}:8443/rhsm"
elsif pulp_primary?
"https://#{URI.parse(url).host}/rhsm"
end
end

def pulp_url
uri = URI.parse(url)
"#{uri.scheme}://#{uri.host}/pulp/api/v2/"
end

def pulp_content_url
setting(SmartProxy::PULP3_FEATURE, 'content_app_url')
end

def pulp_api
@pulp_api ||= Katello::Pulp::Server.config(pulp_url, User.remote_user)
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/katello/host/info_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def host_info
if host.content_facet.present?
info['parameters']['kickstart_repository'] = host.content_facet.kickstart_repository.try(:label)
end

if (rhsm_url = host.content_source&.rhsm_url)
host['rhsm_url'] = rhsm_url
end

if (content_url = host.content_source&.pulp_content_url)
host['content_url'] = content_url
end

info
end

Expand Down
16 changes: 10 additions & 6 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,21 @@ def group
end

def full_path(smart_proxy = nil, force_http = false)
pulp_uri = URI.parse(smart_proxy ? smart_proxy.url : ::SmartProxy.pulp_primary.url)
scheme = force_http ? 'http' : 'https'
smart_proxy ||= ::SmartProxy.pulp_primary
pulp_uri = URI.parse(smart_proxy.pulp_content_url)
pulp_uri.scheme = force_http ? 'http' : 'https'
# TODO: this should be normalized in smart_proxy_pulp's setting
pulp_uri.host = pulp_uri.host.downcase
if docker?
"#{pulp_uri.host.downcase}/#{container_repository_name}"
"#{pulp_uri.host}/#{container_repository_name}"
elsif ostree?
"#{scheme}://#{pulp_uri.host.downcase}/pulp/content/web/#{relative_path}"
pulp_uri.path += "/web/#{relative_path}"
elsif ansible_collection?
"#{scheme}://#{pulp_uri.host.downcase}/pulp_ansible/galaxy/#{relative_path}/api"
pulp_uri.path = "/pulp_ansible/galaxy/#{relative_path}/api"
else
"#{scheme}://#{pulp_uri.host.downcase}/pulp/content/#{relative_path}/"
pulp_uri.path += "/#{relative_path}"
end
pulp_uri.to_s
end

def to_hash(content_source = nil, force_http = false)
Expand Down
1 change: 1 addition & 0 deletions app/services/katello/pulp/repository/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def generate_mirror_importer
end

def partial_repo_path
# TODO: get /pulp/content from pulp_content_url
"/pulp/content/#{repo.relative_path}/".sub('//', '/')
end

Expand Down
1 change: 1 addition & 0 deletions app/services/katello/pulp3/repository/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def self.distribution_bootable?(distribution)
end

def partial_repo_path
# TODO: get /pulp/content from pulp_content_url
"/pulp/content/#{repo.relative_path}/".sub('//', '/')
end

Expand Down

0 comments on commit 6fa02c5

Please sign in to comment.