41 lines
No EOL
937 B
Ruby
41 lines
No EOL
937 B
Ruby
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 bulk_insert(cves)
|
|
CvemonCve.bulk_insert do |worker|
|
|
cves.each do |attrs|
|
|
worker.add(attrs)
|
|
end
|
|
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
|
|
|
|
bulk_insert(cves)
|
|
end
|
|
end |