Class: Bundler::Patch::Scanner

Inherits:
Boson::Runner
  • Object
show all
Defined in:
lib/bundler/patch/scanner.rb

Instance Method Summary collapse

Constructor Details

#initializeScanner

Returns a new instance of Scanner.



6
7
8
# File 'lib/bundler/patch/scanner.rb', line 6

def initialize
  @no_vulns_message = 'No known vulnerabilities to update.'
end

Instance Method Details

#patch(options = {}) ⇒ Object

TODO: Revamp the commands now that we’ve broadened into security specific and generic



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bundler/patch/scanner.rb', line 32

def patch(options={}) # TODO: Revamp the commands now that we've broadened into security specific and generic
  header

  gem_patches, warnings = AdvisoryConsolidator.new(options).patch_gemfile_and_get_gem_specs_to_patch

  unless warnings.empty?
    warnings.each do |gp|
      # TODO: Bundler.ui
      puts "* Could not attempt upgrade for #{gp.gem_name} from #{gp.old_version} to any patched versions " \
        + "#{gp.patched_versions.join(', ')}. Most often this is because a major version increment would be " \
        + "required and it's safer for a major version increase to be done manually."
    end
  end

  if gem_patches.empty?
    puts @no_vulns_message
  else
    gem_patches.each do |gp|
      puts "Attempting #{gp.gem_name}: #{gp.old_version} => #{gp.new_version}" # TODO: Bundler.ui
    end

    puts "Updating '#{gem_patches.map(&:gem_name).join(' ')}' to address vulnerabilities"
    conservative_update(gem_patches, options.merge(patching: true))
  end
end

#scan(options = {}) ⇒ Object

TODO: Revamp the commands now that we’ve broadened into security specific and generic



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bundler/patch/scanner.rb', line 13

def scan(options={}) # TODO: Revamp the commands now that we've broadened into security specific and generic
  header
  gem_patches = AdvisoryConsolidator.new(options).vulnerable_gems

  if gem_patches.empty?
    puts @no_vulns_message
  else
    puts # extra line to separate from advisory db update text
    puts 'Detected vulnerabilities:'
    puts '-------------------------'
    puts gem_patches.map(&:to_s).uniq.sort.join("\n")
  end
end

#update(options = {}) ⇒ Object

TODO: Revamp the commands now that we’ve broadened into security specific and generic



65
66
67
68
69
# File 'lib/bundler/patch/scanner.rb', line 65

def update(options={}) # TODO: Revamp the commands now that we've broadened into security specific and generic
  header
  gem_patches = (options.delete(:gems_to_update) || []).map { |gem_name| GemPatch.new(gem_name: gem_name) }
  conservative_update(gem_patches, options.merge(updating: true))
end