class InspecPlugins::InspecToolsPlugin::CliCommand

Constants

POSSIBLE_LOG_LEVELS

Public Instance Methods

compliance() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 208
def compliance
  compliance = InspecTools::Summary.new(options: options)
  compliance.results_meet_threshold? ? exit(0) : exit(1)
end
csv2inspec() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 83
def csv2inspec
  csv = CSV.read(options[:csv], encoding: 'ISO8859-1')
  mapping = YAML.load_file(options[:mapping])
  profile = InspecTools::CSVTool.new(csv, mapping, options[:csv].split('/')[-1].split('.')[0], options[:verbose]).to_inspec(control_name_prefix: options[:control_name_prefix])
  Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
end
generate_ckl_metadata() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 151
def generate_ckl_metadata
  metadata = {}

  metadata['stigid'] = ask('STID ID: ')
  metadata['role'] = ask('Role: ')
  metadata['type'] = ask('Type: ')
  metadata['hostname'] = ask('Hostname: ')
  metadata['ip'] = ask('IP Address: ')
  metadata['mac'] = ask('MAC Address: ')
  metadata['fqdn'] = ask('FQDN: ')
  metadata['tech_area'] = ask('Tech Area: ')
  metadata['target_key'] = ask('Target Key: ')
  metadata['web_or_database'] = ask('Web or Database: ')
  metadata['web_db_site'] = ask('Web DB Site: ')
  metadata['web_db_instance'] = ask('Web DB Instance: ')

  metadata.delete_if { |_key, value| value.empty? }
  File.open('metadata.json', 'w') do |f|
    f.write(metadata.to_json)
  end
end
generate_inspec_metadata() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 174
def generate_inspec_metadata
  metadata = {}

  metadata['maintainer'] = ask('Maintainer: ')
  metadata['copyright'] = ask('Copyright: ')
  metadata['copyright_email'] = ask('Copyright Email: ')
  metadata['license'] = ask('License: ')
  metadata['version'] = ask('Version: ')

  metadata.delete_if { |_key, value| value.empty? }
  File.open('metadata.json', 'w') do |f|
    f.write(metadata.to_json)
  end
end
generate_map() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 145
def generate_map
  generator = InspecTools::GenerateMap.new
  generator.generate_example('mapping.yml')
end
inspec2ckl() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 122
def inspec2ckl
  metadata = '{}'
  if !options[:metadata].nil?
    metadata = File.read(options[:metadata])
  end
  ckl = InspecTools::Inspec.new(File.read(options[:inspec_json]), metadata).to_ckl
  File.write(options[:output], ckl)
end
inspec2csv() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 111
def inspec2csv
  csv = InspecTools::Inspec.new(File.read(options[:inspec_json])).to_csv
  Utils::CSVUtil.unpack_csv(csv, options[:output])
end
inspec2xccdf() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 64
def inspec2xccdf
  io = File.open(options[:inspec_json], 'rb')
  io.set_encoding_by_bom
  metadata = options[:metadata] ? JSON.parse(File.read(options[:metadata])) : {}
  inspec_tool = InspecTools::Inspec.new(io.read, metadata)
  attr_hsh = YAML.load_file(options[:attributes])
  xccdf = inspec_tool.to_xccdf(attr_hsh)
  File.write(options[:output], xccdf)
end
pdf2inspec() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 138
def pdf2inspec
  pdf = File.open(options[:pdf])
  profile = InspecTools::PDF.new(pdf, options[:output], options[:debug]).to_inspec
  Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
end
summary() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 197
def summary
  summary = InspecTools::Summary.new(options: options)
  summary.output_summary
end
xccdf2inspec() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 39
def xccdf2inspec
  xccdf = InspecTools::XCCDF.new(File.read(options[:xccdf]), options[:control_id] == 'vulnID', options[:replace_tags])
  profile = xccdf.to_inspec

  if !options[:metadata].nil?
    xccdf.inject_metadata(File.read(options[:metadata]))
  end

  Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
  if !options[:attributes].nil?
    attributes = xccdf.to_attributes
    File.write(options[:attributes], YAML.dump(attributes))
  end
end
xlsx2inspec() click to toggle source
# File lib/inspec_tools/plugin_cli.rb, line 99
def xlsx2inspec
  xlsx = Roo::Spreadsheet.open(options[:xlsx])
  mapping = YAML.load_file(options[:mapping])
  profile = InspecTools::XLSXTool.new(xlsx, mapping, options[:xlsx].split('/')[-1].split('.')[0], options[:verbose]).to_inspec(options[:control_name_prefix])
  Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
end