Future parser experiments: A question on params validation

20 views
Skip to first unread message

Alessandro Franceschi

unread,
Apr 12, 2015, 4:14:08 AM4/12/15
to puppet...@googlegroups.com
Hi all,
I've started to make some future parser versions of the most useful Tiny Puppet defines:
the main advantages I've seen, for this use case, is the neater and more concise parameters validation, and, for the tp::install4 define (https://github.com/example42/puppet-tp/blob/master/manifests/install4.pp) , the ability to cope with arrays of packages and services.

Another small change is the usage of the + operator on hashes instead of stdlib's merge().
There's probably more that can be done on them (any input or suggestions  is welcomed) , but in particular I have a point I'd like to fix.

When Parameters are undef by default I didn't find anything better than enforcing an "Any" type, which actually does not validate anything:

define tp::conf4 (
String $ensure = present,
Any $source = undef,
Any $template = undef,
Any $epp = undef,
Any $content = undef,

is there a concise way (without other verbose conditionals in the code) to validate a parameter type IF that parameter is passed when is undef by default? 

Any help appreciated,
al

Henrik Lindberg

unread,
Apr 12, 2015, 7:35:22 AM4/12/15
to puppet...@googlegroups.com
Use the type Optional[T] to enforce either the type T, or undef. In your
example, say that $content must be a non empty string, or undef then you
could type it like this:

Optional[String[1]] $content = undef

Depending on what is accepted you can also use a Variant type with an
explicit Undef, this means the same thing as above:

Variant[Undef, String[1]] $content = undef

Hope that helps

- henrik

> Any help appreciated,
> al
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/66b016b6-0e1a-4623-9c1b-ab61ed179dcb%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/66b016b6-0e1a-4623-9c1b-ab61ed179dcb%40googlegroups..com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Alessandro Franceschi

unread,
Apr 12, 2015, 8:15:11 AM4/12/15
to puppet...@googlegroups.com
Great,
exactly what I need. 
Thank you
Reply all
Reply to author
Forward
0 new messages