added route for cisa known exploits

This commit is contained in:
Brendan McDevitt 2022-04-27 01:11:36 -05:00
parent db1ef2e01a
commit 01a9373cfd
3 changed files with 10 additions and 3 deletions

View file

@ -7,7 +7,7 @@ class CisaKnownExploitsController < ApplicationController
end end
def show def show
@cisa_known_exploit = CisaKnownExploit.find(params[:cve_id]) @cisa_known_exploit = CisaKnownExploit.cve_id(params[:cve_id])
render json: @cisa_known_exploit.to_json render json: @cisa_known_exploit.to_json
end end
end end

View file

@ -5,7 +5,11 @@ class CisaKnownExploit < ActiveRecord::Base
find_by(cve_id: id) find_by(cve_id: id)
end end
def self.from_year(year) def self.cve_id(cve_id)
where('cve_id LIKE ?', "CVE-#{year}-%") last.vulnerabilities.select { |vuln| vuln if vuln.dig('cve_id') == cve_id }
end
def self.cves_from_year(year)
last.vulnerabilities.select { |vuln| vuln if vuln.dig('cve_id') =~ /CVE-#{year}-\d{4,7}/ }
end end
end end

View file

@ -41,4 +41,7 @@ Rails.application.routes.draw do
get '/gsds', to: 'gsds#index' get '/gsds', to: 'gsds#index'
get '/gsds/:gsd_id', to: 'gsds#show' get '/gsds/:gsd_id', to: 'gsds#show'
get '/gsds/years/:year', to: 'gsds#show_year' get '/gsds/years/:year', to: 'gsds#show_year'
get '/cisa_known_exploits', to: 'cisa_known_exploits#index'
get '/cisa_known_exploits/cve/:cve_id', to: 'cisa_known_exploits#show'
end end