Class: InspecTools::Inspec
Instance Method Summary collapse
-
#initialize(inspec_json, metadata = '{}') ⇒ Inspec
constructor
A new instance of Inspec.
- #to_ckl(title = nil, date = nil, cklist = nil) ⇒ Object
-
#to_csv ⇒ Object
converts an InSpec JSON to a CSV file.
- #to_xccdf(attributes, verbose = false) ⇒ Object
Constructor Details
#initialize(inspec_json, metadata = '{}') ⇒ Inspec
Returns a new instance of Inspec.
20 21 22 23 |
# File 'lib/inspec_tools/inspec.rb', line 20 def initialize(inspec_json, = '{}') @json = JSON.parse(inspec_json.gsub(/\\+u0000/, '')) @metadata = JSON.parse() end |
Instance Method Details
#to_ckl(title = nil, date = nil, cklist = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/inspec_tools/inspec.rb', line 25 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_csv ⇒ Object
converts an InSpec JSON to a CSV file
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/inspec_tools/inspec.rb', line 54 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
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/inspec_tools/inspec.rb', line 39 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 |