Class: CisaKevVulnerability

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/vulnerability/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cve_id:, vendor:, product:, vulnerability_name:, added_date:, due_date:, description:, required_action:, ransomware_campaign:, notes:) ⇒ CisaKevVulnerability

Returns a new instance of CisaKevVulnerability.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/domain/vulnerability/model.rb', line 81

def initialize(
  cve_id:,
  vendor:,
  product:,
  vulnerability_name:,
  added_date:,
  due_date:,
  description:,
  required_action:,
  ransomware_campaign:,
  notes:
)
  @cve_id = cve_id
  @vendor = vendor
  @product = product
  @vulnerability_name = vulnerability_name
  @added_date = added_date
  @due_date = due_date
  @description = description
  @required_action = required_action
  @ransomware_campaign = ransomware_campaign
  @notes = notes
end

Instance Attribute Details

#added_dateObject

Returns the value of attribute added_date.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def added_date
  @added_date
end

#cve_idObject

Returns the value of attribute cve_id.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def cve_id
  @cve_id
end

#descriptionObject

Returns the value of attribute description.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def description
  @description
end

#due_dateObject

Returns the value of attribute due_date.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def due_date
  @due_date
end

#notesObject

Returns the value of attribute notes.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def notes
  @notes
end

#productObject

Returns the value of attribute product.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def product
  @product
end

#ransomware_campaignObject

Returns the value of attribute ransomware_campaign.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def ransomware_campaign
  @ransomware_campaign
end

#required_actionObject

Returns the value of attribute required_action.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def required_action
  @required_action
end

#vendorObject

Returns the value of attribute vendor.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def vendor
  @vendor
end

#vulnerability_nameObject

Returns the value of attribute vulnerability_name.



51
52
53
# File 'lib/domain/vulnerability/model.rb', line 51

def vulnerability_name
  @vulnerability_name
end

Class Method Details

.columnsObject



66
67
68
69
70
# File 'lib/domain/vulnerability/model.rb', line 66

def self.columns
  methods = instance_methods - Object.methods
  methods.select { |m| m.to_s.end_with?('=') }
         .map { |m| m.to_s.chop.to_sym }
end

.from_json(json) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/domain/vulnerability/model.rb', line 105

def self.from_json(json)
  CisaKevVulnerability.new(
    cve_id: json['cveID'],
    vendor: json['vendorProject'],
    product: json['product'],
    vulnerability_name: json['vulnerabilityName'],
    added_date: json['dateAdded'],
    due_date: json['dueDate'],
    description: json['shortDescription'],
    required_action: json['requiredAction'],
    ransomware_campaign: json['knownRansomwareCampaignUse'],
    notes: json['notes']
  )
end

.primary_keyObject



72
73
74
# File 'lib/domain/vulnerability/model.rb', line 72

def self.primary_key
  ['cve_id']
end

.table_nameObject



62
63
64
# File 'lib/domain/vulnerability/model.rb', line 62

def self.table_name
  'vulnerability_cisa_kev'
end

Instance Method Details

#to_csvObject



76
77
78
79
# File 'lib/domain/vulnerability/model.rb', line 76

def to_csv
  self.class.columns
      .map { |column| send(column.to_sym) }
end

#to_json(*_args) ⇒ Object

Converts the instance into a JSON string



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/domain/vulnerability/model.rb', line 121

def to_json(*_args)
  hash = {
    cveID: @cve_id,
    vendorProject: @vendor,
    product: @product,
    vulnerabilityName: @vulnerability_name,
    dateAdded: @added_date,
    dueDate: @due_date,
    shortDescription: @description,
    requiredAction: @required_action,
    knownRansomwareCampaignUse: @ransomware_campaign,
    notes: @notes
  }
  JSON.generate(hash)
end

#to_sObject



137
138
139
# File 'lib/domain/vulnerability/model.rb', line 137

def to_s
  [cve_id, vendor, product, vulnerability_name, due_date, description].join ','
end