Class: Dev::Node::Audit

Inherits:
Object show all
Defined in:
lib/firespring_dev_commands/node/audit.rb

Overview

Class which contains commands and customizations for node security audit reports

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Audit

Returns a new instance of Audit.



7
8
9
# File 'lib/firespring_dev_commands/node/audit.rb', line 7

def initialize(data)
  @data = JSON.parse(Dev::Common.new.strip_non_json(data))
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/firespring_dev_commands/node/audit.rb', line 5

def data
  @data
end

Instance Method Details

#to_reportObject

Convert the node audit data to the standardized audit report object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/firespring_dev_commands/node/audit.rb', line 12

def to_report
  ids = Set.new

  Dev::Audit::Report.new(
    data['vulnerabilities'].map do |_, vulnerability|
      # If the via ia a hash and the id is not already recorded, add the item to our report
      vulnerability['via'].map do |it|
        next unless it.is_a?(Hash)

        id = it['url']&.split('/')&.last
        next if ids.include?(id)

        ids << id
        Dev::Audit::Report::Item.new(
          id:,
          name: vulnerability['name'],
          title: it['title'],
          url: it['url'],
          severity: vulnerability['severity'],
          version: it['range']
        )
      end
    end.flatten.compact
  )
end