Class: Bundler::Audit::Scanner

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

Defined Under Namespace

Classes: InsecureSource, UnpatchedGem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ Scanner

Initializes a scanner.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The path to the project root.



36
37
38
39
40
41
42
# File 'lib/bundler/audit/scanner.rb', line 36

def initialize(root=Dir.pwd)
  @root     = File.expand_path(root)
  @database = Database.new
  @lockfile = LockfileParser.new(
    File.read(File.join(@root,'Gemfile.lock'))
  )
end

Instance Attribute Details

#databaseDatabase (readonly)

The advisory database

Returns:



20
21
22
# File 'lib/bundler/audit/scanner.rb', line 20

def database
  @database
end

#lockfileBundler::LockfileParser (readonly)

The parsed Gemfile.lock from the project

Returns:

  • (Bundler::LockfileParser)


28
29
30
# File 'lib/bundler/audit/scanner.rb', line 28

def lockfile
  @lockfile
end

#rootObject (readonly)

Project root directory



23
24
25
# File 'lib/bundler/audit/scanner.rb', line 23

def root
  @root
end

Instance Method Details

#scan(options = {}) {|result| ... } ⇒ Enumerator

Scans the project for issues.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :ignore (Array<String>)

    The advisories to ignore.

Yields:

  • (result)

    The given block will be passed the results of the scan.

Yield Parameters:

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bundler/audit/scanner.rb', line 62

def scan(options={})
  return enum_for(__method__,options) unless block_given?

  ignore = Set[]
  ignore += options[:ignore] if options[:ignore]

  @lockfile.sources.map do |source|
    case source
    when Source::Git
      case source.uri
      when /^git:/, /^http:/
        yield InsecureSource.new(source.uri)
      end
    when Source::Rubygems
      source.remotes.each do |uri|
        if uri.scheme == 'http'
          yield InsecureSource.new(uri.to_s)
        end
      end
    end
  end

  @lockfile.specs.each do |gem|
    @database.check_gem(gem) do |advisory|
      unless ignore.include?(advisory.id)
        yield UnpatchedGem.new(gem,advisory)
      end
    end
  end

  return self
end