Class: Dobby::Defect

Inherits:
Object
  • Object
show all
Defined in:
lib/dobby/defect.rb

Overview

A vulnerability which affects a particular Package

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier:, description:, severity:, link: nil, fixed_in: []) ⇒ Defect

Returns a new instance of Defect.

Parameters:

  • identifier (String)
  • description (String)
  • severity (Severity)
  • fixed_in (Array<Package>) (defaults to: [])
  • link (String) (defaults to: nil)

    External reference for the defect



40
41
42
43
44
45
46
# File 'lib/dobby/defect.rb', line 40

def initialize(identifier:, description:, severity:, link: nil, fixed_in: [])
  @identifier = identifier
  @description = description
  @severity = severity
  @fixed_in = fixed_in
  @link = link
end

Instance Attribute Details

#descriptionString (readonly)

Returns a description of the defect.

Returns:

  • (String)

    a description of the defect



10
11
12
# File 'lib/dobby/defect.rb', line 10

def description
  @description
end

#fixed_inArray<Package> (readonly)

Set of Packages representing the minimum fix version

Returns:



14
15
16
# File 'lib/dobby/defect.rb', line 14

def fixed_in
  @fixed_in
end

#flagObject

Returns the value of attribute flag.



22
23
24
# File 'lib/dobby/defect.rb', line 22

def flag
  @flag
end

#identifierString (readonly)

Returns unique identifier for this defect, usually a CVE ID.

Returns:

  • (String)

    unique identifier for this defect, usually a CVE ID



7
8
9
# File 'lib/dobby/defect.rb', line 7

def identifier
  @identifier
end

Returns the value of attribute link.



20
21
22
# File 'lib/dobby/defect.rb', line 20

def link
  @link
end

#severityString (readonly)

Returns (low, medium, high) the priority category assigned to this Defect.

Returns:

  • (String)

    (low, medium, high) the priority category assigned to this Defect



18
19
20
# File 'lib/dobby/defect.rb', line 18

def severity
  @severity
end

Instance Method Details

#filtered?(filter: :default, flag_filter: :default) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



55
56
57
58
59
60
61
# File 'lib/dobby/defect.rb', line 55

def filtered?(filter: :default, flag_filter: :default)
  return true if flag_filtered?(flag_filter)
  return false if filter == :default
  return !fix_available? if filter == :only_fixed

  raise UnknownFilterError, filter
end

#fix_available?Boolean

The Defect has at least one released fix version

Returns:

  • (Boolean)


51
52
53
# File 'lib/dobby/defect.rb', line 51

def fix_available?
  fixed_in.any? { |v| v.version != Package::MAX_VERSION }
end

#flag_filtered?(filter) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
# File 'lib/dobby/defect.rb', line 67

def flag_filtered?(filter)
  return !flag.nil? if filter == :default
  return false if flag == filter

  true
end

#flagged?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/dobby/defect.rb', line 63

def flagged?
  !flag.nil?
end

#to_hashHash

Simple hash serializer for a Defect

Returns:

  • (Hash)


26
27
28
29
30
31
32
33
# File 'lib/dobby/defect.rb', line 26

def to_hash
  {
    identifier: identifier,
    description: description,
    severity: severity.to_s,
    fixed_in: fixed_in.map(&:to_s)
  }
end