diff options
author | Ken Barber <ken@bob.sh> | 2011-06-29 12:30:07 +0100 |
---|---|---|
committer | Ken Barber <ken@bob.sh> | 2011-06-29 12:30:07 +0100 |
commit | e071b05ab631f4b73fed7178c52d0416f7629cb8 (patch) | |
tree | 117365b45372eb4259f873ad0bbeb1d5f783dccd /lib/puppet/parser | |
parent | 157531cd290e53c9a174171bb29de293bade2ed4 (diff) |
Added kwalify function.
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/functions/kwalify.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/kwalify.rb b/lib/puppet/parser/functions/kwalify.rb new file mode 100644 index 0000000..7238f84 --- /dev/null +++ b/lib/puppet/parser/functions/kwalify.rb @@ -0,0 +1,35 @@ +# +# kwalify.rb +# + +require 'kwalify' + +module Puppet::Parser::Functions + newfunction(:kwalify, :type => :statement, :doc => <<-EOS +This function uses kwalify to validate Puppet data structures against Kwalify +schemas. + EOS + ) do |args| + + raise(Puppet::ParseError, "kwalify(): Wrong number of arguments " + + "given (#{args.size} for 2)") if args.size != 2 + + schema = args[0] + document = args[1] + + validator = Kwalify::Validator.new(schema) + + errors = validator.validate(document) + + if errors && !errors.empty? + error_out = [] + for e in errors + error_out << "[#{e.path}] #{e.message}" + end + raise(Puppet::ParseError, "Failed kwalify schema validation:\n" + error_out.join("\n")) + end + + end +end + +# vim: set ts=2 sw=2 et : |