On 2014-04-07 2:11, Igor Galić wrote:
Hi folks,
last week I proposed we add a function to puppetlabs-apache which
converts puppet booleans to httpd's On/Off.
https://github.com/puppetlabs/puppetlabs-apache/pull/782
of course that has no straight-forward approach, because in some
cases httpd will allow boolean values, as well as strings
https://httpd.apache.org/docs/current/mod/core.html#acceptpathinfo
https://httpd.apache.org/docs/current/mod/core.html#usecanonicalname
to name only a few.
My first throw of naming the function bool2httpd(), allowing it to map
/on/i, /true/i, true, 1, => 'On'
/off/i, /false/i, false, 0, nil, :undef => 'Off'
and otherwise, simply returning whatever we got lead to the effect of
having a *bad* name. Looking at it now, the solution to this seems
simple: Rename the function to normalise_bool(), allow it an optional
parameter (a regex?) that validates the outliers.
But what about the general problem of mapping a sub-system's directives
and the values they can take to puppet-friendly names, and validating
their types and ranges? It seems a lot of energy is expended in our
manifests, templates, or types/providers to that task.
Especially when a system has a rich set of directives, this can become
very cumbersome.
This what the new Puppet Type System in Puppet 4.0 is intended to help
with. As an example, if you want a type that captures boolean
true/false, integers 0 and 1, and a set of enumerators you can write
that as:
assert_type( Variant[Boolean, Enum[on, off, yes, no], Integer[0,1]], $x)
There is an Enum like type that accepts regular expressions as well
instead of literal strings.
The types can also be used as optionally typed parameters in classes,
defines, and lambdas.
Checkout my blog posts about the type system for more information.
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
--
You received this message because you are subscribed to the Google Groups "Puppet
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-dev/lp4v38%24i6e%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.