35 lines
723 B
Ruby
35 lines
723 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rest-client'
|
|
require 'json'
|
|
|
|
class CvemonCveImporter
|
|
attr_accessor :url
|
|
|
|
def initialize
|
|
@url = 'https://raw.githubusercontent.com/ARPSyndicate/cvemon/main/data.json'
|
|
end
|
|
|
|
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}"
|
|
end
|
|
end
|
|
|
|
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] }
|
|
end
|
|
CvemonCve.upsert_all(cves, unique_by: :cve_id)
|
|
end
|
|
end
|