Class: Vkit::CLI::PolicyBundleValidator
- Inherits:
-
Object
- Object
- Vkit::CLI::PolicyBundleValidator
- Defined in:
- lib/vkit/cli/policy_bundle_validator.rb
Instance Method Summary collapse
-
#initialize(schema_path:) ⇒ PolicyBundleValidator
constructor
A new instance of PolicyBundleValidator.
- #validate!(bundle_path) ⇒ Object
Constructor Details
#initialize(schema_path:) ⇒ PolicyBundleValidator
Returns a new instance of PolicyBundleValidator.
7 8 9 10 |
# File 'lib/vkit/cli/policy_bundle_validator.rb', line 7 def initialize(schema_path:) @schema = JSON.parse(File.read(schema_path)) @schemer = JSONSchemer.schema(@schema) end |
Instance Method Details
#validate!(bundle_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vkit/cli/policy_bundle_validator.rb', line 12 def validate!(bundle_path) bundle = JSON.parse(File.read(bundle_path)) errors = @schemer.validate(bundle).to_a return if errors.empty? puts "\n❌ Policy bundle validation failed\n\n" errors.each do |err| puts format_error(err, bundle) end puts "\nFix the errors above and re-run validation." exit 1 end |