diff --git a/.pryrc b/.pryrc index e69de29..9ccd7b9 100644 --- a/.pryrc +++ b/.pryrc @@ -0,0 +1 @@ +irequire 'classes/CVE.rb' diff --git a/Dockerfile b/Dockerfile index cb7ea65..f4f52c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ RUN gem install pry WORKDIR /usr/src/app -CMD pry \ No newline at end of file +CMD pry diff --git a/classes/.pryrc b/classes/.pryrc new file mode 100644 index 0000000..e69de29 diff --git a/classes/cve.rb b/classes/cve.rb deleted file mode 100755 index eadb4df..0000000 --- a/classes/cve.rb +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env ruby -# CVE class - -# the end goal of this is to just be something that i can use to lookup cve quickly from the command line. yes i know that these tools already exist, but what i'm trying to learn more about ruby so why not? - -require 'net/http' - -class CVE - - def base_uri - @base_uri ||= 'https://nvd.nist.gov/feeds/' - end - - def years - # i know this is long, ill fix it later to generate the numbers or something - @year ||= %w[ - 2002 2003 2004 2005 2006 2007 - 2008 2009 2010 2011 2012 2013 - 2014 2015 2016 2017 2018] - end - - def xml_url - endpoint = 'xml/cve/2.0/' - url = self.base_uri + endpoint - uri = URI(url) - end - - def xml_file(year) - xml_file = "nvdcve-2.0-#{year}.xml.gz" - end - -end diff --git a/classes/cve_info.rb b/classes/cve_info.rb new file mode 100644 index 0000000..ae3bb52 --- /dev/null +++ b/classes/cve_info.rb @@ -0,0 +1,2 @@ +class CveInfo +end diff --git a/classes/kenna_api_client.rb b/classes/kenna_api_client.rb new file mode 100644 index 0000000..c441345 --- /dev/null +++ b/classes/kenna_api_client.rb @@ -0,0 +1,26 @@ +require 'net/http' +# Kenna Security API Client +# Requests are limited to a maximum of 5 requests per second. +# If you exceed this limit, your request will receive a “429: Too Many Requests" status code response. + +class APIClient + attr_accessor :api_token, :api_url + + def initialize(api_token) + @api_token = api_token + @api_url = 'https://api.kennasecurity.com' + end + + private + + def get(uri) + # pass a relative url: example - /vulnerabilities + url = URI("#{api_url}/#{uri}") + request = Net::HTTP::Get.new(uri) + request['X-Risk-Token'] = api_token + + response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| + http.request(request) + end + end +end