Class: Katello::Resources::CDN::KatelloCdn
Constant Summary
Constants inherited
from CdnResource
CdnResource::CDN_DOCKER_CONTAINER_LISTING
Instance Method Summary
collapse
Methods inherited from CdnResource
ca_file, create, #fetch_substitutions, #get, #get_container_listings, #get_docker_registries, #http_downloader, #log, #net_http_class, #parse_host, #proxy, redhat_cdn?, redhat_cdn_url, #substitutor
Constructor Details
#initialize(url, options) ⇒ KatelloCdn
Returns a new instance of KatelloCdn.
5
6
7
8
9
10
11
12
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 5
def initialize(url, options)
@organization_label = options.delete(:organization_label)
@content_view_label = options.delete(:content_view_label) || ::Katello::OrganizationCreator::DEFAULT_CONTENT_VIEW_LABEL
@lifecycle_environment_label = options.delete(:lifecycle_environment_label) || ::Katello::OrganizationCreator::DEFAULT_LIFECYCLE_ENV_LABEL
fail ArgumentError, "No upstream organization was specified" if @organization_label.nil?
super
end
|
Instance Method Details
#content_view_id ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 58
def content_view_id
rs = get("/katello/api/v2/organizations/#{organization['id']}/content_views?search=#{CGI.escape("label=#{@content_view_label}")}")
content_view = JSON.parse(rs)['results']&.first
if content_view.blank?
fail _("Upstream organization %{org_label} does not have a content view with the label %{cv_label}") % { org_label: @organization_label,
cv_label: @content_view_label }
end
content_view["id"]
end
|
#debug_certificate ⇒ Object
54
55
56
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 54
def debug_certificate
get("/katello/api/v2/organizations/#{organization['id']}/download_debug_certificate")
end
|
#fetch_paths(content_path) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 20
def fetch_paths(content_path)
repo_set = fetch_repo_set(content_path)
fail _("Upstream organization %s does not provide this content path") % @organization_label if repo_set.nil?
params = {
full_result: true,
organization_id: organization['id'],
content_view_id: content_view_id,
environment_id: lifecycle_environment_id,
search: CGI.escape("content_label = #{repo_set['label']}"),
}
query_params = params.map { |key, value| "#{key}=#{value}" }
url = "/katello/api/v2/repositories?#{query_params.join("&")}"
response = get(url)
json_body = JSON.parse(response)
results = json_body['results']
results.map do |repo|
Katello::Content.substitute_content_path(arch: repo['arch'],
releasever: repo['minor'],
content_path: content_path)
end
end
|
#fetch_repo_set(content_path) ⇒ Object
14
15
16
17
18
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 14
def fetch_repo_set(content_path)
url = "/katello/api/v2/repository_sets?organization_id=#{organization['id']}&search=#{CGI.escape("path = #{content_path}")}"
response = get(url)
JSON.parse(response)['results'].first
end
|
#lifecycle_environment_id ⇒ Object
68
69
70
71
72
73
74
75
76
77
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 68
def lifecycle_environment_id
rs = get("/katello/api/v2/organizations/#{organization['id']}/environments?full_result=true")
env = JSON.parse(rs)['results'].find { |lce| lce['label'] == @lifecycle_environment_label }
if env.blank?
fail _("Upstream organization %{org_label} does not have a lifecycle environment with the label %{lce_label}") % { org_label: @organization_label,
lce_label: @lifecycle_environment_label }
end
env["id"]
end
|
#repository_url(content_label:, arch:, major:, minor:) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 79
def repository_url(content_label:, arch:, major:, minor:)
params = {
search: CGI.escape("content_label = #{content_label}"),
}
params[:content_view_id] = content_view_id if @content_view_label
params[:environment_id] = lifecycle_environment_id if @lifecycle_environment_label
query_params = params.map { |key, value| "#{key}=#{value}" }
url = "/katello/api/v2/organizations/#{organization['id']}/repositories?#{query_params.join('&')}"
response = get(url)
repository = JSON.parse(response)['results']&.find { |r| r['arch'] == arch && r['major'] == major && r['minor'] == minor }
if repository.nil?
msg_params = { content_label: content_label,
arch: arch,
major: major,
minor: minor,
org_label: @organization_label,
cv_label: @content_view_label || Katello::OrganizationCreator::DEFAULT_CONTENT_VIEW_LABEL,
env_label: @lifecycle_environment_label || Katello::OrganizationCreator::DEFAULT_LIFECYCLE_ENV_LABEL,
}
fail _("Repository with content label: '%{content_label}'#{arch ? ', arch: \'%{arch}\'' : ''}#{minor ? ', version: \'%{minor}\'' : ''} was not found in upstream organization '%{org_label}',"\
" content view '%{cv_label}' and lifecycle environment '%{env_label}'") % msg_params
end
repository['full_path']
end
|
#valid_path?(_path, _postfix) ⇒ Boolean
46
47
48
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 46
def valid_path?(_path, _postfix)
true
end
|
#validate! ⇒ Object
50
51
52
|
# File 'app/lib/katello/resources/cdn/katello_cdn.rb', line 50
def validate!
organization && content_view_id && lifecycle_environment_id
end
|