Class: Pipeline::DawnScanner

Inherits:
BaseTask show all
Includes:
Util
Defined in:
lib/pipeline/tasks/dawnscanner.rb

Instance Attribute Summary

Attributes inherited from BaseTask

#appname, #description, #findings, #labels, #name, #stage, #trigger, #warnings

Instance Method Summary collapse

Methods included from Util

#fingerprint, #relative_path, #runsystem, #strip_archive_path

Methods inherited from BaseTask

#directories_with?, #report, #severity, #warn

Constructor Details

#initialize(trigger, tracker) ⇒ DawnScanner

Returns a new instance of DawnScanner.



10
11
12
13
14
15
16
# File 'lib/pipeline/tasks/dawnscanner.rb', line 10

def initialize(trigger, tracker)
  super(trigger, tracker)
  @name = "DawnScanner"
  @description = "DawnScanner ruby analyzer"
  @stage = :code
  @labels << "code"
end

Instance Method Details

#analyzeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pipeline/tasks/dawnscanner.rb', line 26

def analyze
  begin
    @results.each do |result|
      description = result['name'].gsub('\n',' ')
      detail = "#{result['message']}\n#{result['remediation']}\n#{result['cve_link']}"
      source = {:scanner => @name, :file => nil, :line => nil, :code => nil}
      sev = severity(result['severity'])
      fprint = fingerprint("#{description}#{detail}#{source}#{sev}")

      report description, detail, source, sev, fprint
    end
  rescue Exception => e
    Pipeline.warn e.message
    Pipeline.warn e.backtrace
  ensure
    File.unlink @results_file
  end
end

#runObject



18
19
20
21
22
23
24
# File 'lib/pipeline/tasks/dawnscanner.rb', line 18

def run
  Dir.chdir("#{@trigger.path}") do
    @results_file = Tempfile.new(['dawnresults', 'xml'])
    runsystem(true, "dawn", "-F", "#{@results_file.path}", "-j", ".")
    @results = JSON.parse(File.read("#{@results_file.path}"))['vulnerabilities']
  end
end

#supported?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
# File 'lib/pipeline/tasks/dawnscanner.rb', line 45

def supported?
  supported=runsystem(true, "dawn", "--version")
  if supported =~ /command not found/
    Pipeline.notify "Install dawnscanner: 'gem install dawnscanner'"
    return false
  else
    return true
  end
end