Jira (PUP-4020) A way to ask a resource what the type of its parameters are

1 view
Skip to first unread message

Daniele Sluijters (JIRA)

unread,
Feb 17, 2015, 4:33:38 AM2/17/15
to puppe...@googlegroups.com
Daniele Sluijters created an issue
 
Puppet / New Feature PUP-4020
A way to ask a resource what the type of its parameters are
Issue Type: New Feature New Feature
Assignee: Henrik Lindberg
Components: Language
Created: 2015/02/17 1:32 AM
Priority: Normal Normal
Reporter: Daniele Sluijters

As we discussed previously on IRC and last night at the Stockholm PUG, it would be nice to be able to ask a class or (defined) type what the type of its parameters are.

For example, if you're wrapping something like apache::vhost and are exposing parameters that get passed through 1:1 it would be nice to be able to tell your class "this parameter needs to adhere to the same type as that parameter on apache::vhost.

Ideally we should also be able to do this for native types once they've been rewritten to actually provide type information, so that when you expose a packages_ensure parameter on your class you can give it a type expression along the lines of Package.ensure $packages_ensure = 'present'.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Feb 17, 2015, 6:52:38 AM2/17/15
to puppe...@googlegroups.com
Henrik Lindberg commented on New Feature PUP-4020
 
Re: A way to ask a resource what the type of its parameters are

There is currently a type_of function in standard lib that returns the type of its argument, but we have no expression in the language that evaluates to a reference to a parameter (we can only pass evaluated values).

The main problem with supporting getting the type of the parameter is how to express that reference. The current naming rules requires each segment to begin with the same capitalization; lowercase means instance reference ('the value of' as in $apache::vhost::ensure), and uppercase means type references. We currently do not allow $Apache::Vhost which (if we allowed it would return the instance of the Resource Type (as opposed to Apache::Vhost which returns its type). From there we have two choices; either let instances of Resource type escape into the language so we access details e.g. $Apache::Vhost[ensure], or only accept that such references end with a lower case reference to the parameter, and then we can use $ to access it i.e. $Apache::Vhost::ensure. IMO the distinction between upper/lowercase here is too subtle and it is too easy to make a type and get something completely different as a result. One solution is to use a different prefix - say & to mean "reference to" (this is useful to reference other things as well, such as functions (with the intent of passing the function as a block to another function)). In short - $ is a reference to a value, & is a reference to a thing that has or produces a value. We can then use all lower case e.g. &apache::vhost::param.

The next hurdle is what such a reference really means. It seems natural that it evaluates to the object that describes the param (and 'param_type' is an attribute of that param). This means if we call type_of(&apache::vhost::param) we would get something like Param[Enum[...]], and we would need a way to reference the type parameters (i.e. the type of the param). We currently have no way to get the type parameters of a type. So this requires additional language features and or changes (remember that things like Package['foo'] is a reference to a package resource, the 'foo' is not navigation to an attribute of Package - the way this was originally designed in Puppet squats on the semantics of the [] operator for resources and there are too many special cases to make that work. The '.' operator is also used to mean "call function" - we could make the function name resolution also consider attribute names as the names of getter functions and that they have higher precedence than regular functions (while it would work, it is not very appealing).

While it should be possible to come up with an elegant solution, it may not be very easy to understand. I am therefore leaning towards that it is better to introduce a specific function to get the type of a parameter:

# Using string name of the parameter
$the_type = param_type(apache::vhost::ensure)
 
# Using a type reference, and the name of a parameter
$the_type = param_type(Apache::Vhost, ensure)

This however creates a different problem - we cannot type a parameter by using a function; it must be a type reference. We could however use a type alias like this:

type = MyModule::ApacheVhost::Ensure = param_type(apache::vhost::ensure)
define( MyModule::ApacheVhost::Ensure $ensure) {
...
}

Daniele Sluijters (JIRA)

unread,
Feb 17, 2015, 7:27:40 AM2/17/15
to puppe...@googlegroups.com

First of, thanks for the blog post. That explains a few things.

I'm not an overly great fan of the verbosity of type = MyModule::ApacheVhost::Ensure = param_type(apache::vhost::ensure) but for now I'll take it. It should be a feature we have and depending on how it gets used and other use cases people come up with we can consider a different implementation in the language in due time I think.

Is there any way we can 'magically' create types in Puppet for native types when they are typed. So you don't have to go through this madness but by default have a FileEnsure, FilePath type available etc?

Henrik Lindberg (JIRA)

unread,
Feb 17, 2015, 9:36:44 AM2/17/15
to puppe...@googlegroups.com

Yes, we could make the parameter types available automatically - but that creates ambiguities, is A::B::C the type of the parameter 'c' in A::B, or the type A::B::C ? This is essentially the problem I was describing above in the long comment.

I have some other suggestions - we could introduce a type that acts as a reference to another - say Like which could work the same way as the param_type function - e.g:

define( Like[File, ensure] $ensure ) {
...
}

Daniele Sluijters (JIRA)

unread,
Feb 17, 2015, 11:25:37 AM2/17/15
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Feb 17, 2015, 1:08:56 PM2/17/15
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
 

Yes, function is not needed then

  • henrik

Daniele Sluijters (JIRA)

unread,
Feb 17, 2015, 4:00:40 PM2/17/15
to puppe...@googlegroups.com
 
Re: A way to ask a resource what the type of its parameters are

+9000 in that case. I find this much more readable and easier to understand than the function alternative that we came up with first.

Henrik Lindberg (JIRA)

unread,
Feb 17, 2015, 8:25:46 PM2/17/15
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Feb 17, 2015, 8:27:39 PM2/17/15
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Add a Like type to specify a type being the type of a resource parameter
Change By: Henrik Lindberg
Summary: A way Add a Like type  to  ask  specify  a  resource what  type being  the type of  its parameters are  a resource parameter

Henrik Lindberg (JIRA)

unread,
Feb 17, 2015, 8:30:39 PM2/17/15
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
As we discussed previously on IRC and last night at the Stockholm PUG, it would be nice to be able to ask a class or (defined) type what the type of its parameters are.


For example, if you're wrapping something like {{apache::vhost}} and are exposing parameters that get passed through 1:1 it would be nice to be able to tell your class "this parameter needs to adhere to the same type as that parameter on {{apache::vhost}}.

Ideally we should also be able to do this for native types once they've been rewritten to actually provide type information, so that when you expose a {{packages_ensure}} parameter on your class you can give it a type expression along the lines of {{Package.ensure $packages_ensure = 'present'}}.


Update
----
We came to the conclusion that this is best done by introducing a type in the type system {{Like}} that is parameterized with two values, the name of a type (default a resource type), and a parameter name. The result is the type of that parameter. The first type can also be expressed using a type (i.e. Resource[type], Class[name]).

This opens the ability also reference the type parameters of other types such as the from/to parameters in an Integer type, the variants of a variant type, etc.

Henrik Lindberg (JIRA)

unread,
Mar 17, 2017, 8:51:02 AM3/17/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Team: Puppet Developer Experience
Fix Version/s: PUP 4.y
Fix Version/s: PUP 5.y
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

John Duarte (JIRA)

unread,
May 17, 2017, 12:30:03 PM5/17/17
to puppe...@googlegroups.com

Ethan Brown (JIRA)

unread,
May 17, 2017, 12:30:05 PM5/17/17
to puppe...@googlegroups.com
Ethan Brown updated an issue
Change By: Ethan Brown
Team: Puppet Developer Experience Agent

Moses Mendoza (JIRA)

unread,
May 18, 2017, 1:45:34 PM5/18/17
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Mar 23, 2018, 2:29:02 PM3/23/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Fix Version/s: PUP 5.y
Fix Version/s: PUP 6.y
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

David McTavish (Jira)

unread,
Dec 1, 2021, 11:53:02 AM12/1/21
to puppe...@googlegroups.com
David McTavish updated an issue
Change By: David McTavish
Labels: final_triage
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages