Config Interpolation
  • Updated on 20 Oct 2019
  • 3 minutes to read
  • Contributors
  • Print
  • Share
  • Dark
    Light

Config Interpolation

  • Print
  • Share
  • Dark
    Light

# String Interpolation

C8Pipelines is able to perform string interpolation on your config files using Functions.
Functions are resolved each time they are used. However, only certain fields in a config will actually support and interpolate these expressions (insert_part.contents, for example). If you aren't sure that a field in a config section supports functions you should read its respective documentation.

Functions

Some string fields within a C8Pipeline config support function interpolations, these are context specific functions that are executed every time the string is used. To find out if a field supports function interpolation refer to its documentation.

The syntax for functions is ${!function-name}, or ${!function-name:arg} if the function takes an argument, where function-name should be replaced with a valid function.

If a literal string is required that matches this pattern (${!foo}) then, similarly to environment variables, you can escape it with double brackets. For example, the string ${{!foo}} would be read as the literal ${!foo}.

C8Pipelines supports the following functions:

content

Resolves to the content of a message part. The message referred to will depend on the context of where the function is called.

error

If an error has occurred during the processing of a message part this function resolves to the reported cause of the error. For more information about error handling patterns read here.

json_field

Resolves to the value of a JSON field within the message payload located by a dot path specified as an argument. The message referred to will depend on the context of where the function is called. With a message containing {"foo":{"bar":"hello world"}} the function ${!json_field:foo.bar} would resolve to hello world.

When applied to a batch of message parts this function targets the first message part by default. It is possible to specify a target part by following the path with a comma and part number, e.g. ${!json_field:foo.bar,2} would target the field foo.bar within the third message part in the batch.

metadata

Resolves to the value of a metadata key within the message payload. The message referred to will depend on the context of where the function is called. If a message contains the metadata key/value pair foo: bar the function ${!metadata:foo} would resolve to bar.

Message metadata can be modified using the
metadata processor.

metadata_json_object

Resolves to all metadata key/value pairs of a payload as a JSON object. The message referred to will depend on the context of where the function is called.

Message metadata can be modified using the
metadata processor.

uuid_v4

Generates a new RFC-4122 UUID each time it is invoked and prints a string representation.

timestamp_unix_nano

Resolves to the current unix timestamp in nanoseconds. E.g. foo ${!timestamp_unix_nano} bar prints foo 1517412152475689615 bar.

timestamp_unix

Resolves to the current unix timestamp in seconds. E.g. foo ${!timestamp_unix} bar prints foo 1517412152 bar. You can add fractional precision up to the nanosecond by specifying the precision as an argument, e.g. ${!timestamp_unix:3} for millisecond precision.

timestamp

Prints the current time in a custom format specified by the argument. The format is defined by showing how the reference time, defined to be Mon Jan 2 15:04:05 -0700 MST 2006 would be displayed if it were the value.

A fractional second is represented by adding a period and zeros to the end of the seconds section of layout string, as in 15:04:05.000 to format a time stamp with millisecond precision.

timestamp_utc

The equivalent of timestamp except the time is printed as UTC instead of the local timezone.

count

The count function is a counter starting at 1 which increments after each time it is called. Count takes an argument which is an identifier for the counter, allowing you to specify multiple unique counters in your configuration.

Was this article helpful?