Class: Katello::Pulp3::Erratum

Inherits:
PulpContentUnit show all
Includes:
LazyAccessor
Defined in:
app/services/katello/pulp3/erratum.rb

Constant Summary collapse

PULPCORE_CONTENT_TYPE =
"rpm.advisory".freeze

Instance Attribute Summary

Attributes inherited from PulpContentUnit

#backend_data, #uuid

Class Method Summary collapse

Methods included from LazyAccessor

included

Methods inherited from PulpContentUnit

add_timestamps, content_api_create, content_type, content_unit_list, create_content, #fetch_backend_data, fetch_content_list, find_duplicate_unit, #initialize, katello_name_from_pulpcore_name, model_class, page_options, pulp_data, pulp_units_batch_all, pulp_units_batch_for_repo, pulp_units_for_ids

Constructor Details

This class inherits a constructor from Katello::Pulp3::PulpContentUnit

Class Method Details

.backend_unit_identifierObject



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

def self.backend_unit_identifier
  "pulp_href"
end

.build_bugzillas(katello_id, ref_list) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'app/services/katello/pulp3/erratum.rb', line 73

def self.build_bugzillas(katello_id, ref_list)
  ref_list.select { |r| r[:type] == "bugzilla" }.map do |bugzilla|
    {
      bug_id: bugzilla[:id],
      href: bugzilla[:href],
      erratum_id: katello_id,
    }
  end
end

.build_cves(katello_id, ref_list) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'app/services/katello/pulp3/erratum.rb', line 83

def self.build_cves(katello_id, ref_list)
  ref_list.select { |r| r[:type] == "cve" }.map do |cve|
    {
      cve_id: cve[:id],
      href: cve[:href],
      erratum_id: katello_id,
    }
  end
end

.build_modules(katello_id, module_stream_list) ⇒ Object



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

def self.build_modules(katello_id, module_stream_list)
  module_stream_attributes = []
  module_stream_list.each do |package_item|
    if package_item[:module]
      module_stream = ::Katello::ModuleStream.where(package_item[:module]).first
      next if module_stream.blank?
      nvreas = package_item[:packages].map { |hash| Util::Package.build_nvra(hash) }
      package_ids = Katello::ErratumPackage.where(:erratum_id => katello_id, :nvrea => nvreas).pluck(:id)

      module_stream_attributes += package_ids.map do |pkg_id|
        { :module_stream_id => module_stream.id,
          :erratum_package_id => pkg_id }
      end

    end
  end
  module_stream_attributes.uniq
end

.build_packages(katello_id, pkg_list) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'app/services/katello/pulp3/erratum.rb', line 93

def self.build_packages(katello_id, pkg_list)
  list = pkg_list.map do |json|
    package_hashes = json[:packages]
    package_hashes.map do |hash|
      nvrea = Util::Package.build_nvra(hash)
      {'name' => hash[:name], 'nvrea' => nvrea, 'filename' => hash[:filename], :erratum_id => katello_id}
    end
  end
  list.flatten
end

.content_apiObject



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

def self.content_api
  PulpRpmClient::ContentAdvisoriesApi.new(Katello::Pulp3::Api::Yum.new(SmartProxy.pulp_primary!).api_client)
end

.convert_date_if_epoch(date) ⇒ Object



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

def self.convert_date_if_epoch(date)
  date.to_i.to_s == date ? epoch_to_date(date) : date
end

.epoch_to_date(epoch) ⇒ Object



127
128
129
# File 'app/services/katello/pulp3/erratum.rb', line 127

def self.epoch_to_date(epoch)
  Time.at(epoch.to_i).to_s
end

.generate_model_row(unit) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/services/katello/pulp3/erratum.rb', line 29

def self.generate_model_row(unit)
  keys = %w(title id severity issued_date type description reboot_suggested solution updated_date summary)
  custom_json = unit.slice(*keys)
  custom_json.inject(HashWithIndifferentAccess.new({})) { |h, (k, v)| h.merge({ k => v.respond_to?(:strip) ? v.strip : v }) }
  custom_json['pulp_id'] = custom_json['id']
  custom_json["issued"] = custom_json.delete("issued_date")
  custom_json["updated"] = custom_json.delete("updated_date")
  custom_json['title'] = custom_json['title']&.truncate(255)

  # handle SUSE epoch dates
  custom_json["issued"] = convert_date_if_epoch(custom_json["issued"])
  custom_json["updated"] = convert_date_if_epoch(custom_json["updated"]) unless custom_json["updated"].blank?

  custom_json['errata_id'] = custom_json.delete('id')
  custom_json['errata_type'] = custom_json.delete('type')
  custom_json['issued'] = custom_json['issued'].to_datetime.strftime('%Y-%m-%d').to_datetime
  custom_json['updated'] = custom_json['updated'].blank? ? custom_json['issued'] : custom_json['updated'].to_datetime.strftime('%Y-%m-%d').to_datetime
  custom_json
end

.ids_for_repository(repo_id) ⇒ Object



23
24
25
26
27
# File 'app/services/katello/pulp3/erratum.rb', line 23

def self.ids_for_repository(repo_id)
  repo = Katello::Pulp3::Repository::Yum.new(Katello::Repository.find(repo_id), SmartProxy.pulp_primary)
  repo_content_list = repo.content_list
  repo_content_list.map { |content| content.try(:pulp_href) }
end

.insert_child_associations(units, pulp_id_to_id) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/services/katello/pulp3/erratum.rb', line 49

def self.insert_child_associations(units, pulp_id_to_id)
  bugzillas = []
  cves = []
  packages = []
  modules = []

  units.each do |unit|
    katello_id = pulp_id_to_id[unit['id']]
    bugzillas += build_bugzillas(katello_id, unit['references'])
    cves += build_cves(katello_id, unit['references'])
    packages += build_packages(katello_id, unit['pkglist'])
  end

  Katello::ErratumBugzilla.insert_all(bugzillas, unique_by: [:erratum_id, :bug_id, :href]) if bugzillas.any?
  Katello::ErratumCve.insert_all(cves, unique_by: [:erratum_id, :cve_id, :href]) if cves.any?
  Katello::ErratumPackage.insert_all(packages, unique_by: [:erratum_id, :nvrea, :name, :filename]) if packages.any?
  units.each do |unit|
    katello_id = pulp_id_to_id[unit['id']]
    modules += build_modules(katello_id, unit['pkglist'])
  end
  ModuleStreamErratumPackage.insert_all(modules, unique_by: [:module_stream_id, :erratum_package_id]) if modules.any?
  nil
end

.supports_id_fetch?Boolean

Returns:

  • (Boolean)


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

def self.supports_id_fetch?
  false
end

.unit_identifierObject



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

def self.unit_identifier
  "id"
end