Class: InspecPlugins::InspecToolsPlugin::CliCommand
- Defined in:
- lib/inspec_tools/plugin_cli.rb
Constant Summary collapse
- POSSIBLE_LOG_LEVELS =
%w{debug info warn error fatal}.freeze
Instance Method Summary collapse
- #compliance ⇒ Object
- #csv2inspec ⇒ Object
- #generate_ckl_metadata ⇒ Object
- #generate_inspec_metadata ⇒ Object
- #generate_map ⇒ Object
- #inspec2ckl ⇒ Object
- #inspec2csv ⇒ Object
- #inspec2xccdf ⇒ Object
- #pdf2inspec ⇒ Object
- #summary ⇒ Object
- #xccdf2inspec ⇒ Object
- #xlsx2inspec ⇒ Object
Instance Method Details
#compliance ⇒ Object
208 209 210 211 |
# File 'lib/inspec_tools/plugin_cli.rb', line 208 def compliance compliance = InspecTools::Summary.new(options: ) compliance.results_meet_threshold? ? exit(0) : exit(1) end |
#csv2inspec ⇒ Object
83 84 85 86 87 88 |
# File 'lib/inspec_tools/plugin_cli.rb', line 83 def csv2inspec csv = CSV.read([:csv], encoding: 'ISO8859-1') mapping = YAML.load_file([:mapping]) profile = InspecTools::CSVTool.new(csv, mapping, [:csv].split('/')[-1].split('.')[0], [:verbose]).to_inspec(control_name_prefix: [:control_name_prefix]) Utils::InspecUtil.unpack_inspec_json([:output], profile, [:separate_files], [:format]) end |
#generate_ckl_metadata ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/inspec_tools/plugin_cli.rb', line 151 def = {} ['stigid'] = ask('STID ID: ') ['role'] = ask('Role: ') ['type'] = ask('Type: ') ['hostname'] = ask('Hostname: ') ['ip'] = ask('IP Address: ') ['mac'] = ask('MAC Address: ') ['fqdn'] = ask('FQDN: ') ['tech_area'] = ask('Tech Area: ') ['target_key'] = ask('Target Key: ') ['web_or_database'] = ask('Web or Database: ') ['web_db_site'] = ask('Web DB Site: ') ['web_db_instance'] = ask('Web DB Instance: ') .delete_if { |_key, value| value.empty? } File.open('metadata.json', 'w') do |f| f.write(.to_json) end end |
#generate_inspec_metadata ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/inspec_tools/plugin_cli.rb', line 174 def = {} ['maintainer'] = ask('Maintainer: ') ['copyright'] = ask('Copyright: ') ['copyright_email'] = ask('Copyright Email: ') ['license'] = ask('License: ') ['version'] = ask('Version: ') .delete_if { |_key, value| value.empty? } File.open('metadata.json', 'w') do |f| f.write(.to_json) end end |
#generate_map ⇒ Object
145 146 147 148 |
# File 'lib/inspec_tools/plugin_cli.rb', line 145 def generate_map generator = InspecTools::GenerateMap.new generator.generate_example('mapping.yml') end |
#inspec2ckl ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/inspec_tools/plugin_cli.rb', line 122 def inspec2ckl = '{}' if ![:metadata].nil? = File.read([:metadata]) end ckl = InspecTools::Inspec.new(File.read([:inspec_json]), ).to_ckl File.write([:output], ckl) end |
#inspec2csv ⇒ Object
111 112 113 114 |
# File 'lib/inspec_tools/plugin_cli.rb', line 111 def inspec2csv csv = InspecTools::Inspec.new(File.read([:inspec_json])).to_csv Utils::CSVUtil.unpack_csv(csv, [:output]) end |
#inspec2xccdf ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/inspec_tools/plugin_cli.rb', line 64 def inspec2xccdf io = File.open([:inspec_json], 'rb') io.set_encoding_by_bom = [:metadata] ? JSON.parse(File.read([:metadata])) : {} inspec_tool = InspecTools::Inspec.new(io.read, ) attr_hsh = YAML.load_file([:attributes]) xccdf = inspec_tool.to_xccdf(attr_hsh) File.write([:output], xccdf) end |
#pdf2inspec ⇒ Object
138 139 140 141 142 |
# File 'lib/inspec_tools/plugin_cli.rb', line 138 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
197 198 199 200 |
# File 'lib/inspec_tools/plugin_cli.rb', line 197 def summary summary = InspecTools::Summary.new(options: ) summary.output_summary end |
#xccdf2inspec ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/inspec_tools/plugin_cli.rb', line 39 def xccdf2inspec xccdf = InspecTools::XCCDF.new(File.read([:xccdf]), [:control_id] == 'vulnID', [:replace_tags]) profile = xccdf.to_inspec if ![:metadata].nil? xccdf.(File.read([:metadata])) end 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 |
#xlsx2inspec ⇒ Object
99 100 101 102 103 104 |
# File 'lib/inspec_tools/plugin_cli.rb', line 99 def xlsx2inspec xlsx = Roo::Spreadsheet.open([:xlsx]) mapping = YAML.load_file([:mapping]) profile = InspecTools::XLSXTool.new(xlsx, mapping, [:xlsx].split('/')[-1].split('.')[0], [:verbose]).to_inspec([:control_name_prefix]) Utils::InspecUtil.unpack_inspec_json([:output], profile, [:separate_files], [:format]) end |