Class: InspecTools::CLI

Inherits:
Command show all
Defined in:
lib/inspec_tools/cli.rb

Instance Method Summary collapse

Methods inherited from Command

dispatch

Instance Method Details

#complianceObject



131
132
133
134
135
136
137
138
139
140
# File 'lib/inspec_tools/cli.rb', line 131

def compliance
  if options[:threshold_file].nil? && options[:threshold_inline].nil?
    puts 'Please provide threshold as a yaml file or inline yaml'
    exit(1)
  end
  threshold = YAML.load_file(options[:threshold_file]) unless options[:threshold_file].nil?
  threshold = YAML.safe_load(options[:threshold_inline]) unless options[:threshold_inline].nil?
  compliance = InspecTools::Summary.new(File.read(options[:inspec_json])).threshold(threshold)
  compliance ? exit(0) : exit(1)
end

#csv2inspecObject



49
50
51
52
53
54
# File 'lib/inspec_tools/cli.rb', line 49

def csv2inspec
  csv = CSV.read(options[:csv], encoding: 'ISO8859-1')
  mapping = YAML.load_file(options[:mapping])
  profile = CSVTool.new(csv, mapping, options[:csv].split('/')[-1].split('.')[0], options[:verbose]).to_inspec
  Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
end

#generate_mapObject



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

#inspec2cklObject



71
72
73
74
# File 'lib/inspec_tools/cli.rb', line 71

def inspec2ckl
  ckl = InspecTools::Inspec.new(File.read(options[:inspec_json])).to_ckl
  File.write(options[:output], ckl)
end

#inspec2csvObject



61
62
63
64
# File 'lib/inspec_tools/cli.rb', line 61

def inspec2csv
  csv = Inspec.new(File.read(options[:inspec_json])).to_csv
  Utils::CSVUtil.unpack_csv(csv, options[:output])
end

#inspec2xccdfObject



33
34
35
36
37
38
39
# File 'lib/inspec_tools/cli.rb', line 33

def inspec2xccdf
  json = File.read(options[:inspec_json])
  inspec_tool = InspecTools::Inspec.new(json)
  attr_hsh = YAML.load_file(options[:attributes])
  xccdf = inspec_tool.to_xccdf(attr_hsh)
  File.write(options[:output], xccdf)
end

#pdf2inspecObject



83
84
85
86
87
# File 'lib/inspec_tools/cli.rb', line 83

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

#summaryObject



119
120
121
122
# File 'lib/inspec_tools/cli.rb', line 119

def summary
  summary = InspecTools::Summary.new(File.read(options[:inspec_json])).to_summary
  File.write(options[:output], summary.to_json)
end

#versionObject



143
144
145
# File 'lib/inspec_tools/cli.rb', line 143

def version
  puts VERSION
end

#xccdf2inspecObject



18
19
20
21
22
23
24
25
26
# File 'lib/inspec_tools/cli.rb', line 18

def xccdf2inspec
  xccdf = XCCDF.new(File.read(options[:xccdf]))
  profile = xccdf.to_inspec
  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