Class: YAVDB::Advisory

Inherits:
Struct
  • Object
show all
Defined in:
lib/yavdb/dtos/advisory.rb

Overview

TODO: Enable Style/StructInheritance - check attr_reader: or initialize method

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#affected_package ⇒ Object

Returns the value of attribute affected_package

Returns:

  • (Object) —

    the current value of affected_package



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def affected_package
  @affected_package
end

#created_date ⇒ Object

Returns the value of attribute created_date

Returns:

  • (Object) —

    the current value of created_date



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def created_date
  @created_date
end

#credit ⇒ Object

Returns the value of attribute credit

Returns:

  • (Object) —

    the current value of credit



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def credit
  @credit
end

#cve ⇒ Object

Returns the value of attribute cve

Returns:

  • (Object) —

    the current value of cve



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def cve
  @cve
end

#cvss_v2_score ⇒ Object

Returns the value of attribute cvss_v2_score

Returns:

  • (Object) —

    the current value of cvss_v2_score



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def cvss_v2_score
  @cvss_v2_score
end

#cvss_v2_vector ⇒ Object

Returns the value of attribute cvss_v2_vector

Returns:

  • (Object) —

    the current value of cvss_v2_vector



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def cvss_v2_vector
  @cvss_v2_vector
end

#cvss_v3_score ⇒ Object

Returns the value of attribute cvss_v3_score

Returns:

  • (Object) —

    the current value of cvss_v3_score



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def cvss_v3_score
  @cvss_v3_score
end

#cvss_v3_vector ⇒ Object

Returns the value of attribute cvss_v3_vector

Returns:

  • (Object) —

    the current value of cvss_v3_vector



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def cvss_v3_vector
  @cvss_v3_vector
end

#cwe ⇒ Object

Returns the value of attribute cwe

Returns:

  • (Object) —

    the current value of cwe



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def cwe
  @cwe
end

#description ⇒ Object

Returns the value of attribute description

Returns:

  • (Object) —

    the current value of description



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def description
  @description
end

#disclosed_date ⇒ Object

Returns the value of attribute disclosed_date

Returns:

  • (Object) —

    the current value of disclosed_date



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def disclosed_date
  @disclosed_date
end

#id ⇒ Object

Returns the value of attribute id

Returns:

  • (Object) —

    the current value of id



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def id
  @id
end

#last_modified_date ⇒ Object

Returns the value of attribute last_modified_date

Returns:

  • (Object) —

    the current value of last_modified_date



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def last_modified_date
  @last_modified_date
end

#osvdb ⇒ Object

Returns the value of attribute osvdb

Returns:

  • (Object) —

    the current value of osvdb



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def osvdb
  @osvdb
end

#package_manager ⇒ Object

Returns the value of attribute package_manager

Returns:

  • (Object) —

    the current value of package_manager



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def package_manager
  @package_manager
end

#patched_versions ⇒ Object

Returns the value of attribute patched_versions

Returns:

  • (Object) —

    the current value of patched_versions



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def patched_versions
  @patched_versions
end

#references ⇒ Object

Returns the value of attribute references

Returns:

  • (Object) —

    the current value of references



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def references
  @references
end

#severity ⇒ Object

Returns the value of attribute severity

Returns:

  • (Object) —

    the current value of severity



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def severity
  @severity
end

#source_url ⇒ Object

Returns the value of attribute source_url

Returns:

  • (Object) —

    the current value of source_url



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def source_url
  @source_url
end

#title ⇒ Object

Returns the value of attribute title

Returns:

  • (Object) —

    the current value of title



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def title
  @title
end

#unaffected_versions ⇒ Object

Returns the value of attribute unaffected_versions

Returns:

  • (Object) —

    the current value of unaffected_versions



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def unaffected_versions
  @unaffected_versions
end

#vulnerable_versions ⇒ Object

Returns the value of attribute vulnerable_versions

Returns:

  • (Object) —

    the current value of vulnerable_versions



19
20
21
# File 'lib/yavdb/dtos/advisory.rb', line 19

def vulnerable_versions
  @vulnerable_versions
end

Class Method Details

.load(path) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/yavdb/dtos/advisory.rb', line 44

def self.load(path)
  data = YAML.load_file(path)

  raise("Advisory data in #{path.dump} was not an Array") unless data.is_a?(Array)

  data.map do |advisory|
    raise("Advisory data in #{path.dump} was not a Hash") unless advisory.is_a?(Hash)

    new(
      advisory['id'],
      advisory['title'],
      advisory['description'],
      advisory['affected_package'],
      advisory['vulnerable_versions'],
      advisory['unaffected_versions'],
      advisory['patched_versions'],
      advisory['severity'],
      advisory['package_manager'],
      advisory['cve'],
      advisory['cwe'],
      advisory['osvdb'],
      advisory['cvss_v2_vector'],
      advisory['cvss_v2_score'],
      advisory['cvss_v3_vector'],
      advisory['cvss_v3_score'],
      advisory['disclosed_date'],
      advisory['created_date'],
      advisory['last_modified_date'],
      advisory['credit'],
      advisory['references'],
      advisory['source_url']
    )
  end
end

Instance Method Details

#to_json(*args) ⇒ Object



97
98
99
# File 'lib/yavdb/dtos/advisory.rb', line 97

def to_json(*args)
  to_map.to_json(*args)
end

#to_map ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/yavdb/dtos/advisory.rb', line 79

def to_map
  map = {}
  members.each do |m|
    if !self[m] ||
       (self[m].is_a?(String) && self[m].empty?) ||
       (self[m].is_a?(Array) && self[m].none?)
      next
    elsif self[m].is_a?(Struct)
      map[m.to_s] = self[m].to_map
    elsif self[m].is_a?(Array)
      map[m.to_s] = self[m].sort_by { |c| c.to_s.downcase }
    else
      map[m.to_s] = self[m]
    end
  end
  map
end

#to_yaml(*args) ⇒ Object



101
102
103
# File 'lib/yavdb/dtos/advisory.rb', line 101

def to_yaml(*args)
  to_map.to_yaml(*args)
end