Jira (PUP-7675) Add the ability to typecast a key using lookup_options

1 view
Skip to first unread message

Henrik Lindberg (JIRA)

unread,
Jun 19, 2017, 1:41:03 PM6/19/17
to puppe...@googlegroups.com
Henrik Lindberg created an issue
 
Puppet / New Feature PUP-7675
Add the ability to typecast a key using lookup_options
Issue Type: New Feature New Feature
Assignee: Unassigned
Created: 2017/06/19 10:40 AM
Priority: Normal Normal
Reporter: Henrik Lindberg

With the addition of the Init[T, arg, ...] data type it is possible to formalize and describe type casting of values.

This can be added to lookup_options to enable type casting. This is of value as there is no way to represent certain data types directly in JSON, YAML, etc. By adding the key data_type to lookup options, and setting either the desired type directly (for example Sensitive), or by setting it to an Init[T, arg,...arg] enables type casts of the looked up data to be performed by lookup before the value is returned.

If a simple data type is used (for example Sensitive) it is expected that this type has a single argument constructor that accepts the looked up value and returns an instance of the specified data type. If the constructor is more complex and needs additional arguments, or where its single argument constructor is not appropriate for the use case, an Init[T, args...] is instead used. (An example could be interpretation of a String in a particular format used to construct a time/date value).

The data_type entry in lookup_options is a String with a valid Puppet Type System specification of a data type.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Jacob Henner (JIRA)

unread,
Mar 11, 2018, 8:58:02 PM3/11/18
to puppe...@googlegroups.com
Jacob Henner commented on New Feature PUP-7675
 
Re: Add the ability to typecast a key using lookup_options

Will type-casting be enabled by default during automatic class parameter lookup? This would help greatly with several use cases, especially for Sensitive values.

This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Mar 12, 2018, 4:51:02 AM3/12/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
 
Change By: Henrik Lindberg
With In order to type-cast/transform values from hiera backends, the addition of the {{ Init\[T, arg, ...] lookup_options }} data should be given a new key {{convert_to}} that accepts either a type it is possible to formalize name (for example {{Sensitive}}), or an array of type name and describe arguments to the type casting of values 's {{new}} function .

This
can be added to lookup_options to enable type casting. This is of value as there is no way to represent certain data types directly in JSON, YAML, etc. By adding the key {{data_type}} to lookup options, and setting either the desired type directly (for example {{Sensitive}}), or by setting it to an {{Init\[T, arg,...arg]}} enables type casts of the looked up data to be performed by lookup before the value is returned.


If a simple data type is used (for example {{Sensitive}}) it is expected that this type has a single argument constructor that accepts the looked up value and returns an instance of the specified data type. If the constructor is more complex and needs additional arguments, or where its single argument constructor is not appropriate for the use case, an {{Init\[T, args...]}} array of typename + arguments is instead used. ( An example could be interpretation of a String in a particular format used to construct a time/date value ) .

The
{{data_type}} type entry in lookup_options is a String with a valid Puppet Type System specification of a data type , thereby also adding type matching - since a `new` will check that what is produced is compliant with any type constraints expressed in the type .

When implementing this, the {{lookup}} function should have an option to override/set the {{convert_to}} lookup option.

Henrik Lindberg (JIRA)

unread,
Mar 12, 2018, 4:53:03 AM3/12/18
to puppe...@googlegroups.com
Henrik Lindberg commented on New Feature PUP-7675
 
Re: Add the ability to typecast a key using lookup_options

Jacob Henner yes, all lookups, explicit or via APL will type convert if there is a lookup_option for the key being looked up. Users would not have to do anything except specifying the type conversion in the lookup_option. This will be enabled by default as the opt-in performed by adding the conversion to the lookup_options.

Henrik Lindberg (JIRA)

unread,
Mar 13, 2018, 12:03:04 PM3/13/18
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Mar 13, 2018, 12:05:03 PM3/13/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Release Notes Summary: It is now possible to specify a type cast conversion in the lookup options for hiera 5.
This can be used to
transform/typecast convert values to a rich data type - for example making a value {{Sensitive}}, construct a {{Timestamp}} and other such values that cannot be directly represented in JSON or YAML.

Henrik Lindberg (JIRA)

unread,
Mar 13, 2018, 12:05:04 PM3/13/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Component/s: Language
Component/s: DOCS

Henrik Lindberg (JIRA)

unread,
Mar 13, 2018, 12:11:03 PM3/13/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
In order to type-cast/transform convert values from hiera backends to rich data values not directly representable in plain YAML/JSON , the {{lookup_options}} should be given a new key {{convert_to}} that accepts either a type name (for example {{ " Sensitive " }}), or an array of type name and arguments to the type's {{new}} function.


This is of value as there is no way to represent certain data types directly in JSON, YAML, etc.

and there is no way to have any logic post process a looked up value before it is assigned to a class parameter when using APL.

If a simple data type is used (for example {{Sensitive}}) it is expected that this type has a single argument constructor that accepts the looked up value and returns an instance of the specified data type. If the constructor is more complex and needs additional arguments, or where its single argument constructor is not appropriate for the use case, an array of typename + arguments is instead used. An example could be interpretation of a String in a particular format used to construct a time/date value.

The type entry in lookup_options is a String with a valid Puppet Type System specification of a data type, thereby also adding type matching - since a `new` will check that what is produced is compliant with any type constraints expressed in the type.

When implementing this, the Example - Making a value Sensitive
{ code:yaml}
mymodule::mykey: 42
lookup_options:
  mymodule::mykey:
    convert_to: "Sensitive"
{ lookup code } } function should have

Example - turning a non Array value into
an option to override/set the array:
{ { code:yaml}
mymodule::mykey: 42
lookup_options:
  mymodule::mykey:
convert_to :
      - "Array"
      - true
{code
} } lookup option.

Henrik Lindberg (JIRA)

unread,
Mar 13, 2018, 12:11:03 PM3/13/18
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Mar 13, 2018, 12:12:02 PM3/13/18
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Story Points: 2
Sprint: Platform Core KANBAN

Thomas Hallgren (JIRA)

unread,
Mar 13, 2018, 12:16:04 PM3/13/18
to puppe...@googlegroups.com

John Duarte (JIRA)

unread,
Oct 21, 2019, 10:49:05 AM10/21/19
to puppe...@googlegroups.com
John Duarte updated an issue
 
Change By: John Duarte
QA Risk Assessment: Needs Assessment No Action
Reply all
Reply to author
Forward
0 new messages