65 lines
1.4 KiB
Ruby
Executable file
65 lines
1.4 KiB
Ruby
Executable file
require 'openapi_client'
|
|
require 'date'
|
|
require 'json'
|
|
require 'pry'
|
|
|
|
MONTHS = %w[
|
|
Jan
|
|
Feb
|
|
Mar
|
|
Apr
|
|
May
|
|
Jun
|
|
Jul
|
|
Aug
|
|
Sep
|
|
Oct
|
|
Nov
|
|
Dec
|
|
]
|
|
|
|
BEGIN_YEAR = 2016
|
|
CURRENT_YEAR = Date.today.year
|
|
YEAR_RANGE = (BEGIN_YEAR..CURRENT_YEAR).to_a
|
|
|
|
class MicrosoftCvrfClient
|
|
attr_accessor :ids, :api_instance, :api_version, :api_key
|
|
|
|
def initialize(api_instance = OpenapiClient::DefaultApi.new, api_version = 'api_version_example', api_key = 'api_key_example')
|
|
@ids = YEAR_RANGE.map { |y| MONTHS.map { |m| "#{y}-#{m}" } }.flatten
|
|
@api_instance = api_instance
|
|
@api_version = api_version
|
|
@api_key = api_key
|
|
end
|
|
|
|
def get_id(id)
|
|
api_instance.cvrf_id_get(api_version, api_key, id)
|
|
rescue OpenapiClient::ApiError => e
|
|
puts "Exception when calling DefaultApi->cvrf_id_get: #{e}"
|
|
end
|
|
|
|
# response from get_id()
|
|
def cves_and_threat_strings(response)
|
|
response.vulnerability.map do |vuln|
|
|
threat_string = get_threat_string_for_vuln(vuln)
|
|
split_t_string = split_threat_string(threat_string)
|
|
#hashed_string = split_threat_string_to_hash(split_t_string)
|
|
[ vuln.cve, split_t_string ]
|
|
end
|
|
end
|
|
|
|
def get_threat_string_for_vuln(vuln)
|
|
vuln.threats.select { |t| t.type == 1 }.first.description.value
|
|
end
|
|
|
|
def split_threat_string(threat_string)
|
|
threat_string.split(";")
|
|
end
|
|
|
|
# doesnt work
|
|
def split_threat_string_to_hash(split_threat_string)
|
|
Hash[*split_threat_string.flatten]
|
|
end
|
|
|
|
end
|
|
|