Class: Bundler::Audit::CLI
- Inherits:
-
Thor
- Object
- Thor
- Bundler::Audit::CLI
- Defined in:
- lib/bundler/audit/cli.rb
Constant Summary collapse
- CRITICALITY_MAP =
{ :low => ["Low"], :medium => ["Medium", :yellow], :high => ["High", [:red, :bold]], }
Instance Method Summary collapse
- #check ⇒ Object
- #print_advisory(gem, advisory) ⇒ Object protected
- #print_advisory_details(advisory) ⇒ Object protected
- #print_advisory_solution(advisory) ⇒ Object protected
- #print_affected_gem(gem) ⇒ Object protected
- #print_warning(message) ⇒ Object protected
- #say(message = "", color = nil) ⇒ Object protected
- #update ⇒ Object
- #version ⇒ Object
Instance Method Details
#check ⇒ Object
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 |
# File 'lib/bundler/audit/cli.rb', line 38 def check scanner = Scanner.new vulnerable = false # attempt update the database before doing a scan scanner.database.update! scanner.scan(:ignore => .ignore) do |result| vulnerable = true case result when Scanner::InsecureSource print_warning "Insecure Source URI found: #{result.source}" when Scanner::UnpatchedGem print_advisory result.gem, result.advisory end end if vulnerable say "Unpatched versions found!", :red exit 1 else say "No unpatched versions found", :green end end |
#print_advisory(gem, advisory) ⇒ Object (protected)
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bundler/audit/cli.rb', line 90 def print_advisory(gem, advisory) print_affected_gem(gem) say "Advisory: ", :red say advisory.id say "Criticality: ", :red say *(CRITICALITY_MAP[advisory.criticality] || "Unknown") say "URL: ", :red say advisory.url print_advisory_details advisory print_advisory_solution advisory say end |
#print_advisory_details(advisory) ⇒ Object (protected)
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bundler/audit/cli.rb', line 117 def print_advisory_details(advisory) if .verbose? say "Description:", :red say print_wrapped advisory.description, :indent => 2 say else say "Title: ", :red say advisory.title end end |
#print_advisory_solution(advisory) ⇒ Object (protected)
130 131 132 133 134 135 136 137 138 |
# File 'lib/bundler/audit/cli.rb', line 130 def print_advisory_solution(advisory) unless advisory.patched_versions.empty? say "Solution: upgrade to ", :red say advisory.patched_versions.join(', ') else say "Solution: ", :red say "remove or disable this gem until a patch is available!", [:red, :bold] end end |
#print_affected_gem(gem) ⇒ Object (protected)
109 110 111 112 113 114 115 |
# File 'lib/bundler/audit/cli.rb', line 109 def print_affected_gem(gem) say "Name: ", :red say gem.name say "Version: ", :red say gem.version end |
#print_warning(message) ⇒ Object (protected)
86 87 88 |
# File 'lib/bundler/audit/cli.rb', line 86 def print_warning() say , :yellow end |
#say(message = "", color = nil) ⇒ Object (protected)
81 82 83 84 |
# File 'lib/bundler/audit/cli.rb', line 81 def say(="", color=nil) color = nil unless $stdout.tty? super(.to_s, color) end |