Created
October 10, 2019 16:46
-
-
Save dLobatog/53225294303b2676ed99cc21dbc2b022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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