From 7aa0327da652a4e829689b1f924976d126b0e117 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 29 Nov 2011 11:45:41 -0800 Subject: [PATCH] Add option to exit with 1 if warnings are found --- bin/brakeman | 11 ++++++++++- lib/brakeman.rb | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/brakeman b/bin/brakeman index 83fbc802..133f51ae 100755 --- a/bin/brakeman +++ b/bin/brakeman @@ -147,6 +147,10 @@ OptionParser.new do |opts| end end + opts.on( "-s", "--exit-on-warn", "Exit code is non-zero if warnings found.") do |s| + options[:exit_on_warn] = s + end + opts.separator "" opts.on "-k", "--checks", "List all available vulnerability checks" do @@ -164,4 +168,9 @@ OptionParser.new do |opts| end end.parse!(ARGV) -Brakeman.run options +clean = Brakeman.run options + +if options[:exit_on_warn] && !clean + exit 1 +end + diff --git a/lib/brakeman.rb b/lib/brakeman.rb index 253aab73..4eecd392 100644 --- a/lib/brakeman.rb +++ b/lib/brakeman.rb @@ -184,5 +184,14 @@ module Brakeman else puts tracker.report.send(options[:output_format]) end + + if options[:exit_on_warn] + tracker.checks.warnings.each do |warning| + next if warning.confidence > options[:min_confidence] + return false + end + end + return true + end end -- GitLab