Class: HolePicker::ScanReporter

Inherits:
Object
  • Object
show all
Includes:
HasLogger
Defined in:
lib/holepicker/scan_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasLogger

included, #logger

Constructor Details

#initializeScanReporter

Returns a new instance of ScanReporter.



11
12
13
14
15
16
# File 'lib/holepicker/scan_reporter.rb', line 11

def initialize
  @safe_gemfiles = []
  @vulnerable_gemfiles = []
  @vulnerable_gems = []
  @vulnerabilities = Set.new
end

Instance Attribute Details

#safe_gemfilesObject (readonly)

Returns the value of attribute safe_gemfiles.



9
10
11
# File 'lib/holepicker/scan_reporter.rb', line 9

def safe_gemfiles
  @safe_gemfiles
end

#vulnerabilitiesObject (readonly)

Returns the value of attribute vulnerabilities.



9
10
11
# File 'lib/holepicker/scan_reporter.rb', line 9

def vulnerabilities
  @vulnerabilities
end

#vulnerable_gemfilesObject (readonly)

Returns the value of attribute vulnerable_gemfiles.



9
10
11
# File 'lib/holepicker/scan_reporter.rb', line 9

def vulnerable_gemfiles
  @vulnerable_gemfiles
end

#vulnerable_gemsObject (readonly)

Returns the value of attribute vulnerable_gems.



9
10
11
# File 'lib/holepicker/scan_reporter.rb', line 9

def vulnerable_gems
  @vulnerable_gems
end

Instance Method Details

#add_safe_gemfile(path) ⇒ Object



27
28
29
# File 'lib/holepicker/scan_reporter.rb', line 27

def add_safe_gemfile(path)
  @safe_gemfiles << path
end

#add_vulnerable_gem(gem, vulnerabilities) ⇒ Object



18
19
20
21
# File 'lib/holepicker/scan_reporter.rb', line 18

def add_vulnerable_gem(gem, vulnerabilities)
  @vulnerabilities.merge(vulnerabilities)
  @vulnerable_gems << gem
end

#add_vulnerable_gemfile(path) ⇒ Object



23
24
25
# File 'lib/holepicker/scan_reporter.rb', line 23

def add_vulnerable_gemfile(path)
  @vulnerable_gemfiles << path
end


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/holepicker/scan_reporter.rb', line 35

def print_report
  if success?
    if @safe_gemfiles.empty?
      logger.warn "No gemfiles found - are you sure the paths are correct?"
    else
      logger.info "No vulnerabilities found."
    end
  else
    gem_count = @vulnerable_gems.length
    gemfile_count = @vulnerable_gemfiles.length

    gems = Utils.pluralize(gem_count, 'gem')
    gemfiles = Utils.pluralize(gemfile_count, 'gemfile')

    logger.fail "#{gem_count} vulnerable #{gems} found in #{gemfile_count} #{gemfiles}!\n"

    report_vulnerabilities
    print_notes if @vulnerabilities.any?(&:note)
  end
end

#success?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/holepicker/scan_reporter.rb', line 31

def success?
  @vulnerable_gems.empty?
end