Class: InspecTools::CLI
Instance Method Summary collapse
- #compliance ⇒ Object
- #csv2inspec ⇒ Object
- #generate_map ⇒ Object
- #inspec2ckl ⇒ Object
- #inspec2csv ⇒ Object
- #inspec2xccdf ⇒ Object
- #pdf2inspec ⇒ Object
- #summary ⇒ Object
- #version ⇒ Object
- #xccdf2inspec ⇒ Object
Methods inherited from Command
Instance Method Details
#compliance ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/inspec_tools/cli.rb', line 131 def compliance if [:threshold_file].nil? && [:threshold_inline].nil? puts 'Please provide threshold as a yaml file or inline yaml' exit(1) end threshold = YAML.load_file([:threshold_file]) unless [:threshold_file].nil? threshold = YAML.safe_load([:threshold_inline]) unless [:threshold_inline].nil? compliance = InspecTools::Summary.new(File.read([:inspec_json])).threshold(threshold) compliance ? exit(0) : exit(1) end |
#csv2inspec ⇒ Object
49 50 51 52 53 54 |
# File 'lib/inspec_tools/cli.rb', line 49 def csv2inspec csv = CSV.read([:csv], encoding: 'ISO8859-1') mapping = YAML.load_file([:mapping]) profile = CSVTool.new(csv, mapping, [:csv].split('/')[-1].split('.')[0], [:verbose]).to_inspec Utils::InspecUtil.unpack_inspec_json([:output], profile, [:separate_files], [:format]) end |
#generate_map ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/inspec_tools/cli.rb', line 90 def generate_map template = ' # Setting csv_header to true will skip the csv file header skip_csv_header: true width : 80 control.id: 0 control.title: 15 control.desc: 16 control.tags: severity: 1 rid: 8 stig_id: 3 cci: 2 check: 12 fix: 10 ' myfile = File.new('mapping.yml', 'w') myfile.puts template myfile.close end |
#inspec2ckl ⇒ Object
71 72 73 74 |
# File 'lib/inspec_tools/cli.rb', line 71 def inspec2ckl ckl = InspecTools::Inspec.new(File.read([:inspec_json])).to_ckl File.write([:output], ckl) end |
#inspec2csv ⇒ Object
61 62 63 64 |
# File 'lib/inspec_tools/cli.rb', line 61 def inspec2csv csv = Inspec.new(File.read([:inspec_json])).to_csv Utils::CSVUtil.unpack_csv(csv, [:output]) end |
#inspec2xccdf ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/inspec_tools/cli.rb', line 33 def inspec2xccdf json = File.read([:inspec_json]) inspec_tool = InspecTools::Inspec.new(json) attr_hsh = YAML.load_file([:attributes]) xccdf = inspec_tool.to_xccdf(attr_hsh) File.write([:output], xccdf) end |
#pdf2inspec ⇒ Object
83 84 85 86 87 |
# File 'lib/inspec_tools/cli.rb', line 83 def pdf2inspec pdf = File.open([:pdf]) profile = InspecTools::PDF.new(pdf, [:output], [:debug]).to_inspec Utils::InspecUtil.unpack_inspec_json([:output], profile, [:separate_files], [:format]) end |
#summary ⇒ Object
119 120 121 122 |
# File 'lib/inspec_tools/cli.rb', line 119 def summary summary = InspecTools::Summary.new(File.read([:inspec_json])).to_summary File.write([:output], summary.to_json) end |
#version ⇒ Object
143 144 145 |
# File 'lib/inspec_tools/cli.rb', line 143 def version puts VERSION end |
#xccdf2inspec ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/inspec_tools/cli.rb', line 18 def xccdf2inspec xccdf = XCCDF.new(File.read([:xccdf])) profile = xccdf.to_inspec Utils::InspecUtil.unpack_inspec_json([:output], profile, [:separate_files], [:format]) if ![:attributes].nil? attributes = xccdf.to_attributes File.write([:attributes], YAML.dump(attributes)) end end |