Class: Katello::Pulp3::AlternateContentSource

Inherits:
Object
  • Object
show all
Includes:
ServiceCommon
Defined in:
app/services/katello/pulp3/alternate_content_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ServiceCommon

#create_test_remote, #ignore_404_exception, #reformat_api_exception, #test_remote_name

Constructor Details

#initialize(acs, smart_proxy, repository = nil) ⇒ AlternateContentSource

Returns a new instance of AlternateContentSource.



10
11
12
13
14
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 10

def initialize(acs, smart_proxy, repository = nil)
  @acs = acs
  @smart_proxy = smart_proxy
  @repository = repository
end

Instance Attribute Details

#acsObject

Returns the value of attribute acs.



6
7
8
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 6

def acs
  @acs
end

#repositoryObject

Returns the value of attribute repository.



8
9
10
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 8

def repository
  @repository
end

#smart_proxyObject

Returns the value of attribute smart_proxy.



7
8
9
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 7

def smart_proxy
  @smart_proxy
end

Instance Method Details

#apiObject



16
17
18
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 16

def api
  @api ||= ::Katello::Pulp3::Repository.api(smart_proxy, @acs.content_type)
end

#createObject



100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 100

def create
  if smart_proxy_acs&.alternate_content_source_href.nil?
    paths = acs.subpaths.deep_dup
    if acs.content_type == ::Katello::Repository::FILE_TYPE && acs.subpaths.present?
      paths = insert_pulp_manifest!(paths)
    end
    response = api.alternate_content_source_api.create(name: generate_backend_object_name, paths: paths,
                                                       remote: smart_proxy_acs.remote_href)
    smart_proxy_acs.update!(alternate_content_source_href: response.pulp_href)
    return response
  end
end

#create_remoteObject



78
79
80
81
82
83
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 78

def create_remote
  if smart_proxy_acs&.remote_href.nil?
    response = super
    smart_proxy_acs.update!(remote_href: response.pulp_href)
  end
end

#delete_alternate_content_sourceObject



126
127
128
129
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 126

def delete_alternate_content_source
  href = smart_proxy_acs.alternate_content_source_href
  ignore_404_exception { api.alternate_content_source_api.delete(href) } if href
end

#delete_remote(options = {}) ⇒ Object

The old repo URL is needed to determine which remote API to use.



94
95
96
97
98
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 94

def delete_remote(options = {})
  options[:href] ||= smart_proxy_acs.remote_href
  options[:old_url] ||= remote_options[:url]
  ignore_404_exception { options[:old_url]&.start_with?('uln') ? api.remotes_uln_api.delete(options[:href]) : api.remotes_api.delete(options[:href]) } if options[:href]
end

#generate_backend_object_nameObject



20
21
22
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 20

def generate_backend_object_name
  "#{acs.label}-#{smart_proxy.url}-#{rand(9999)}"
end

#get_remote(href = smart_proxy_acs.remote_href) ⇒ Object



85
86
87
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 85

def get_remote(href = smart_proxy_acs.remote_href)
  acs.base_url&.start_with?('uln') ? api.remotes_uln_api.read(href) : api.remotes_api.read(href)
end

#read(href = smart_proxy_acs.alternate_content_source_href) ⇒ Object



113
114
115
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 113

def read(href = smart_proxy_acs.alternate_content_source_href)
  api.alternate_content_source_api.read(href)
end

#refreshObject



131
132
133
134
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 131

def refresh
  href = smart_proxy_acs.alternate_content_source_href
  api.alternate_content_source_api.refresh(href)
end

#remote_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 48

def remote_options
  return simplified_acs_remote_options if repository.present?

  remote_options = {
    tls_validation: acs.verify_ssl,
    name: generate_backend_object_name,
    url: acs.base_url,
    policy: 'on_demand',
    proxy_url: smart_proxy.http_proxy&.url,
    proxy_username: smart_proxy.http_proxy&.username,
    proxy_password: smart_proxy.http_proxy&.password,
    total_timeout: Setting[:sync_connect_timeout]
  }
  if acs.content_type == ::Katello::Repository::FILE_TYPE && acs.subpaths.empty? && !remote_options[:url].end_with?('/PULP_MANIFEST')
    remote_options[:url] = acs.base_url + '/PULP_MANIFEST'
  end
  remote_options.merge!(username: acs&.upstream_username, password: acs&.upstream_password)
  remote_options.merge!(ssl_remote_options)
end

#simplified_acs_remote_optionsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 32

def simplified_acs_remote_options
  options = repository.backend_service(smart_proxy).remote_options
  options[:policy] = 'on_demand'
  # Potential RFE: allow inheriting of default smart proxy repo's HTTP proxies for simplified ACSs
  if acs.use_http_proxies
    options[:proxy_url] = smart_proxy.http_proxy&.url
    options[:proxy_username] = smart_proxy.http_proxy&.username
    options[:proxy_password] = smart_proxy.http_proxy&.password
  else
    options[:proxy_url] = nil
    options[:proxy_username] = nil
    options[:proxy_password] = nil
  end
  options
end

#smart_proxy_acsObject



24
25
26
27
28
29
30
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 24

def smart_proxy_acs
  if %w[custom rhui].include?(acs.alternate_content_source_type)
    ::Katello::SmartProxyAlternateContentSource.find_by(alternate_content_source_id: acs.id, smart_proxy_id: smart_proxy.id)
  else
    ::Katello::SmartProxyAlternateContentSource.find_by(alternate_content_source_id: acs.id, smart_proxy_id: smart_proxy.id, repository_id: repository.id)
  end
end

#ssl_remote_optionsObject



68
69
70
71
72
73
74
75
76
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 68

def ssl_remote_options
  if acs.custom? || acs.rhui?
    {
      client_cert: acs.ssl_client_cert&.content,
      client_key: acs.ssl_client_key&.content,
      ca_cert: acs.ssl_ca_cert&.content
    }
  end
end

#updateObject



117
118
119
120
121
122
123
124
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 117

def update
  href = smart_proxy_acs.alternate_content_source_href
  paths = acs.subpaths.deep_dup
  if acs.content_type == ::Katello::Repository::FILE_TYPE && acs.subpaths.present?
    paths = insert_pulp_manifest!(paths)
  end
  api.alternate_content_source_api.update(href, name: generate_backend_object_name, paths: paths, remote: smart_proxy_acs.remote_href)
end

#update_remoteObject



89
90
91
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 89

def update_remote
  api.remotes_api.partial_update(smart_proxy_acs.remote_href, remote_options)
end