Skip to content
Snippets Groups Projects
Commit 5d0f46c5 authored by Paul Millar's avatar Paul Millar
Browse files

Add initial version of PaN search API checking script

parent f0f84b9d
No related branches found
No related tags found
1 merge request!40Add initial version of PaN search API checking script
Pipeline #467896 passed
# check_search_api.rb
require 'httparty'
require 'yaml'
require 'json'
def check_search_api_endpoint(endpoint_url)
queryIdentify_url = endpoint_url + "/datasets/count"
begin
response = HTTParty.get(queryIdentify_url)
if response.body.nil? || response.body.empty?
puts "Endpoint returned an empty body."
return "Error"
end
response_json = JSON.parse(response.body)
count = response_json["count"]
if count.nil?
puts "Response missing dataset count."
return "Error"
end
puts "Endpoint is functional: reported #{count} datasets."
return "Active"
rescue StandardError => e
puts "Error occurred while accessing endpoint: #{e.message}"
return "Error"
rescue JSON::JSONError => e
puts "Failed to parse JSON response: #{e.message}"
return "Error"
end
end
up_to_date = true
facilities = YAML.safe_load(File.read('_data/facilities.yml'), permitted_classes: [Date])
facilities.each do |facility|
odr = facility['odr']
if odr && odr.key?('pan-search-api')
endpoint = odr['pan-search-api']['link']
if endpoint
expected_status = odr['pan-search-api']['status']
puts "Checking PaN Search API endpoint for #{facility['short-name']}: #{endpoint}"
endpoint_status = check_search_api_endpoint(endpoint)
status_match = expected_status == endpoint_status
puts "Error: Expected status '#{expected_status}' for #{facility['short-name']} PaN Search API endpoint, but found status '#{endpoint_status}'." unless status_match
up_to_date &= status_match
end
end
end
exit(1) unless up_to_date
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment