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
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 101
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
81
82
83
84
85
86
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 81
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
127
128
129
130
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 127
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
96
97
98
99
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 96
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
18
19
20
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 18
def generate_backend_object_name
"#{acs.label}-#{smart_proxy.url}-#{rand(9999)}"
end
|
#get_remote(href = smart_proxy_acs.remote_href) ⇒ Object
88
89
90
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 88
def get_remote(href = smart_proxy_acs.remote_href)
api.get_remotes_api(href: href).read(href)
end
|
#read(href = smart_proxy_acs.alternate_content_source_href) ⇒ Object
114
115
116
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 114
def read(href = smart_proxy_acs.alternate_content_source_href)
api.alternate_content_source_api.read(href)
end
|
#refresh ⇒ Object
132
133
134
135
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 132
def refresh
href = smart_proxy_acs.alternate_content_source_href
api.alternate_content_source_api.refresh(href)
end
|
#remote_options ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 46
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
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 30
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
22
23
24
25
26
27
28
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 22
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
71
72
73
74
75
76
77
78
79
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 71
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
118
119
120
121
122
123
124
125
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 118
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.sort, remote: smart_proxy_acs.remote_href)
end
|
#update_remote(href = smart_proxy_acs.remote_href) ⇒ Object
92
93
94
|
# File 'app/services/katello/pulp3/alternate_content_source.rb', line 92
def update_remote(href = smart_proxy_acs.remote_href)
api.get_remotes_api(href: href).partial_update(href, remote_options)
end
|