Class: GitlabBundlerAuditParser::Parser

Inherits:
Object
  • Object
show all
Includes:
ScanSection, VulnerabilitiesSection
Defined in:
lib/gitlab_bundler_audit_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outfile: nil) ⇒ Parser

Returns a new instance of Parser.



12
13
14
# File 'lib/gitlab_bundler_audit_parser.rb', line 12

def initialize(outfile: nil)
  @outfile = outfile || 'gl-dependency-scanning-report.json'
end

Class Method Details

.run(outfile: nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/gitlab_bundler_audit_parser.rb', line 16

def self.run(outfile: nil)
  parser = new outfile: outfile
  parser.parse
  parser.create_audit
  parser.ouput_audit
end

Instance Method Details

#create_auditObject



28
29
30
31
32
33
34
# File 'lib/gitlab_bundler_audit_parser.rb', line 28

def create_audit
  @audit = {
    version: @parsed_audit['version']
  }
  @audit.merge! create_vulnerabilities_section(@parsed_audit)
  @audit.merge! create_scan_section(@parsed_audit)
end

#ouput_auditObject



36
37
38
39
40
# File 'lib/gitlab_bundler_audit_parser.rb', line 36

def ouput_audit
  encoded = JSON.generate(@audit)
  File.write(@outfile, encoded)
  @audit[:vulnerabilities].any?
end

#parseObject



23
24
25
26
# File 'lib/gitlab_bundler_audit_parser.rb', line 23

def parse
  input = $stdin.read
  @parsed_audit = JSON.parse(input)
end