Class: InspecTools::Inspec

Inherits:
Object show all
Defined in:
lib/inspec_tools/inspec.rb

Instance Method Summary collapse

Constructor Details

#initialize(inspec_json, metadata = {}) ⇒ Inspec

Returns a new instance of Inspec.



17
18
19
20
# File 'lib/inspec_tools/inspec.rb', line 17

def initialize(inspec_json,  = {})
  @json = JSON.parse(inspec_json)
  @metadata = 
end

Instance Method Details

#to_ckl(title = nil, date = nil, cklist = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/inspec_tools/inspec.rb', line 22

def to_ckl(title = nil, date = nil, cklist = nil)
  @data = Utils::InspecUtil.parse_data_for_ckl(@json)
  @platform = Utils::InspecUtil.get_platform(@json)
  @title = generate_title title, @json, date
  @cklist = cklist
  @checklist = HappyMapperTools::StigChecklist::Checklist.new
  if @cklist.nil?
    generate_ckl
  else
    update_ckl
  end
  @checklist.to_xml.encode('UTF-8').gsub('<?xml version="1.0"?>', '<?xml version="1.0" encoding="UTF-8"?>').chomp
end

#to_csvObject

converts an InSpec JSON to a CSV file



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/inspec_tools/inspec.rb', line 50

def to_csv
  @data = {}
  @data['controls'] = []
  get_all_controls_from_json(@json)
  data = inspec_json_to_array(@data)
  CSV.generate do |csv|
    data.each do |row|
      csv << row
    end
  end
end

#to_xccdf(attributes, verbose = false) ⇒ String

Convert Inspec result data to XCCDF

Parameters:

  • attributes (Hash)

    Optional input attributes

Returns:

  • (String)

    XML formatted String



40
41
42
43
44
45
# File 'lib/inspec_tools/inspec.rb', line 40

def to_xccdf(attributes, verbose = false)
  data = Utils::FromInspec.new.parse_data_for_xccdf(@json)
  @verbose = verbose

  Utils::ToXCCDF.new(attributes || {}, data).to_xml(@metadata)
end