So I've been working on various modules that have very complex data
requirements ... for example the bind zone configuration resource is
fairly complex in that it can have anywhere up to 40 different
attributes:

http://ftp.isc.org/isc/bind9/cur/9.8/doc/arm/Bv9ARM.ch06.html#zone_statement_grammar

Some of these attributes also require arrays and hashes to be passed
in puppet so I can easily convert them to bind grammar.

Now this is all very well and good - but I face the issue of trying to
validate these complex structures. In answer to this I created this
function:

https://github.com/puppetlabs/puppetlabs-functions/blob/master/lib/puppet/parser/functions/kwalify.rb

Which allows validation using kwalify:

http://www.kuwata-lab.com/kwalify/ruby/users-guide.01.html#schema

This function monopolizes kwalify schema validation techniques - so I
can use Puppet hashes and arrays to create kwalify schemas to validate
my resource input. Some examples:

https://github.com/puppetlabs/puppetlabs-functions/blob/master/examples/kwalify-1.pp
https://github.com/puppetlabs/puppetlabs-functions/blob/master/examples/kwalify-2.pp

This is great in that I can now combine my validation into 1 data
structure and use that to validate ...

Now this in of itself is interesting but I started to think about the
wider case. What if I wanted to validate _every_ parameter in a class
or resource?

So I created this:

https://github.com/puppetlabs/puppetlabs-functions/blob/master/lib/puppet/parser/functions/validate_resource.rb

This converts all the params in a class or resource into a hash, and
goes looking for a separate schema file to use as validation. The idea
being, I can define a module_name/manifests/init.pp file with a class
in it, and a corresponding module_name/manifests/init.schema file for
its complex validation. This way you can create classes in the normal
layout structure, and have each class have a corresponding schema
file.

Some examples:

https://github.com/puppetlabs/puppetlabs-functions/blob/master/examples/validate_resource-1.pp
https://github.com/puppetlabs/puppetlabs-functions/blob/master/examples/validate_resource-1.schema

https://github.com/puppetlabs/puppetlabs-functions/blob/master/examples/validate_resource-2.pp
https://github.com/puppetlabs/puppetlabs-functions/blob/master/examples/validate_resource-2.schema

So now - I can allow complex structures to be passed, and have
validation in kwalify do most of the heavy lifting for validation ...
but also ... if someone was keen - they could use the kwalify schema
files - dynamically create a form in an ENC tool for parameterized
classes data entry purposes.

So the obvious debate to be made is weither this kind of complex
validation lives in the language or not ... but I do generally feel
that the current language support doesn't go deep enough to express
the data needed by a class and/or an ENC tool - kwalify comes a little
closer even if it isn't the correct implementation it certainly is
closer to the kind of information that needs to be expressed.

Anyway ... just want to put these ideas out there and see what people think.

ken.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to