On Wed, Jul 27, 2011 at 10:00 AM, Ken Barber <k...@puppetlabs.com> wrote:
> So I managed to make some of this work in core. I've got a very basic > patch ... its not what one would call complete but I want to make sure > I'm going in the right direction: > > > https://github.com/kbarber/puppet/commit/74d32f3d8c565567faf23f90bbd828f8528539bb > > added inline comments > So there are three sides to this ... the schema can now be obtained > using resource_type: > > kbarber:puppet ken$ ~/Development/puppet/bin/puppet resource_type find > > testclass{"name":"testclass","arguments":{"arg3":null,"arg4":null,"arg1":null,"arg2":null},"line":1,"schema":{"type":"map","mapping":{"arg3":{"required":true,"pattern":"/^\\d+$/","type":"str"},"arg4":{"type":"map","mapping":{"a":{"required":true,"pattern":"/^\\d+$/","type":"str"},"b":{"required":true,"pattern":"/^\\d+$/","type":"str"},"c":{"required":true,"pattern":"/^\\d+$/","type":"str"}}},"arg1":{"required":true,"type":"str"},"arg2":{"required":true,"type":"str"}}},"type":"hostclass","file":"/Users/ken/.puppet/modules/testclass/manifests/init.pp"} > kbarber:puppet ken$ > > If no schema is defined, you get back a schema derived from the > existing arguments: > > kbarber:puppet ken$ ~/Development/puppet/bin/puppet resource_type find > testclass2 > > {"name":"testclass2","arguments":{"arg3":"\"asdf\"","arg1":null,"arg2":null},"line":1,"schema":{"type":"map","mapping":{"arg3":{"required":false,"default":"asdf","type":"str"},"arg1":{"required":true,"type":"str"},"arg2":{"required":true,"type":"str"}}},"type":"hostclass","file":"/Users/ken/.puppet/modules/testclass2/manifests/init.pp"} > kbarber:puppet ken$ > I would prefer to not get back any schema if one is not specified. Not all users will want to create schemas, so this could wind up displaying unnecessary information. > And you now get rich validation - including things like regex pattern > validation: > > kbarber:puppet ken$ ~/Development/puppet/bin/puppet apply > ~/.puppet/manifests/site.pp > Failed kwalify schema validation: > [/arg4/a] 'd': not matched to pattern /^\d+$/. at > /Users/ken/.puppet/manifests/site.pp:10 on node kbarber.lan > kbarber:puppet ken$ > > I'm guess I'm just looking for direction. I want to see if people > think this kind of thing is a good idea and if my implementation is > correct. I have a number of concerns generally: > > * A separate schema file while simple - feels like it might be the > wrong approach and potentially this should be in the language itself > somehow. > I think having the schema exist in a separate file is the right approach ( maybe I am just used to that b/c that is how it was done in Java). It makes it easy for users to view the resources in a manifest without having to simultaneously digest the schema. I think this lowers the barrier for entry for new users getting started. > * I'm going to need to validate schema against the real argument list > in the class to make sure they don't mismatch. > not sure what you mean > * A schema/interface to anything can change - an ENC may need a quick > way of determining if there has been a change to understand if its > data needs to be re-validated. Versioning or hashes of the schema are > potential approaches. > You could also create a yaml terminus and rebuild the cache when the schema or interface change (not sure exactly how this would work..) > * What if we want to use a different schema type in the future as > apposed to kwalify? > > Thanks. > > ken. > > On Sat, Jul 2, 2011 at 1:01 AM, Ken Barber <k...@puppetlabs.com> wrote: > > So on the topic of generating forms from Kwalify, I found this: > > > > http://robla.net/jsonwidget/ > > > > Which supports kwalify-like schemas to render forms using Javascript > > (extra bits were added to support rendering). Here is a demo for an > > address book editor for example: > > > > http://robla.net/jsonwidget/example.php?sample=blankaddr&user=normal > > > > While a bit rough - you can see it has capabilities to handle > > structured data including nested elements like hashes and arrays. I > > think it would be awesome to give users the power to just 'add a > > class' in dashboard and be presented with a shiny form of this nature > > to configure their app. The election example: > > > > http://robla.net/jsonwidget/example.php?sample=normal&user=advanced > > > > Shows off the use of context sensitive help which is derived from the > > schema (click on help next to an attribute to see this). > > > > And > > > > On Fri, Jul 1, 2011 at 8:25 PM, Ken Barber <k...@puppetlabs.com> wrote: > >> 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. > >> > > > > > > -- > "Join us for PuppetConf, September 22nd and 23rd in Portland, OR: > http://bit.ly/puppetconfsig" > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To post to this group, send email to puppet-dev@googlegroups.com. > To unsubscribe from this group, send email to > puppet-dev+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. > > -- "Join us for PuppetConf <http://bit.ly/puppetconfsig>, September 22nd and 23rd in Portland, OR." <http://bit.ly/puppetconfsig> -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.