20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/foreman_openscap/data_migration.rb', line 20
def migrate
ForemanOpenscap::Asset.where(:assetable_type => "Host::Base").select { |a| a.host.nil? }.map(&:destroy)
ForemanOpenscap::Asset.where(:assetable_type => "Hostgroup").select { |a| a.hostgroup.nil? }.map(&:destroy)
old_arf_reports = ActiveRecord::Migration.execute("SELECT * FROM foreman_openscap_arf_reports;")
old_arf_reports.select do |report|
policy_id = report["policy_id"]
date = DateTime.strptime(report["created_at"], "%Y-%m-%d %H:%M:%S")
date += 1.second until arfs_by_reported(date).empty?
host_name = fetch_host_name(report["asset_id"])
arf_file = fetch_xml_file(report["id"])
next if arf_file.blank?
migrator = ::ProxyAPI::Migration.new(:url => @url)
migrated_id = migrator.migrate_arf_report(arf_file, host_name, policy_id, date.to_i)
migrated_arf = ForemanOpenscap::ArfReport.find(migrated_id["arf_id"])
migrated_arf.update_attribute(:openscap_proxy_id, @proxy.id)
puts "Migrated Old arf_report #{report['id']} as arf: #{migrated_arf.id}"
delete_old_records(report["id"]) if migrated_arf
end
end
|