Class: Katello::Pulp3::Repository

Inherits:
Object
  • Object
show all
Includes:
ServiceCommon, Util::HttpProxy
Defined in:
app/services/katello/pulp3/repository.rb,
app/services/katello/pulp3/repository/apt.rb,
app/services/katello/pulp3/repository/yum.rb,
app/services/katello/pulp3/repository/file.rb,
app/services/katello/pulp3/repository/docker.rb,
app/services/katello/pulp3/repository/generic.rb,
app/services/katello/pulp3/repository/ansible_collection.rb

Direct Known Subclasses

AnsibleCollection, Apt, Docker, File, Generic, Yum

Defined Under Namespace

Classes: AnsibleCollection, Apt, Docker, File, Generic, Yum

Constant Summary collapse

COPY_UNIT_PAGE_SIZE =
10_000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ServiceCommon

#create_test_remote, #ignore_404_exception, #reformat_api_exception, #test_remote_name

Methods included from Util::HttpProxy

#proxy, #proxy_host, #proxy_port, #proxy_scheme, #proxy_uri

Constructor Details

#initialize(repo, smart_proxy) ⇒ Repository

Returns a new instance of Repository.



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

def initialize(repo, smart_proxy)
  @repo = repo
  @smart_proxy = smart_proxy
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



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

def repo
  @repo
end

#smart_proxyObject

Returns the value of attribute smart_proxy.



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

def smart_proxy
  @smart_proxy
end

Class Method Details

.api(smart_proxy, repository_type_label) ⇒ Object



55
56
57
58
59
# File 'app/services/katello/pulp3/repository.rb', line 55

def self.api(smart_proxy, repository_type_label)
  repo_type = RepositoryTypeManager.enabled_repository_types[repository_type_label]
  fail _("%s content type is not enabled." % repository_type_label) unless repo_type
  repo_type.pulp3_api(smart_proxy)
end

.build_prn(href, pulp_plugin, pulp_model) ⇒ String?

Build a PRN from a Pulp href

Parameters:

  • href (String)

    Pulp href (e.g., "/pulp/api/v3/contentguards/certguard/rhsm/uuid/")

  • pulp_plugin (String)

    Pulp plugin name (e.g., "certguard", "container", "rpm")

  • pulp_model (String)

    Pulp model name (e.g., "rhsmcertguard", "containerrepository", "rpmrepository")

Returns:

  • (String, nil)

    PRN string (e.g., "prn:certguard.rhsmcertguard:uuid") or nil if href doesn't match expected format



33
34
35
36
37
38
39
40
41
# File 'app/services/katello/pulp3/repository.rb', line 33

def self.build_prn(href, pulp_plugin, pulp_model)
  return nil unless href

  # Extract UUID from href (last non-empty path segment)
  uuid = href.split('/').reject(&:empty?).last
  return nil unless uuid

  "prn:#{pulp_plugin}.#{pulp_model}:#{uuid}"
end

.instance_for_type(repo, smart_proxy) ⇒ Object



128
129
130
131
132
133
# File 'app/services/katello/pulp3/repository.rb', line 128

def self.instance_for_type(repo, smart_proxy)
  repo_types = Katello::RepositoryTypeManager.enabled_repository_types(false)
  # Populate cache on first call if empty
  repo_types = Katello::RepositoryTypeManager.enabled_repository_types if repo_types.empty?
  repo_types[repo.root.content_type].pulp3_service_class.new(repo, smart_proxy)
end

.publication_href?(href) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/services/katello/pulp3/repository.rb', line 24

def self.publication_href?(href)
  href.include?('/publications/')
end

.version_href?(href) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.version_href?(href)
  /.*\/versions\/\d*\//.match(href)
end

Instance Method Details

#add_content(content_unit_href, remove_all_units = false) ⇒ Object



584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'app/services/katello/pulp3/repository.rb', line 584

def add_content(content_unit_href, remove_all_units = false)
  content_unit_href = [content_unit_href] unless content_unit_href.is_a?(Array)
  if remove_all_units
    api.repositories_api.modify(repository_reference.repository_href, remove_content_units: ['*'])
    api.repositories_api.modify(repository_reference.repository_href, add_content_units: content_unit_href)
  else
    api.repositories_api.modify(repository_reference.repository_href, add_content_units: content_unit_href)
  end
rescue api.client_module::ApiError => e
  if e.message.include? 'Could not find the following content units'
    raise ::Katello::Errors::Pulp3Error, "Content units that do not exist in Pulp were requested to be copied."\
       " Please run `foreman-rake katello:delete_orphaned_content` to fix the following repository:"\
      " #{repository_reference.root_repository.name}. Original error: #{e.message}"
  else
    raise e
  end
end

#add_content_for_repo(repository_href, content_unit_href) ⇒ Object



602
603
604
605
606
607
608
609
610
611
612
613
# File 'app/services/katello/pulp3/repository.rb', line 602

def add_content_for_repo(repository_href, content_unit_href)
  content_unit_href = [content_unit_href] unless content_unit_href.is_a?(Array)
  api.repositories_api.modify(repository_href, add_content_units: content_unit_href)
rescue api.client_module::ApiError => e
  if e.message.include? 'Could not find the following content units'
    raise ::Katello::Errors::Pulp3Error, "Content units that do not exist in Pulp were requested to be copied."\
      " Please run `foreman-rake katello:delete_orphaned_content` to fix the following repository:"\
      " #{::Katello::Pulp3::RepositoryReference.find_by(repository_href: repository_href).root_repository.name}. Original error: #{e.message}"
  else
    raise e
  end
end

#apiObject



65
66
67
# File 'app/services/katello/pulp3/repository.rb', line 65

def api
  @api ||= self.class.api(smart_proxy, repo.content_type)
end

#append_proxy_cacert(options) ⇒ Object



547
548
549
550
551
552
# File 'app/services/katello/pulp3/repository.rb', line 547

def append_proxy_cacert(options)
  if root.http_proxy&.cacert&.present? && options.key?(:ca_cert)
    options[:ca_cert] = [options[:ca_cert], root.http_proxy.cacert].compact.join("\n")
  end
  options
end

#common_remote_optionsObject



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'app/services/katello/pulp3/repository.rb', line 454

def common_remote_options
  remote_options = {
    tls_validation: root.verify_ssl_on_sync,
    name: generate_backend_object_name,
    url: root.url,
    proxy_url: root.http_proxy&.url,
    proxy_username: root.http_proxy&.username,
    proxy_password: root.http_proxy&.password,
    total_timeout: Setting[:sync_total_timeout],
    connect_timeout: Setting[:sync_connect_timeout_v2],
    sock_connect_timeout: Setting[:sync_sock_connect_timeout],
    sock_read_timeout: Setting[:sync_sock_read_timeout],
    rate_limit: Setting[:download_rate_limit],
  }
  remote_options[:url] = root.url unless root.url.blank?
  remote_options[:download_concurrency] = root.download_concurrency unless root.download_concurrency.blank?
  remote_options.merge!(username: root&.upstream_username,
                        password: root&.upstream_password)
  remote_options[:username] = nil if remote_options[:username] == ''
  remote_options[:password] = nil if remote_options[:password] == ''
  remote_options.merge!(ssl_remote_options)
end

#compute_remote_options(computed_options = remote_options) ⇒ Object



191
192
193
# File 'app/services/katello/pulp3/repository.rb', line 191

def compute_remote_options(computed_options = remote_options)
  computed_options.except(:name, :client_key)
end

#content_serviceObject



82
83
84
# File 'app/services/katello/pulp3/repository.rb', line 82

def content_service
  Katello::Pulp3::Content
end

#copy_all(source_repository, options = {}) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'app/services/katello/pulp3/repository.rb', line 347

def copy_all(source_repository, options = {})
  tasks = []
  if options[:remove_all]
    tasks << api.repositories_api.modify(repository_reference.repository_href, remove_content_units: ['*'])
  end

  if options[:mirror] && api.class.respond_to?(:add_remove_content_class)
    data = api.class.add_remove_content_class.new(
              base_version: source_repository.version_href)

    tasks << api.repositories_api.modify(repository_reference.repository_href, data)
    tasks
  elsif api.respond_to? :copy_api
    data = api.class.copy_class.new
    data.config = [{
      source_repo_version: source_repository.version_href,
      dest_repo: repository_reference.repository_href,
    }]
    tasks << api.copy_api.copy_content(data)
    tasks
  else
    copy_content_for_source(source_repository)
  end
end

#copy_units_by_href(unit_hrefs) ⇒ Object



339
340
341
342
343
344
345
# File 'app/services/katello/pulp3/repository.rb', line 339

def copy_units_by_href(unit_hrefs)
  tasks = []
  unit_hrefs.each_slice(COPY_UNIT_PAGE_SIZE) do |slice|
    tasks << create_version(:add_content_units => slice)
  end
  tasks
end

#copy_version(from_repository) ⇒ Object



372
373
374
# File 'app/services/katello/pulp3/repository.rb', line 372

def copy_version(from_repository)
  create_version(:base_version => from_repository.version_href)
end

#core_apiObject



61
62
63
# File 'app/services/katello/pulp3/repository.rb', line 61

def core_api
  Katello::Pulp3::Api::Core.new(smart_proxy)
end

#create(force = false) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'app/services/katello/pulp3/repository.rb', line 195

def create(force = false)
  if force || !repository_reference
    response = api.repositories_api.create(create_options)
    RepositoryReference.where(
      root_repository_id: repo.root_id,
      content_view_id: repo.content_view.id).destroy_all
    RepositoryReference.where(
      root_repository_id: repo.root_id,
      content_view_id: repo.content_view.id,
      repository_href: response.pulp_href,
      repository_prn: response.prn).create!
    response
  end
end

#create_distribution(path) ⇒ Object



299
300
301
302
303
304
305
306
307
# File 'app/services/katello/pulp3/repository.rb', line 299

def create_distribution(path)
  options = secure_distribution_options(path)
  options.delete(:content_guard_prn) # Remove PRN field before sending to Pulp
  distribution_data = api.distribution_class.new(options)
  unless ::Katello::RepositoryTypeManager.find(repo.content_type).pulp3_skip_publication
    fail_missing_publication(distribution_data.publication)
  end
  [api.distributions_api.create(distribution_data)]
end

#create_mirror_entitiesObject



151
152
153
# File 'app/services/katello/pulp3/repository.rb', line 151

def create_mirror_entities
  RepositoryMirror.new(self).create_entities
end

#create_optionsObject



488
489
490
# File 'app/services/katello/pulp3/repository.rb', line 488

def create_options
  { name: generate_backend_object_name }.merge!(specific_create_options)
end

#create_publicationObject



241
242
243
244
# File 'app/services/katello/pulp3/repository.rb', line 241

def create_publication
  publication_data = api.publication_class.new(publication_options(repo))
  api.publications_api.create(publication_data)
end

#create_remoteObject



86
87
88
89
# File 'app/services/katello/pulp3/repository.rb', line 86

def create_remote
  response = super
  repo.update!(:remote_href => response.pulp_href, :remote_prn => response.prn)
end

#create_version(options = {}) ⇒ Object



395
396
397
# File 'app/services/katello/pulp3/repository.rb', line 395

def create_version(options = {})
  api.repositories_api.modify(repository_reference.repository_href, options)
end

#custom_cdn_ca_certObject



542
543
544
545
# File 'app/services/katello/pulp3/repository.rb', line 542

def custom_cdn_ca_cert
  return root.cdn_configuration.ssl_ca if root.cdn_configuration.ssl_ca.present?
  ::File.read(::Katello::Resources::CDN::CdnResource.ca_file) if root.cdn_configuration.redhat_cdn_host?
end

#delete_distributionsObject



439
440
441
442
443
# File 'app/services/katello/pulp3/repository.rb', line 439

def delete_distributions
  if (dist_ref = distribution_reference)
    ignore_404_exception { api.delete_distribution(dist_ref.href) }
  end
end

#delete_distributions_by_pathObject



445
446
447
448
449
450
451
452
# File 'app/services/katello/pulp3/repository.rb', line 445

def delete_distributions_by_path
  path = relative_path
  dists = lookup_distributions(base_path: path)

  task = api.delete_distribution(dists.first.pulp_href) if dists.first
  Katello::Pulp3::DistributionReference.where(:path => path).destroy_all
  task
end

#delete_publicationObject



246
247
248
# File 'app/services/katello/pulp3/repository.rb', line 246

def delete_publication
  ignore_404_exception { api.publications_api.delete(repo.publication_href) } if repo.publication_href
end

#delete_remote(options = {}) ⇒ Object



123
124
125
126
# File 'app/services/katello/pulp3/repository.rb', line 123

def delete_remote(options = {})
  options[:href] ||= repo.remote_href
  ignore_404_exception { api.get_remotes_api(href: options[:href]).delete(options[:href]) } if options[:href]
end

#delete_repository(repo_reference = repository_reference) ⇒ Object



224
225
226
227
228
# File 'app/services/katello/pulp3/repository.rb', line 224

def delete_repository(repo_reference = repository_reference)
  href = repo_reference.try(:repository_href)
  repo_reference.try(:destroy)
  ignore_404_exception { api.repositories_api.delete(href) } if href
end

#delete_versionObject



380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'app/services/katello/pulp3/repository.rb', line 380

def delete_version
  ignore_404_exception { api.repository_versions_api.delete(repo.version_href) } unless version_zero?
rescue api.api_exception_class => e
  if e.message.include?("are currently being used to distribute content")
    Rails.logger.warn "Exception when calling repository_versions_api->delete: #{e}"
    publication_href = repo.publication_href
    Rails.logger.warn "Trying to delete publication #{publication_href} for repository #{repo.id}}"
    Rails.logger.error "Could not delete version: #{repo.version_href} because conflicting publication could not be looked up" unless publication_href
    if publication_href
      ignore_404_exception { api.publications_api.delete(publication_href) }
      ignore_404_exception { api.repository_versions_api.delete(repo.version_href) }
    end
  end
end

#distribution_needs_update?Boolean

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
188
189
# File 'app/services/katello/pulp3/repository.rb', line 178

def distribution_needs_update?
  if distribution_reference
    # FIXME: Workaround for https://github.com/pulp/pulpcore/issues/7004
    expected = secure_distribution_options(relative_path).except(:name, :content_guard_prn).compact
    actual = get_distribution&.to_hash || {}
    expected != actual.slice(*expected.keys)
  elsif repo.environment
    true
  else
    false
  end
end

#distribution_referenceObject



147
148
149
# File 'app/services/katello/pulp3/repository.rb', line 147

def distribution_reference
  DistributionReference.find_by(:repository_id => repo.id)
end

#fail_missing_publication(publication_href) ⇒ Object



626
627
628
629
630
# File 'app/services/katello/pulp3/repository.rb', line 626

def fail_missing_publication(publication_href)
  unless lookup_publication(publication_href)
    fail _("The repository's publication is missing. Please run a 'complete sync' on %s." % repo.name)
  end
end

#generate_backend_object_nameObject



139
140
141
# File 'app/services/katello/pulp3/repository.rb', line 139

def generate_backend_object_name
  "#{root.label}-#{repo.id}#{rand(9999)}"
end

#get_distribution(href = distribution_reference.href) ⇒ Object



174
175
176
# File 'app/services/katello/pulp3/repository.rb', line 174

def get_distribution(href = distribution_reference.href)
  api.get_distribution(href)
end

#get_remote(href = repo.remote_href) ⇒ Object



170
171
172
# File 'app/services/katello/pulp3/repository.rb', line 170

def get_remote(href = repo.remote_href)
  api.get_remotes_api(href: href).read(href)
end

#list(options) ⇒ Object



216
217
218
# File 'app/services/katello/pulp3/repository.rb', line 216

def list(options)
  api.repositories_api.list(options).results
end

#lookup_distributions(args) ⇒ Object



309
310
311
# File 'app/services/katello/pulp3/repository.rb', line 309

def lookup_distributions(args)
  api.distributions_api.list(args).results
end

#lookup_publication(href) ⇒ Object



561
562
563
564
565
566
# File 'app/services/katello/pulp3/repository.rb', line 561

def lookup_publication(href)
  api.publications_api.read(href) if href
rescue api.api_exception_class => e
  Rails.logger.error "Exception when calling publications_api->read: #{e}"
  nil
end

#lookup_version(href) ⇒ Object



554
555
556
557
558
559
# File 'app/services/katello/pulp3/repository.rb', line 554

def lookup_version(href)
  api.repository_versions_api.read(href) if href
rescue api.api_exception_class => e
  Rails.logger.error "Exception when calling repository_versions_api->read: #{e}"
  nil
end

#mirror_remote_optionsObject



477
478
479
480
481
482
483
484
485
486
# File 'app/services/katello/pulp3/repository.rb', line 477

def mirror_remote_options
  options = {}
  if Katello::RootRepository::CONTENT_ATTRIBUTE_RESTRICTIONS[:download_policy].include?(repo.content_type)
    options[:policy] = smart_proxy.download_policy
    if smart_proxy.download_policy == SmartProxy::DOWNLOAD_INHERIT
      options[:policy] = repo.root.download_policy
    end
  end
  options
end

#partial_repo_pathObject



43
44
45
# File 'app/services/katello/pulp3/repository.rb', line 43

def partial_repo_path
  fail NotImplementedError
end

#publication_options(repository) ⇒ Object



250
251
252
253
254
# File 'app/services/katello/pulp3/repository.rb', line 250

def publication_options(repository)
  {
    repository_version: repository.version_href,
  }
end

#published?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/services/katello/pulp3/repository.rb', line 69

def published?
  !repo.publication_href.nil?
end

#readObject



220
221
222
# File 'app/services/katello/pulp3/repository.rb', line 220

def read
  api.repositories_api.read(repository_reference.try(:repository_href))
end

#read_distribution(href = distribution_reference.href) ⇒ Object



313
314
315
# File 'app/services/katello/pulp3/repository.rb', line 313

def read_distribution(href = distribution_reference.href)
  ignore_404_exception { api.distributions_api.read(href) }
end

#refresh_distributionsObject



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'app/services/katello/pulp3/repository.rb', line 260

def refresh_distributions
  if repo.docker?
    dist = lookup_distributions(base_path: repo.container_repository_name).first
  else
    dist = lookup_distributions(base_path: repo.relative_path).first
  end
  dist_ref = distribution_reference

  if dist && !dist_ref
    save_distribution_references([dist.pulp_href])
    return update_distribution
  end

  if dist && dist_ref
    # If the saved distribution reference is wrong, delete it and use the existing distribution
    if dist.pulp_href != dist_ref.href
      dist_ref.destroy
      save_distribution_references([dist.pulp_href])
    end
    return update_distribution
  end

  # Since we got this far, we need to create a new distribution
  # Note: the distribution reference can't be saved yet because distribution creation is async
  begin
    create_distribution(relative_path)
  rescue api.client_module::ApiError => e
    # Now it seems there is a distribution. Fetch it and save the reference.
    if e.message.include?("\"base_path\":[\"This field must be unique.\"]") ||
        e.message.include?("\"base_path\":[\"Overlaps with existing distribution\"")
      dist = lookup_distributions(base_path: repo.relative_path).first
      save_distribution_references([dist.pulp_href])
      return update_distribution
    else
      raise e
    end
  end
end

#refresh_entitiesObject



159
160
161
# File 'app/services/katello/pulp3/repository.rb', line 159

def refresh_entities
  [update_remote].flatten.compact
end

#refresh_if_neededObject



163
164
165
166
167
168
# File 'app/services/katello/pulp3/repository.rb', line 163

def refresh_if_needed
  tasks = []
  tasks << update_remote #always update remote
  tasks << update_distribution if distribution_needs_update?
  tasks.compact
end

#refresh_mirror_entitiesObject



155
156
157
# File 'app/services/katello/pulp3/repository.rb', line 155

def refresh_mirror_entities
  RepositoryMirror.new(self).refresh_entities
end

#relative_pathObject



256
257
258
# File 'app/services/katello/pulp3/repository.rb', line 256

def relative_path
  repo.relative_path.sub(/^\//, '')
end

#remote_partial_updateObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/services/katello/pulp3/repository.rb', line 108

def remote_partial_update
  url_type = remote_options[:url]&.start_with?('uln') ? 'uln' : 'default'
  remote_type = repo.remote_href.start_with?('/pulp/api/v3/remotes/rpm/uln/') ? 'uln' : 'default'
  href = repo.remote_href

  if url_type == remote_type
    response = api.get_remotes_api(href: href).partial_update(href, remote_options)
    # Pulp 3.90+ returns polymorphic responses (PULP-734): task when changes occur, nil when no-op
    response if response.respond_to?(:task) && response.task.present?
  else # We need to recreate a remote of the correct type!
    create_remote
    delete_remote(href: href)
  end
end

#remove_content(content_units) ⇒ Object



568
569
570
571
572
573
574
# File 'app/services/katello/pulp3/repository.rb', line 568

def remove_content(content_units)
  if repo.root.content_type == "docker"
    api.repositories_api.remove(repository_reference.repository_href, content_units: content_units.map(&:pulp_id))
  else
    api.repositories_api.modify(repository_reference.repository_href, remove_content_units: content_units.map(&:pulp_id))
  end
end

#repair(repository_version_href) ⇒ Object



73
74
75
76
# File 'app/services/katello/pulp3/repository.rb', line 73

def repair(repository_version_href)
  data = api.repair_class.new
  api.repository_versions_api.repair(repository_version_href, data)
end

#repository_import_content(artifact_href, options = {}) ⇒ Object



576
577
578
579
580
581
582
# File 'app/services/katello/pulp3/repository.rb', line 576

def repository_import_content(artifact_href, options = {})
  ostree_import = PulpOstreeClient::OstreeRepoImport.new
  ostree_import.artifact = artifact_href
  ostree_import.repository_name = options[:ostree_repository_name]
  ostree_import.ref = options[:ostree_ref]
  api.repositories_api.import_commits(repository_reference.repository_href, ostree_import)
end

#repository_referenceObject



143
144
145
# File 'app/services/katello/pulp3/repository.rb', line 143

def repository_reference
  RepositoryReference.find_by(:root_repository_id => repo.root_id, :content_view_id => repo.content_view.id)
end

#retain_package_versions_countObject



621
622
623
624
# File 'app/services/katello/pulp3/repository.rb', line 621

def retain_package_versions_count
  return 0 if root.retain_package_versions_count.nil? || root.using_mirrored_content?
  root.retain_package_versions_count.to_i
end

#save_distribution_references(hrefs) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'app/services/katello/pulp3/repository.rb', line 399

def save_distribution_references(hrefs)
  hrefs.each do |href|
    pulp3_distribution_data = api.get_distribution(href)
    path = pulp3_distribution_data&.base_path
    content_guard_href = pulp3_distribution_data&.content_guard

    # FIXME: Workaround for ansible distributions not returning PRN
    # Remove once https://github.com/pulp/pulp_ansible/issues/2320 is fixed
    if repo.ansible_collection?
      prn = self.class.build_prn(href, 'ansible', 'ansibledistribution')
    else
      prn = pulp3_distribution_data&.prn
    end

    # Build content_guard PRN from href if content_guard exists
    # FIXME: Workaround for https://github.com/pulp/pulpcore/issues/7004
    content_guard_prn = if content_guard_href&.include?('/contentguards/certguard/rhsm/')
                          self.class.build_prn(content_guard_href, 'certguard', 'rhsmcertguard')
                        end

    if distribution_reference
      found_distribution = read_distribution(distribution_reference.href)
      unless found_distribution
        distribution_reference.destroy
      end
    end
    unless distribution_reference
      # Ensure that duplicates won't be created in the case of a race condition
      DistributionReference.where(
        path: path,
        href: href,
        prn: prn,
        repository_id: repo.id,
        content_guard_href: content_guard_href,
        content_guard_prn: content_guard_prn
      ).first_or_create!
    end
  end
end

#secure_distribution_options(path) ⇒ Object



496
497
498
499
500
501
502
503
504
505
506
507
# File 'app/services/katello/pulp3/repository.rb', line 496

def secure_distribution_options(path)
  secured_distribution_options = {}
  if root.unprotected
    secured_distribution_options[:content_guard] = nil
    secured_distribution_options[:content_guard_prn] = nil
  else
    content_guard = ::Katello::Pulp3::ContentGuard.first
    secured_distribution_options[:content_guard] = content_guard.pulp_href
    secured_distribution_options[:content_guard_prn] = content_guard.pulp_prn
  end
  secured_distribution_options.merge!(distribution_options(path))
end

#should_purge_empty_contents?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'app/services/katello/pulp3/repository.rb', line 135

def should_purge_empty_contents?
  false
end

#skip_typesObject



78
79
80
# File 'app/services/katello/pulp3/repository.rb', line 78

def skip_types
  nil
end

#specific_create_optionsObject



492
493
494
# File 'app/services/katello/pulp3/repository.rb', line 492

def specific_create_options
  {}
end

#ssl_remote_optionsObject



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'app/services/katello/pulp3/repository.rb', line 509

def ssl_remote_options
  options = {}
  if root.redhat? && root.cdn_configuration.redhat_cdn?
    options = {
      client_cert: root.product.certificate,
      client_key: root.product.key,
      ca_cert: Katello::Repository.feed_ca_cert(root.url),
    }
  elsif root.redhat? && root.cdn_configuration.custom_cdn?
    options = {
      ca_cert: custom_cdn_ca_cert,
    }
    if root.cdn_configuration.redhat_cdn_host?
      options[:client_cert] = root.product.certificate
      options[:client_key] = root.product.key
    end
  elsif root.redhat? && root.cdn_configuration.network_sync?
    options = {
      client_cert: root.cdn_configuration.ssl_cert,
      client_key: root.cdn_configuration.ssl_key,
      ca_cert: root.cdn_configuration.ssl_ca,
    }
  elsif root.custom?
    options = {
      client_cert: root.ssl_client_cert&.content,
      client_key: root.ssl_client_key&.content,
      ca_cert: root.ssl_ca_cert&.content,
    }
  end
  append_proxy_cacert(options) if options.key?(:ca_cert)
  options
end

#sync(options = {}) ⇒ Object



230
231
232
233
# File 'app/services/katello/pulp3/repository.rb', line 230

def sync(options = {})
  repository_sync_url_data = api.repository_sync_url_class.new(sync_url_params(options))
  [api.repositories_api.sync(repository_reference.repository_href, repository_sync_url_data)]
end

#sync_url_params(_sync_options) ⇒ Object



235
236
237
238
239
# File 'app/services/katello/pulp3/repository.rb', line 235

def sync_url_params(_sync_options)
  params = {remote: repo.remote_href, mirror: repo.root.mirroring_policy == Katello::RootRepository::MIRRORING_POLICY_CONTENT}
  params[:skip_types] = skip_types if (skip_types && repo.root.mirroring_policy != Katello::RootRepository::MIRRORING_POLICY_COMPLETE)
  params
end

#unit_keys(uploads) ⇒ Object



615
616
617
618
619
# File 'app/services/katello/pulp3/repository.rb', line 615

def unit_keys(uploads)
  uploads.map do |upload|
    upload.except('id')
  end
end

#updateObject



210
211
212
213
214
# File 'app/services/katello/pulp3/repository.rb', line 210

def update
  response = api.repositories_api.update(repository_reference.try(:repository_href), create_options)
  # Pulp 3.90+ returns polymorphic responses (PULP-734): task when changes occur, nil when no-op
  response if response.respond_to?(:task) && response.task.present?
end

#update_distributionObject



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'app/services/katello/pulp3/repository.rb', line 317

def update_distribution
  if distribution_reference
    options = secure_distribution_options(relative_path).except(:name)

    repo_type = ::Katello::RepositoryTypeManager.find(repo.content_type)
    # Clear publication field when transitioning from publication to repository_version
    if repo_type.pulp3_transitioning_from_publication
      dist = read_distribution
      options[:publication] = nil if dist&.publication.present?
    elsif !repo_type.pulp3_skip_publication
      # Content type uses publication
      fail_missing_publication(options[:publication])
    end

    content_guard_prn = options.delete(:content_guard_prn) # Extract PRN and remove from options
    distribution_reference.update(:content_guard_href => options[:content_guard], :content_guard_prn => content_guard_prn)
    response = api.distributions_api.partial_update(distribution_reference.href, options)
    # Pulp 3.90+ returns polymorphic responses (PULP-734): task when changes occur, nil when no-op
    (response.respond_to?(:task) && response.task.present?) ? [response] : []
  end
end

#update_remoteObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/services/katello/pulp3/repository.rb', line 91

def update_remote
  href = repo.remote_href
  if remote_options[:url].blank?
    if href
      repo.update(remote_href: nil, remote_prn: nil)
      delete_remote(href: href)
    end
  else
    if href
      remote_partial_update
    else
      create_remote
      return nil #return nil, as create isn't async
    end
  end
end

#version_zero?Boolean

Returns:

  • (Boolean)


376
377
378
# File 'app/services/katello/pulp3/repository.rb', line 376

def version_zero?
  repo.version_href.ends_with?('/versions/0/')
end

#with_mirror_adapterObject



47
48
49
50
51
52
53
# File 'app/services/katello/pulp3/repository.rb', line 47

def with_mirror_adapter
  if smart_proxy.pulp_primary?
    return self
  else
    return RepositoryMirror.new(self)
  end
end