Created
April 12, 2018 02:49
-
-
Save trevor-vaughan/dcb1c61a98d9206aac2b99d3568c87a4 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
require 'yaml' | |
require 'nokogiri' | |
# This is extracted from the DISA STIG content | |
input_doc = 'U_Red_Hat_Enterprise_Linux_7_STIG_V1R2_Manual-xccdf.xml' | |
# You have to pull this file out of the STIGViewer Java JAR file | |
cci_mapping = 'U_CCI_List.xml' | |
def cci2nist(cci, ccidoc) | |
cci_item = ccidoc.at_css("[id=#{cci}]") | |
return [] unless cci_item | |
cci_item.css('reference').map do |reference| | |
{ | |
reference['title'] => reference['index'] | |
} | |
end.flatten | |
end | |
doc = Nokogiri::XML(File.read(input_doc)) | |
ccidoc = Nokogiri::XML(File.read(cci_mapping)) | |
group2cci = doc.css("Group").map do |groups| | |
{ groups['id'] => groups.css('ident').map do |cci| | |
{cci.text => cci2nist(cci.text, ccidoc)} | |
end | |
} | |
end | |
puts group2cci.to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment