lib/inspec_tools/xccdf.rb in inspec_tools-1.2.2 vs lib/inspec_tools/xccdf.rb in inspec_tools-1.3.0

- old
+ new

@@ -1,10 +1,11 @@ require_relative '../happy_mapper_tools/stig_attributes' require_relative '../happy_mapper_tools/cci_attributes' require_relative '../utilities/inspec_util' require 'digest' +require 'json' module InspecTools # rubocop:disable Metrics/ClassLength # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/PerceivedComplexity @@ -77,34 +78,46 @@ def published @benchmark.release_date.release_date end + def inject_metadata(metadata = '{}') + json_metadata = JSON.parse(metadata) + json_metadata.each do |key, value| + @profile[key] = value + end + end + private def replace_tags_in_xccdf(replace_tags, xccdf_xml) replace_tags.each do |tag| xccdf_xml = xccdf_xml.gsub(/(&lt;|<)#{tag}(&gt;|>)/, "$#{tag}") end xccdf_xml end def insert_json_metadata - @profile['name'] = @benchmark.title + @profile['name'] = @benchmark.id @profile['title'] = @benchmark.title - @profile['maintainer'] = 'The Authors' - @profile['copyright'] = 'The Authors' - @profile['copyright_email'] = 'you@example.com' - @profile['license'] = 'Apache-2.0' + @profile['maintainer'] = 'The Authors' if @profile['maintainer'].nil? + @profile['copyright'] = 'The Authors' if @profile['copyright'].nil? + @profile['copyright_email'] = 'you@example.com' if @profile['copyright_email'].nil? + @profile['license'] = 'Apache-2.0' if @profile['license'].nil? @profile['summary'] = "\"#{@benchmark.description.gsub('\\', '\\\\\\').gsub('"', '\"')}\"" - @profile['version'] = '0.1.0' + @profile['version'] = '0.1.0' if @profile['version'].nil? @profile['supports'] = [] @profile['attributes'] = [] @profile['generator'] = { 'name': 'inspec', 'version': Gem.loaded_specs['inspec'].version } + @profile['plaintext'] = @benchmark.plaintext.plaintext + @profile['status'] = "#{@benchmark.status} on #{@benchmark.release_date.release_date}" + @profile['reference_href'] = @benchmark.reference.href + @profile['reference_publisher'] = @benchmark.reference.dc_publisher + @profile['reference_source'] = @benchmark.reference.dc_source end def insert_controls @benchmark.group.each do |group| control = {} @@ -131,9 +144,10 @@ control['tags']['mitigation_controls'] = group.rule.description.mitigation_controls if group.rule.description.mitigation_controls != '' control['tags']['responsibility'] = group.rule.description.responsibility if group.rule.description.responsibility != '' control['tags']['ia_controls'] = group.rule.description.ia_controls if group.rule.description.ia_controls != '' control['tags']['check'] = group.rule.check.content control['tags']['fix'] = group.rule.fixtext + control['tags']['severity'] = group.rule.severity @controls << control end @profile['controls'] = @controls end end