Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat object parameters as objects in templating (#3225)
* 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 <[email protected]> * 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 <[email protected]> * Use format string for `Fprintf` Fixes lint error `SA1006`. Signed-off-by: Leo Bergnéhr <[email protected]> * 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 <[email protected]> --------- Signed-off-by: Leo Bergnéhr <[email protected]> Signed-off-by: Kim Christensen <[email protected]> Co-authored-by: Kim Christensen <[email protected]>
- Loading branch information