Class: Katello::Pulp3::Api::ContentGuard

Inherits:
Core
  • Object
show all
Defined in:
app/services/katello/pulp3/api/content_guard.rb

Instance Attribute Summary

Attributes inherited from Core

#repository_type, #smart_proxy

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core

#api_client_class, #api_exception_class, #artifacts_api, #cancel_task, #core_api_client, #core_repositories_api, #core_repositories_list_all, #delete_distribution, #delete_orphans, #delete_remote, #distributions_api, #distributions_list_all, #export_api, #exporter_api, fetch_from_list, #get_distribution, #ignore_404_exception, ignore_409_exception, #import_api, #importer_api, #importer_check_api, #initialize, #list_all, #orphans_api, #publications_api, remote_uln_class, #remotes_api, #remotes_list, #remotes_list_all, #remotes_uln_api, #repair_class, #repositories_api, #repositories_reclaim_space_api, #repository_sync_url_class, #repository_version_hrefs, #repository_versions, #repository_versions_api, #signing_services_api, #task_groups_api, #tasks_api, #upload_class, #upload_commit_class, #uploads_api, #versions_list_for_repository, #yum_export_api, #yum_exporter_api

Constructor Details

This class inherits a constructor from Katello::Pulp3::Api::Core

Class Method Details

.api_exception_classObject



15
16
17
# File 'app/services/katello/pulp3/api/content_guard.rb', line 15

def self.api_exception_class
  PulpCertguardClient::ApiError
end

Instance Method Details

#api_clientObject



19
20
21
# File 'app/services/katello/pulp3/api/content_guard.rb', line 19

def api_client
  api_client_class(PulpCertguardClient::ApiClient.new(smart_proxy.pulp3_configuration(PulpCertguardClient::Configuration)))
end

#ca_certObject



27
28
29
# File 'app/services/katello/pulp3/api/content_guard.rb', line 27

def ca_cert
  Cert::Certs.candlepin_client_ca_cert
end

#client_moduleObject



11
12
13
# File 'app/services/katello/pulp3/api/content_guard.rb', line 11

def client_module
  PulpCertguardClient
end

#create(name = default_name) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'app/services/katello/pulp3/api/content_guard.rb', line 53

def create(name = default_name)
  data = PulpCertguardClient::CertguardRHSMCertGuard.new(name: name, ca_certificate: ca_cert)
  rhsm_api_client.create(data)
rescue self.class.api_exception_class => e
  if (found = list&.results&.first) #check for possible race condition
    found
  else
    raise e
  end
end

#default_nameObject



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

def default_name
  'RHSMCertGuard'
end

#delete(href) ⇒ Object



73
74
75
# File 'app/services/katello/pulp3/api/content_guard.rb', line 73

def delete(href)
  rhsm_api_client.delete(href) if href
end

#list(options = {}) ⇒ Object



64
65
66
# File 'app/services/katello/pulp3/api/content_guard.rb', line 64

def list(options = {})
  rhsm_api_client.list options
end

#partial_update(href) ⇒ Object



68
69
70
71
# File 'app/services/katello/pulp3/api/content_guard.rb', line 68

def partial_update(href)
  data = PulpCertguardClient::CertguardRHSMCertGuard.new(ca_certificate: ca_cert)
  rhsm_api_client.partial_update(href, data)
end

#persist_if_needed(href) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'app/services/katello/pulp3/api/content_guard.rb', line 41

def persist_if_needed(href)
  return if self.smart_proxy.pulp_mirror?
  Katello::Util::Support.active_record_retry do
    found = Katello::Pulp3::ContentGuard.find_by(:name => default_name)
    if found
      found.update(pulp_href: href)
    else
      Katello::Pulp3::ContentGuard.create(name: default_name, pulp_href: href)
    end
  end
end

#refreshObject



31
32
33
34
35
36
37
38
39
# File 'app/services/katello/pulp3/api/content_guard.rb', line 31

def refresh
  found = list(name: default_name).results.first
  if found && found.ca_certificate != ca_cert
    partial_update(found.pulp_href)
  else
    found = create
  end
  persist_if_needed(found.pulp_href)
end

#rhsm_api_clientObject



23
24
25
# File 'app/services/katello/pulp3/api/content_guard.rb', line 23

def rhsm_api_client
  PulpCertguardClient::ContentguardsRhsmApi.new(api_client)
end