summaryrefslogtreecommitdiff
blob: 0ecea877accb80d2724c49db79226ecf143d6f07 (plain)
1
2
3
4
5
6
7
8
9
10
11
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
37
38
39
40
require 'date'

# A version 1 GLSA
class GLSAv1
  attr_reader :id, :title, :synopsis, :product, :date, :revised, :revision, :bugs, :access, :packages,
    :background, :description, :severity, :impact, :workaround, :resolution, :references

  def parse(xml)
    @id          = xml.root['id']
    @title       = xml.xpath('/glsa/title/text()').first.content
    @synopsis    = xml.xpath('/glsa/synopsis/text()').first.content
    @product     = xml.xpath('/glsa/product/text()').first.content
    @date        = DateTime.parse(xml.xpath('/glsa/announced/text()').first.content)
    @revised,
    @revision    = xml.xpath('/glsa/revised/text()').first.content.split(': ')
    @revised     = DateTime.parse(@revised)

    @bugs        = xml.xpath('/glsa/bug/text()').map {|bug_node| bug_node.content.to_i }
    @access      = xml.xpath('/glsa/access/text()').first.content

    @packages    = {}
    xml.xpath('/glsa/affected/package').each do |package|
      @packages[package['name'] + ':' + package['arch']] = {
        auto:       package['auto'] == 'yes',
        unaffected: package.xpath('./unaffected').map {|ver| [ver['range'], ver.content] },
        vulnerable: package.xpath('./vulnerable').map {|ver| [ver['range'], ver.content] }
      }
    end

    @background  = xml.xpath('/glsa/background').first.children.to_xml.strip
    @description = xml.xpath('/glsa/description').first.children.to_xml.strip
    @severity    = xml.xpath('/glsa/impact').first['type']
    @impact      = xml.xpath('/glsa/impact').first.children.to_xml.strip
    @workaround  = xml.xpath('/glsa/workaround').first.children.to_xml.strip
    @resolution  = xml.xpath('/glsa/resolution').first.children.to_xml.strip
    @references  = xml.xpath('/glsa/references/uri').map {|uri| [uri.content, uri['link']] }

    self
  end
end