Class: Package::Audit::Npm::VulnerabilityFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/package/audit/npm/vulnerability_finder.rb

Constant Summary collapse

AUDIT_ADVISORY_REGEX =
/^{"type":"auditAdvisory".*$/

Instance Method Summary collapse

Constructor Details

#initialize(dir, pkgs) ⇒ VulnerabilityFinder

Returns a new instance of VulnerabilityFinder.



10
11
12
13
14
# File 'lib/package/audit/npm/vulnerability_finder.rb', line 10

def initialize(dir, pkgs)
  @dir = dir
  @pkg_hash = pkgs.to_h { |pkg| [pkg.name, pkg] }
  @vuln_hash = {}
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/package/audit/npm/vulnerability_finder.rb', line 16

def run
  json_string_lines = `#{format(Const::Cmd::YARN_AUDIT_JSON, @dir)}`
  array = json_string_lines.scan(AUDIT_ADVISORY_REGEX)

  vulnerability_json_array = JSON.parse("[#{array.join(',')}]", symbolize_names: true)
  vulnerability_json_array.each do |vulnerability_json|
    (vulnerability_json)
  end
  @vuln_hash.values
end