Class: ScaBox::ContainerScanner

Inherits:
Scanner
  • Object
show all
Defined in:
lib/scabox_sdk/container.rb

Constant Summary

Constants inherited from Scanner

Scanner::DEFAULT_SOLUTION

Instance Attribute Summary

Attributes inherited from Scanner

#description, #issues, #name, #support, #timeout

Instance Method Summary collapse

Methods inherited from Scanner

#add_issue, #build_title, #check_info_flag, #check_output_flag, #enable_color, #filename_for_plugin, #gen_random_tmp_filename, #gen_random_tmp_filename_json, #get_code_version, #info, #parse_json_from_file, #parse_json_from_str, #save_results, #start_scan, #txt_output

Methods included from Runner

#command?, #run_cmd, #run_cmd_with_timeout

Methods included from Printer

#coloring, included, #print_debug, #print_error, #print_normal, #print_success, #print_title, #print_with_label, #suppress_output?

Constructor Details

#initialize(params) ⇒ ContainerScanner

Returns a new instance of ContainerScanner.



8
9
10
# File 'lib/scabox_sdk/container.rb', line 8

def initialize(params)
  super(params)
end

Instance Method Details

#parse_opts(args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/scabox_sdk/container.rb', line 25

def parse_opts(args)
  @opts = OpenStruct.new
  @opts.image_name  = nil
  @opts.image_file  = nil
  @opts.output      = nil
  @opts.format      = :json
  @opts.verbose     = false
  @opts.info        = false
  @opts.color       = true
  @opts.output_stdout = false


  opt_parser = OptionParser.new do |opts|
    opts.on('-n', '--image-name=IMAGE_NAME', 'Name of image to be scanned') do |image_name|
      @opts.image_name = image_name
    end

    opts.on('-p', '--image-file=IMAGE_PATH', 'Path of image to be scanned') do |image_file|
      @opts.image_file = image_file
    end

    opts.on('-f', '--format=FORMAT', 'Format to save result (json or txt)') do |f|
      @opts.format = f.to_sym
    end

    opts.on('-o', '--output=OUTPUT', 'File to save result') do |output|
      @opts.output = output
    end

    opts.on('--output-stdout', 'Print result to stdout') do
      @opts.output_stdout = true
    end

    opts.on("-v", '--[no-]verbose', 'Run verbosely') do |v|
      @opts.verbose = v
    end

    opts.on("-i", '--info', 'Info about the scanner') do
      @opts.info = true
    end

    opts.on('', '--[no-]color', 'Enable/disable coloring') do |v|
      @opts.color = v
      enable_color(@opts.color)
    end
  end

  opt_parser.parse!(args)
  print_debug(@opts.inspect) if @opts.verbose
  @opts
end

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/scabox_sdk/container.rb', line 12

def run
  parse_opts(ARGV)
  check_info_flag

  if @opts.image_name.nil? and @opts.image_file.nil?
    print_error("No image passed")
    exit 1
  end

  check_output_flag
  start_scan
end