Sha256: ebd415e1dcd599a0282ebd728689d572133fe6ea8a40a7bd1ef1b83c2b4835ae

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require 'nokogiri'
require 'json'
require 'open-uri'
require 'pry'

main_page = Nokogiri::HTML(open("https://www.stigviewer.com/stigs"))

main_page.search('td').each do |td|
  begin
    standard      = {}
    standard_link = td.children[1].attributes['href'].value
    puts "Searching #{standard_link} for JSON"
    standard_page = Nokogiri::HTML(open("https://www.stigviewer.com#{standard_link}"))
    json_link     = standard_page.at_css('[id="json"]').attributes['href'].value
    puts "Downloading JSON: #{json_link}"
    stig          = JSON.parse(open("https://www.stigviewer.com#{json_link}").read)['stig']

    # Map elements
    standard['name'] = "stig_#{stig['slug']}"
    standard['date'] = stig['date']
    standard['description'] = stig['description']
    standard['title'] = stig['title']
    standard['version'] = stig['version']
    standard['item_syntax'] = '^\w-\d+$'
    standard['section_separator'] = nil
    standard['items'] = stig['findings'].map { |id,details|
      {
        'id'          => id,
        'title'       => details['title'],
        'description' => details['description'],
        'severity'    => details['severity'],
      }
    }

    puts "Writing standard #{standard['name']}"
    File.write("standards/#{standard['name']}.json", JSON.pretty_generate(standard))
  rescue
    puts 'Something went wrong, pretending it didn\'t happen'
  end
end

puts 'done'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kriterion-0.1.0 bin/update_stigs.rb
kriterion-0.0.1 bin/update_stigs.rb