Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat object parameters as objects in templating #3225

Merged
merged 5 commits into from
Sep 30, 2024

Commits on Sep 24, 2024

  1. Treat object parameters as objects in templating

    This change makes it possible to access a parameter in templating, not
    only to the top-level, i.e. the parameter itself, but also -- if the
    parameter is of type "object" -- to access properties of the object
    value. For example:
    
    ```yaml
    parameters:
      - name: foo
        type: object
        default:
          a: 1
          b: 2
    
    install:
      mymixin:
        some_property: ${ bundle.parameters.foo.a }
    ```
    
    In this case, the `.a` was not possible before as `foo` was merely a
    JSON string at the point of template resolution.
    
    Signed-off-by: Leo Bergnéhr <leo@bergnehr.se>
    lbergnehr committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    6b5e0f1 View commit details
    Browse the repository at this point in the history

Commits on Sep 25, 2024

  1. Interpolate object parameters as JSON strings

    When trating object parameters as `map`s, the interpolation of the
    object itself changes to the string representation of `map` instead of
    the previous JSON string representation.
    
    In order to keep the old behaviour of interpolating the object parameter
    to a JSON string, this change introduces a new type, `FormattedObject`,
    which implements the [`fmt.Formatter`](https://pkg.go.dev/fmt#Formatter)
    interface. The implemented `Format` function turns the object's string
    representation into a JSON string, instad of the default Go
    representation of a `map`.
    
    Example:
    
    ```yaml
    parameter:
      - name: foo
        type: object
        default:
          bar: 1
    
    install:
      mymixin:
        # Interpolating a nested property of the object parameter.
        val: "${ bundle.parameter.foo.bar }" # -> `val: '1'`
    
        # Interpolating the object parameter directly.
        obj: "${ bundle.parameter.foo }"     # -> `obj: '{"bar":1}'`
    ```
    
    A shortcoming of this implementation is that interpolating nested
    properties which also are `map` types will result in the interpolated
    value being the string representation of `map`.
    
    Signed-off-by: Leo Bergnéhr <leo@bergnehr.se>
    lbergnehr committed Sep 25, 2024
    Configuration menu
    Copy the full SHA
    0511ee1 View commit details
    Browse the repository at this point in the history

Commits on Sep 27, 2024

  1. Merge branch 'main' into interpolate-objects-in-templates

    Signed-off-by: Kim Christensen <2461567+kichristensen@users.noreply.github.com>
    kichristensen authored Sep 27, 2024
    Configuration menu
    Copy the full SHA
    82c5012 View commit details
    Browse the repository at this point in the history

Commits on Sep 30, 2024

  1. Use format string for Fprintf

    Fixes lint error `SA1006`.
    
    Signed-off-by: Leo Bergnéhr <leo@bergnehr.se>
    lbergnehr committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    3cb1f10 View commit details
    Browse the repository at this point in the history
  2. Support sensitive for object parameters

    This adds support for tracking object parameters as sensitive. However,
    if interpolating sub-properties of an object in templating, those will
    not get tracked as sensitive.
    
    Signed-off-by: Leo Bergnéhr <leo@bergnehr.se>
    lbergnehr committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    7630bc3 View commit details
    Browse the repository at this point in the history