Sha256: 81cb10caaeb64408eea065f437853f4a6d1c97f407cc4e6aa66e319198135421

Contents?: true

Size: 867 Bytes

Versions: 5

Compression:

Stored size: 867 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'net/http'
require 'json'
require 'uri'
require_relative '../../domain/vulnerability/model'

module CisaKevApi
  FEED_URL = 'https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json'

  def self.fetch_vulnerabilities
    uri = URI(FEED_URL)
    response = Net::HTTP.get_response(uri)

    unless response.is_a?(Net::HTTPSuccess)
      raise "Failed to fetch vulnerabilities: #{response.code} #{response.message}"
    end

    json_response = JSON.parse(response.body)
    vulnerabilities = json_response['vulnerabilities']
    vulnerabilities.each do |vulnerability|
      yield CisaKevVulnerability.from_json(vulnerability)
    end
  end

  def self.vulnerabilities
    list = []
    fetch_vulnerabilities do |vulnerability|
      list << vulnerability
    end
    list
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
avs-0.1.3 lib/service/api/cisa_kev.rb
avs-0.1.2 lib/service/api/cisa_kev.rb
avs-0.1.1 lib/service/api/cisa_kev.rb
avs-0.1.0 lib/service/api/cisa_kev.rb
avs-0.0.9 lib/service/api/cisa_kev.rb