From 01a9373cfd9a26d140dc96033528baa8a0941636 Mon Sep 17 00:00:00 2001 From: Brendan McDevitt Date: Wed, 27 Apr 2022 01:11:36 -0500 Subject: [PATCH] added route for cisa known exploits --- app/controllers/cisa_known_exploits_controller.rb | 2 +- app/models/cisa_known_exploit.rb | 8 ++++++-- config/routes.rb | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/cisa_known_exploits_controller.rb b/app/controllers/cisa_known_exploits_controller.rb index cacbd55..225da57 100644 --- a/app/controllers/cisa_known_exploits_controller.rb +++ b/app/controllers/cisa_known_exploits_controller.rb @@ -7,7 +7,7 @@ class CisaKnownExploitsController < ApplicationController end 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 end end diff --git a/app/models/cisa_known_exploit.rb b/app/models/cisa_known_exploit.rb index 48e85f7..27e0b2c 100644 --- a/app/models/cisa_known_exploit.rb +++ b/app/models/cisa_known_exploit.rb @@ -5,7 +5,11 @@ class CisaKnownExploit < ActiveRecord::Base find_by(cve_id: id) end - def self.from_year(year) - where('cve_id LIKE ?', "CVE-#{year}-%") + def self.cve_id(cve_id) + 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 diff --git a/config/routes.rb b/config/routes.rb index b3ca970..f80e864 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,4 +41,7 @@ Rails.application.routes.draw do get '/gsds', to: 'gsds#index' get '/gsds/:gsd_id', to: 'gsds#show' 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