Class: Rails::Guarddog::Reporters::ConsoleReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/guarddog/reporters/console_reporter.rb

Constant Summary collapse

GREEN =
"\e[32m"
RED =
"\e[31m"
YELLOW =
"\e[33m"
CYAN =
"\e[36m"
BOLD =
"\e[1m"
RESET =
"\e[0m"

Instance Method Summary collapse

Constructor Details

#initialize(findings) ⇒ ConsoleReporter

Returns a new instance of ConsoleReporter.



12
13
14
# File 'lib/rails/guarddog/reporters/console_reporter.rb', line 12

def initialize(findings)
  @findings = findings
end

Instance Method Details

#reportObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails/guarddog/reporters/console_reporter.rb', line 16

def report
  puts "\n" + "="*60
  puts "Rails GuardDog Security Report".center(60)
  puts "="*60 + "\n"

  if @findings.empty?
    puts "#{GREEN}✓ No security issues found!#{RESET}"
    return
  end

  @findings.group_by(&:severity).each do |severity, findings|
    color = severity_color(severity)
    puts "\n#{BOLD}#{color}[#{severity.upcase}] (#{findings.count})#{RESET}"
    findings.each do |finding|
      puts "  #{finding.category}#{finding.message}"
      puts "    #{CYAN}#{finding.file}:#{finding.line}#{RESET}"
      puts "    Fix: #{finding.remediation}\n"
    end
  end

  puts "\n" + "="*60
  puts "#{BOLD}Total findings: #{@findings.count}#{RESET}"
  puts "="*60 + "\n"
end