Wallets: validate wallet YAML file using JSON Schema

This commit is contained in:
David A. Harding 2017-05-14 05:53:15 -04:00
parent 0354fe0399
commit ab641d7300
No known key found for this signature in database
GPG key ID: 4B29C30FF29EC4B7
7 changed files with 361 additions and 3 deletions

31
_contrib/schema-validator.rb Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env ruby
# This file is licensed under the MIT License (MIT) available on
# http://opensource.org/licenses/MIT.
require 'safe_yaml/load'
require 'json-schema'
if ARGV[1].nil?
puts "Usage: schema-validator.rb <schema-file> <file-to-validate>"
exit(255)
end
schema_file = ARGV[0]
file_to_validate = ARGV[1]
file = File.open(schema_file, 'r')
schema = SafeYAML.load(file)
file.close()
file = File.open(file_to_validate, 'r')
document = SafeYAML.load(file)
file.close()
results = JSON::Validator.fully_validate(schema, document)
if results.empty?
exit(0)
else
puts results
exit(1)
end