added filename generator
This commit is contained in:
parent
c3755a71d3
commit
2ee050f603
1 changed files with 29 additions and 4 deletions
|
@ -3,14 +3,16 @@ require 'zlib'
|
|||
require 'json'
|
||||
|
||||
class NvdDownloader
|
||||
attr_accessor :base_url, :years
|
||||
attr_accessor :version, :base_url, :base_filename, :years
|
||||
|
||||
MIN_YEAR = '2002'
|
||||
MAX_YEAR = '2019'
|
||||
AVAILABLE_YEARS = (MIN_YEAR..MAX_YEAR).to_a
|
||||
|
||||
def initialize
|
||||
@base_url = "https://nvd.nist.gov/feeds/json/cve/1.0/"
|
||||
@version = "1.0"
|
||||
@base_url = "https://nvd.nist.gov/feeds/json/cve/#{version}/"
|
||||
@base_filename = "nvdcve-#{version}-"
|
||||
@years = self.years
|
||||
end
|
||||
|
||||
|
@ -20,8 +22,17 @@ class NvdDownloader
|
|||
end.to_h
|
||||
end
|
||||
|
||||
def year(year)
|
||||
years[year]
|
||||
def filenames(extension)
|
||||
year_filenames = years.map do |k, year|
|
||||
"#{base_filename}#{year}.#{extension}"
|
||||
end
|
||||
|
||||
other_filenames = [
|
||||
"#{base_filename}recent.#{extension}",
|
||||
"#{base_filename}modified.#{extension}"
|
||||
]
|
||||
|
||||
year_filenames + other_filenames
|
||||
end
|
||||
|
||||
def get(url)
|
||||
|
@ -35,7 +46,21 @@ class NvdDownloader
|
|||
gz.read
|
||||
end
|
||||
|
||||
def write_to_file(parsed_json, file_path)
|
||||
File.write(file_path, parsed_json)
|
||||
end
|
||||
|
||||
def parse_json(json_string)
|
||||
JSON.parse(json_string)
|
||||
end
|
||||
|
||||
def one_time_import
|
||||
# this should be a method that does a one-time import
|
||||
# of all of the json.gz from each year + recent + modified json feeds
|
||||
end
|
||||
|
||||
def modified_meta
|
||||
# this should be a method that builds
|
||||
# the modified filename with the meta file extension included
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue