Last active
August 29, 2015 13:56
-
-
Save cjp/9081280 to your computer and use it in GitHub Desktop.
Convert XCCDF to Markdown
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'xmlsimple' | |
# stolen from facets, thanks to dharple for the suggestion | |
def word_wrap(text, col_width=80) | |
text.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' ) | |
text.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" ) | |
text | |
end | |
xml = ARGF.read | |
data = XmlSimple.xml_in(xml, { 'KeyAttr' => 'id' , 'GroupTags' => { 'Group' => 'Rule' }}) | |
# data = XmlSimple.xml_in('rhel6.xml', { 'KeyAttr' => 'id' , 'GroupTags' => { 'Group' => 'Rule' }}) | |
data['Group'].each do |ok, ov| | |
ov['Rule'].each do |ik, iv| | |
print "## #{iv['title'][0]}\n" | |
print "Severity: _#{iv['severity']}_\n" | |
desc = iv['description'][0].gsub /<VulnDiscussion>(.*)<\/VulnDiscussion>.*/m, '\1' | |
desc = word_wrap desc, 72 | |
desc = desc.gsub /\n/m, "\n> " | |
print "### Description\n> #{desc}\n" | |
print "\n\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment