Class: Pipeline::Brakeman

Inherits:
BaseTask show all
Includes:
Util
Defined in:
lib/pipeline/tasks/brakeman.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) ⇒ Brakeman

Returns a new instance of Brakeman.



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

def initialize(trigger, tracker)
  super(trigger, tracker)
  @name = "Brakeman"
  @description = "Source analysis for Ruby"
  @stage = :code
  @labels << "code" << "ruby" << "rails"
end

Instance Method Details

#analyzeObject



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

def analyze
  # puts @result
  begin
    parsed = JSON.parse(@result)
    parsed["warnings"].each do |warning|
      file = relative_path(warning['file'], @trigger.path)

      detail = "#{warning['message']}\n#{warning['link']}"
      if ! warning['line']
        warning['line'] = "0"
      end
      if ! warning['code']
        warning['code'] = ""
      end
      source = { :scanner => @name, :file => file, :line => warning['line'], :code => warning['code'].lstrip }

      report warning["warning_type"], detail, source, severity(warning["confidence"]), fingerprint("#{warning['message']}#{warning['link']}#{severity(warning["confidence"])}#{source}")
    end
  rescue Exception => e
    Pipeline.warn e.message
    Pipeline.warn e.backtrace
  end
end

#runObject



19
20
21
22
# File 'lib/pipeline/tasks/brakeman.rb', line 19

def run
  rootpath = @trigger.path
  @result=runsystem(true, "brakeman", "-A", "-q", "-f", "json", "#{rootpath}")
end

#supported?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
# File 'lib/pipeline/tasks/brakeman.rb', line 48

def supported?
  supported=runsystem(true, "brakeman", "-v")
  if supported =~ /command not found/
    Pipeline.notify "Run: gem install brakeman"
    return false
  else
    return true
  end
end