added methods to download the modified metadata file

This commit is contained in:
booboy 2019-06-12 22:46:34 -05:00
parent e6c8b0c0b2
commit 4736d84e7d

View file

@ -5,18 +5,18 @@ require 'json'
module NvdTools module NvdTools
class NvdDownloader class NvdDownloader
attr_accessor :version, :base_url, :base_filename, :years, :filenames_json, :client attr_accessor :version, :base_url, :base_filename, :years, :filenames_json, :filenames_meta, :client
MIN_YEAR = '2002' MIN_YEAR = '2002'
MAX_YEAR = '2019' MAX_YEAR = '2019'
AVAILABLE_YEARS = (MIN_YEAR..MAX_YEAR).to_a AVAILABLE_YEARS = (MIN_YEAR..MAX_YEAR).to_a
GZIPPED_JSON_EXTENSION = 'json.gz'
def initialize(client: NvdClient.new) def initialize(client: NvdClient.new)
@base_filename = "nvdcve-#{client.version}-" @base_filename = "nvdcve-#{client.version}-"
@years = self.years @years = self.years
@filenames_json = self.filenames(GZIPPED_JSON_EXTENSION) @filenames_json = self.filenames('json.gz')
@filenames_meta = self.filenames('meta')
@client = client @client = client
end end
@ -75,12 +75,19 @@ module NvdTools
# of all of the json.gz from each year + recent + modified json feeds # of all of the json.gz from each year + recent + modified json feeds
end end
def modified_meta def modified_meta(filename)
file = filenames('meta').select do |name|
name == filename
end.first
r = client.get(file)
r.body.split("\r\n")
# this should be a method that builds # this should be a method that builds
# the modified filename with the meta file extension included # the modified filename with the meta file extension included
end end
def check_metafile(metafile) def check_metafile(metafile)
# open the metafile, build a hash of k/v pairs of the data inside of the file # open the metafile, build a hash of k/v pairs of the data inside of the file
# check each k/v pair against the file on disk # check each k/v pair against the file on disk
# return a new hash with the same k as before, but the value being a boolean true or false if the value from the k/v pair # return a new hash with the same k as before, but the value being a boolean true or false if the value from the k/v pair