Class: Bundler::Audit::Scanner
- Inherits:
-
Object
- Object
- Bundler::Audit::Scanner
- Defined in:
- lib/bundler/audit/scanner.rb
Defined Under Namespace
Classes: InsecureSource, UnpatchedGem
Instance Attribute Summary collapse
-
#database ⇒ Database
readonly
The advisory database.
-
#lockfile ⇒ Bundler::LockfileParser
readonly
The parsed
Gemfile.lock
from the project. -
#root ⇒ Object
readonly
Project root directory.
Instance Method Summary collapse
-
#initialize(root = Dir.pwd, gemfile_lock = 'Gemfile.lock') ⇒ Scanner
constructor
Initializes a scanner.
-
#scan(options = {}) {|result| ... } ⇒ Enumerator
Scans the project for issues.
-
#scan_sources(options = {}) {|result| ... } ⇒ Enumerator
Scans the gem sources in the lockfile.
-
#scan_specs(options = {}) {|result| ... } ⇒ Enumerator
Scans the gem sources in the lockfile.
Constructor Details
#initialize(root = Dir.pwd, gemfile_lock = 'Gemfile.lock') ⇒ Scanner
Initializes a scanner.
42 43 44 45 46 47 48 |
# File 'lib/bundler/audit/scanner.rb', line 42 def initialize(root=Dir.pwd,gemfile_lock='Gemfile.lock') @root = File.(root) @database = Database.new @lockfile = LockfileParser.new( File.read(File.join(@root,gemfile_lock)) ) end |
Instance Attribute Details
#database ⇒ Database (readonly)
The advisory database
23 24 25 |
# File 'lib/bundler/audit/scanner.rb', line 23 def database @database end |
#lockfile ⇒ Bundler::LockfileParser (readonly)
The parsed Gemfile.lock
from the project
31 32 33 |
# File 'lib/bundler/audit/scanner.rb', line 31 def lockfile @lockfile end |
#root ⇒ Object (readonly)
Project root directory
26 27 28 |
# File 'lib/bundler/audit/scanner.rb', line 26 def root @root end |
Instance Method Details
#scan(options = {}) {|result| ... } ⇒ Enumerator
Scans the project for issues.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bundler/audit/scanner.rb', line 68 def scan(={},&block) return enum_for(__method__,) unless block ignore = Set[] ignore += [:ignore] if [:ignore] scan_sources(,&block) scan_specs(,&block) return self end |
#scan_sources(options = {}) {|result| ... } ⇒ Enumerator
Scans the gem sources in the lockfile.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/bundler/audit/scanner.rb', line 99 def scan_sources(={}) return enum_for(__method__,) unless block_given? @lockfile.sources.map do |source| case source when Source::Git case source.uri when /^git:/, /^http:/ unless internal_source?(source.uri) yield InsecureSource.new(source.uri) end end when Source::Rubygems source.remotes.each do |uri| if (uri.scheme == 'http' && !internal_source?(uri)) yield InsecureSource.new(uri.to_s) end end end end end |
#scan_specs(options = {}) {|result| ... } ⇒ Enumerator
Scans the gem sources in the lockfile.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/bundler/audit/scanner.rb', line 143 def scan_specs(={}) return enum_for(__method__,) unless block_given? ignore = Set[] ignore += [:ignore] if [:ignore] @lockfile.specs.each do |gem| @database.check_gem(gem) do |advisory| unless (ignore.include?(advisory.cve_id) || ignore.include?(advisory.osvdb_id)) yield UnpatchedGem.new(gem,advisory) end end end end |