Class: Utils::FromInspec
Overview
Data transformation from Inspec result output into usable data for XCCDF conversions.
Constant Summary collapse
- DATA_NOT_FOUND_MESSAGE =
'N/A'.freeze
Instance Method Summary collapse
-
#parse_data_for_xccdf(json) ⇒ Object
Convert raw Inspec result json into format acceptable for XCCDF transformation.
Instance Method Details
#parse_data_for_xccdf(json) ⇒ Object
Convert raw Inspec result json into format acceptable for XCCDF transformation.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/utilities/xccdf/from_inspec.rb', line 7 def parse_data_for_xccdf(json) data = {} controls = [] if json['profiles'].nil? controls = json['controls'] elsif json['profiles'].length == 1 controls = json['profiles'].last['controls'] else json['profiles'].each do |profile| controls.concat(profile['controls']) end end c_data = {} controls.each do |control| c_id = control['id'].to_sym c_data[c_id] = {} c_data[c_id]['id'] = control['id'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['title'] = control['title'] if control['title'] # Optional attribute c_data[c_id]['desc'] = control['desc'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['severity'] = control['tags']['severity'] || 'unknown' c_data[c_id]['gid'] = control['tags']['gid'] || control['id'] c_data[c_id]['gtitle'] = control['tags']['gtitle'] if control['tags']['gtitle'] # Optional attribute c_data[c_id]['gdescription'] = control['tags']['gdescription'] if control['tags']['gdescription'] # Optional attribute c_data[c_id]['rid'] = control['tags']['rid'] || "r_#{c_data[c_id]['gid']}" c_data[c_id]['rversion'] = control['tags']['rversion'] if control['tags']['rversion'] # Optional attribute c_data[c_id]['rweight'] = control['tags']['rweight'] if control['tags']['rweight'] # Optional attribute where N/A is not schema compliant c_data[c_id]['stig_id'] = control['tags']['stig_id'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['cci'] = control['tags']['cci'] if control['tags']['cci'] # Optional attribute c_data[c_id]['legacy'] = control['tags']['legacy'] if control['tags']['legacy'] # Optional attribute c_data[c_id]['nist'] = control['tags']['nist'] || ['unmapped'] c_data[c_id]['check'] = control['tags']['check'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['checkref'] = control['tags']['checkref'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['fix'] = control['tags']['fix'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['fix_id'] = control['tags']['fix_id'] if control['tags']['fix_id'] # Optional attribute where N/A is not schema compliant c_data[c_id]['rationale'] = control['tags']['rationale'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['cis_family'] = control['tags']['cis_family'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['cis_rid'] = control['tags']['cis_rid'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['cis_level'] = control['tags']['cis_level'] || DATA_NOT_FOUND_MESSAGE c_data[c_id]['impact'] = control['impact'].to_s || DATA_NOT_FOUND_MESSAGE c_data[c_id]['code'] = control['code'].to_s || DATA_NOT_FOUND_MESSAGE c_data[c_id]['results'] = parse_results_for_xccdf(control['results']) if control['results'] end data['controls'] = c_data.values data['profiles'] = parse_profiles_for_xccdf(json['profiles']) data['status'] = 'success' data['inspec_version'] = json['version'] data end |