Class: Katello::Pulp3::AlternateContentSource
- Inherits:
-
Object
- Object
- Katello::Pulp3::AlternateContentSource
show all
- Includes:
- ServiceCommon
- Defined in:
- app/services/katello/pulp3/alternate_content_source.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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.
8
9
10
11
12
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 8
def initialize(acs, smart_proxy, repository = nil)
@acs = acs
@smart_proxy = smart_proxy
@repository = repository
end
|
Instance Attribute Details
#acs ⇒ Object
Returns the value of attribute acs.
6
7
8
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 6
def acs
@acs
end
|
#repository ⇒ Object
Returns the value of attribute repository.
6
7
8
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 6
def repository
@repository
end
|
#smart_proxy ⇒ Object
Returns the value of attribute smart_proxy.
6
7
8
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 6
def smart_proxy
@smart_proxy
end
|
Instance Method Details
#api ⇒ Object
14
15
16
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 14
def api
@api ||= ::Katello::Pulp3::Repository.api(smart_proxy, @acs.content_type)
end
|
#create ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 119
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.sort,
remote: smart_proxy_acs.remote_href)
smart_proxy_acs.update!(alternate_content_source_href: response.pulp_href, alternate_content_source_prn: response.prn)
return response
end
end
|
#create_remote ⇒ Object
97
98
99
100
101
102
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 97
def create_remote
if smart_proxy_acs&.remote_href.nil?
response = super
smart_proxy_acs.update!(remote_href: response.pulp_href, remote_prn: response.prn)
end
end
|
#delete_alternate_content_source ⇒ Object
147
148
149
150
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 147
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
114
115
116
117
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 114
def delete_remote(options = {})
options[:href] ||= smart_proxy_acs.remote_href
ignore_404_exception { api.get_remotes_api(href: options[:href]).delete(options[:href]) } if options[:href]
end
|
#generate_backend_object_name ⇒ Object
29
30
31
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 29
def generate_backend_object_name
"#{acs.label}-#{smart_proxy.url}-#{rand(9999)}"
end
|
#get_remote(href = smart_proxy_acs.remote_href) ⇒ Object
104
105
106
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 104
def get_remote(href = smart_proxy_acs.remote_href)
api.get_remotes_api(href: href).read(href)
end
|
#join_space_or_nil(value) ⇒ Object
18
19
20
21
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 18
def join_space_or_nil(value)
vals = Array(value).map(&:to_s).map(&:strip).reject(&:blank?)
vals.empty? ? nil : vals.join(' ')
end
|
#join_space_required!(field, value) ⇒ Object
23
24
25
26
27
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 23
def join_space_required!(field, value)
s = join_space_or_nil(value)
fail ::Katello::Errors::Pulp3Error, "Debian ACS requires '#{field}' to be a non-empty string" if s.nil?
s
end
|
#read(href = smart_proxy_acs.alternate_content_source_href) ⇒ Object
132
133
134
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 132
def read(href = smart_proxy_acs.alternate_content_source_href)
api.alternate_content_source_api.read(href)
end
|
#refresh ⇒ Object
152
153
154
155
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 152
def refresh
href = smart_proxy_acs.alternate_content_source_href
api.alternate_content_source_api.refresh(href)
end
|
#remote_options ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 57
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.deb?
remote_options[:distributions] = join_space_required!('deb_releases', acs.deb_releases)
remote_options[:components] = join_space_or_nil(acs.deb_components)
remote_options[:architectures] = join_space_or_nil(acs.deb_architectures)
end
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
unless acs.use_http_proxies
remote_options[:proxy_url] = nil
remote_options[:proxy_username] = nil
remote_options[:proxy_password] = nil
end
remote_options.merge!(username: acs&.upstream_username, password: acs&.upstream_password)
remote_options.merge!(ssl_remote_options)
end
|
#simplified_acs_remote_options ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 41
def simplified_acs_remote_options
options = repository.backend_service(smart_proxy).remote_options
options[:policy] = 'on_demand'
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_acs ⇒ Object
33
34
35
36
37
38
39
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 33
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_options ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 87
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
|
#update ⇒ Object
136
137
138
139
140
141
142
143
144
145
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 136
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
response = api.alternate_content_source_api.update(href, name: generate_backend_object_name, paths: paths.sort, remote: smart_proxy_acs.remote_href)
response if response.respond_to?(:task) && response.task.present?
end
|
#update_remote(href = smart_proxy_acs.remote_href) ⇒ Object
108
109
110
111
112
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 108
def update_remote(href = smart_proxy_acs.remote_href)
response = api.get_remotes_api(href: href).partial_update(href, remote_options)
response if response.respond_to?(:task) && response.task.present?
end
|