begin fleshing out ways to pull oval definitions;

This commit is contained in:
kenna-bmcdevitt 2020-10-27 18:20:50 -05:00
parent 155e201707
commit f304c79fa1
3 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,64 @@
# frozen_string_literal: true
require 'json'
require 'rest-client'
class OvalStreamDataParser
attr_accessor :data, :api_url
def initialize
@api_url = 'https://access.redhat.com/hydra/rest/securitydata/oval'
@data = refresh_index
end
def refresh_index
response = RestClient::Request.execute(
method: :get,
url: "#{api_url}/ovalstreams.json",
content_type: 'application/json'
)
if response.code == 200
parse_index(response)
else
puts "Error: HTTP Response code #{response.code} received."
end
end
def parse_index(response)
JSON.parse(response.body)
end
def list_stream_names
data.map do |entry|
entry['stream']
end.sort
end
def list_stream_urls
data.map do |entry|
entry['resourceUrl']
end.sort
end
def list_stream_labels
data.map do |entry|
entry['label']
end.sort
end
def select_stream_by_label(label)
data.select { |json| json['label'] == label }
end
def verify_shasum
# method that will check the sha256sum of a downloaded file from resourceUrl and ensure they match
# step 1:
# get original shasum
# step 2:
# download file
# step 3:
# run sha256sum against file download
# step 4:
# run == logic against both sums and return true/false
end
end

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
# do a fresh pull of the data
# the class should also do this when initialized but if you want a seperate script to run quick just to pull you can use this
wget https://access.redhat.com/hydra/rest/securitydata/oval/ovalstreams.json