Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-7675

Add the ability to typecast a key using lookup_options

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 5.5.0
    • Component/s: DOCS, Language
    • Labels:
      None
    • Template:
    • Epic Link:
    • Team:
      Platform Core
    • Sub-team:
    • Sprint:
      Platform Core KANBAN
    • Release Notes:
      New Feature
    • Release Notes Summary:
      Hide
      It is now possible to specify a type conversion in the lookup options for hiera 5.
      This can be used to 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.
      Show
      It is now possible to specify a type conversion in the lookup options for hiera 5. This can be used to 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.
    • QA Risk Assessment:
      Needs Assessment

      Description

      In order to 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.

      Example - Making a value Sensitive

      mymodule::mykey: 42
      lookup_options:
        mymodule::mykey:
          convert_to: "Sensitive"
      

      Example - turning a non Array value into an array:

      mymodule::mykey: 42
      lookup_options:
        mymodule::mykey:
          convert_to: 
            - "Array"
            - true
      

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  henrik.lindberg Henrik Lindberg
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: