Class: InspecTools::Inspec

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

Instance Method Summary collapse

Constructor Details

#initialize(inspec_json) ⇒ Inspec

Returns a new instance of Inspec.



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

def initialize(inspec_json)
  @json = JSON.parse(inspec_json)
end

Instance Method Details

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



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

def to_ckl(title = nil, date = nil, cklist = nil)
  @data = Utils::InspecUtil.parse_data_for_ckl(@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



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

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) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/inspec_tools/inspec.rb', line 36

def to_xccdf(attributes, verbose = false)
  @data = Utils::InspecUtil.parse_data_for_xccdf(@json)
  @attribute = attributes
  @attribute = {} if @attribute.eql? false
  @verbose = verbose
  @benchmark = HappyMapperTools::Benchmark::Benchmark.new
  populate_header
  # populate_profiles @todo populate profiles; not implemented now because its use is deprecated
  populate_groups
  @benchmark.to_xml
end