add route

This commit is contained in:
Brendan McDevitt 2022-04-27 01:31:57 -05:00
parent 763de4b83d
commit 3a32d6086f
3 changed files with 9 additions and 2 deletions

View file

@ -10,4 +10,9 @@ class CisaKnownExploitsController < ApplicationController
@cisa_known_exploit = CisaKnownExploit.cve_id(params[:cve_id])
render json: @cisa_known_exploit.to_json
end
def show_product
@cisa_known_exploits = CisaKnownExploit.by_product(params[:product_name])
render json: @cisa_known_exploits.to_json
end
end

View file

@ -5,6 +5,7 @@ class CisaKnownExploit < ActiveRecord::Base
find_by(cve_id: id)
end
#TODO: i think i can just use postgrs sql jsonb ->> queries to better pull this data
def self.cve_id(cve_id)
last.vulnerabilities.select { |vuln| vuln if vuln.dig('cve_id') == cve_id }
end
@ -14,7 +15,7 @@ class CisaKnownExploit < ActiveRecord::Base
end
def self.by_product(product_name)
last.vulnerabilities.select {|vuln| vuln if vuln.dig('product') == product_name }
last.vulnerabilities.select {|vuln| vuln if vuln.dig('product') =~ /#{product_name}/ }
end
def self.by_due_date(due_date)

View file

@ -43,5 +43,6 @@ Rails.application.routes.draw do
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'
get '/cisa_known_exploits/vulnerabilities/:cve_id', to: 'cisa_known_exploits#show'
get '/cisa_known_exploits/vulnerabilities/product/:product_name', to: 'cisa_known_exploits#show_product'
end