Class: Bundler::Audit::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/bundler/audit/cli.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bundler/audit/cli.rb', line 37

def check
  scanner    = Scanner.new
  vulnerable = false

  scanner.scan(:ignore => options.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


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bundler/audit/cli.rb', line 78

def print_advisory(gem, advisory)
  say "Name: ", :red
  say gem.name

  say "Version: ", :red
  say gem.version

  say "Advisory: ", :red
  say advisory.id

  say "Criticality: ", :red
  case advisory.criticality
  when :low    then say "Low"
  when :medium then say "Medium", :yellow
  when :high   then say "High", [:red, :bold]
  else              say "Unknown"
  end

  say "URL: ", :red
  say advisory.url

  if options.verbose?
    say "Description:", :red
    say

    print_wrapped advisory.description, :indent => 2
    say
  else

    say "Title: ", :red
    say advisory.title
  end

  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

  say
end


74
75
76
# File 'lib/bundler/audit/cli.rb', line 74

def print_warning(message)
  say message, :yellow
end

#say(string = "", color = nil) ⇒ Object (protected)



69
70
71
72
# File 'lib/bundler/audit/cli.rb', line 69

def say(string="", color=nil)
  color = nil unless $stdout.tty?
  super(string, color)
end

#versionObject



61
62
63
64
65
# File 'lib/bundler/audit/cli.rb', line 61

def version
  database = Database.new

  puts "#{File.basename($0)} #{VERSION} (advisories: #{database.size})"
end