data_importer/lib/importers/cvemon_cve_importer.rb

36 lines
723 B
Ruby
Raw Normal View History

2022-04-19 02:37:27 -05:00
# frozen_string_literal: true
2022-04-07 04:32:08 -05:00
require 'rest-client'
require 'json'
class CvemonCveImporter
2022-04-19 02:37:27 -05:00
attr_accessor :url
def initialize
@url = 'https://raw.githubusercontent.com/ARPSyndicate/cvemon/main/data.json'
end
2022-04-07 04:32:08 -05:00
2022-04-19 02:37:27 -05:00
def get_cve_data
r = RestClient::Request.execute(
method: :get,
url: url,
headers: { "Content-type": 'application/json' }
)
if r.code == 200
JSON.parse(r.body)
else
puts "HTTP Code #{r.code}"
2022-04-07 04:32:08 -05:00
end
2022-04-19 02:37:27 -05:00
end
2022-04-07 04:32:08 -05:00
2022-04-19 02:37:27 -05:00
def import
feed = get_cve_data
cve_ids = feed.keys
puts 'Now importing CvemonCves.'
cves = cve_ids.map do |cve_id|
{ cve_id: cve_id, urls: feed[cve_id] }
2022-04-07 04:32:08 -05:00
end
2022-04-19 02:37:27 -05:00
CvemonCve.upsert_all(cves, unique_by: :cve_id)
end
end