Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
task fix_xccdf_reports: :environment do
start_time = Time.now.utc
puts "Starting fix_xccdf_reports job at #{start_time}"
xccdf_profiles = Profile.reject{ |profile| profile.ref_id.match?(/xccdf_org.ssgproject.content_profile_.*/) }
xccdf_profiles.map { |profile| profile.update(name: "xccdf_org.ssgproject.content_profile_#{profile.ref_id}") }
# At this point, some of the profiles will still have the same broken ref_id as other profiles in the same
# account might have it.
xccdf_profiles = Profile.reject{ |profile| profile.ref_id.match?(/xccdf_org.ssgproject.content_profile_.*/) }
xccdf_profiles.each do |xccdf_profile|
ds_profile = profile.account.profiles.find_by(ref_id: "xccdf_org.ssgproject.content_profile_#{profile.ref_id}")
ProfileHost.where(rule_id: xccdf_profile.id).update(rule_id: ds_profile.id)
xccdf_profile.rules.each do |xccdf_rule|
ds_rule = ds_profile.rules.find_by(ref_id: "xccdf_org.ssgproject.content_profile_#{xccdf_rule.ref_id}")
xccdf_rule.destroy if RuleResult.where(rule_id: xccdf_rule.id).update(rule_id: ds_rule.id)
end
xccdf_profile.destroy
end
end_time = Time.now.utc
duration = end_time - start_time
puts "Finishing fix_xccdf_reports job at #{end_time} "\
"and last #{duration} seconds"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment