substitution

package
v0.59.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyArrayReplacements

func ApplyArrayReplacements(in string, stringReplacements map[string]string, arrayReplacements map[string][]string) []string

ApplyArrayReplacements takes an input string, and output an array of strings related to possible arrayReplacements. If there aren't any areas where the input can be split up via arrayReplacements, then just return an array with a single element, which is ApplyReplacements(in, replacements).

func ApplyReplacements

func ApplyReplacements(in string, replacements map[string]string) string

ApplyReplacements returns a string with references to parameters replaced, based on the mapping provided in replacements. For example, if the input string is "foo: $(params.foo)", and replacements maps "params.foo" to "bar", the output would be "foo: bar".

func ExtractArrayIndexingParamsExpressions added in v0.54.0

func ExtractArrayIndexingParamsExpressions(s string) []string

ExtractArrayIndexingParamsExpressions will find all `$(params.paramName[int])` expressions

func ExtractIndex added in v0.38.0

func ExtractIndex(s string) (int, error)

ExtractIndex will extract int from `[int]`

func ExtractIndexString added in v0.38.0

func ExtractIndexString(s string) string

ExtractIndexString will find the leftmost match of `[int]`

func ExtractVariableExpressions added in v0.54.0

func ExtractVariableExpressions(s, prefix string) ([]string, error)

func ExtractVariablesFromString added in v0.40.0

func ExtractVariablesFromString(s, prefix string) ([]string, bool, string)

ExtractVariablesFromString extracts variables from an input string s with the given prefix via regex matching. It returns a slice of strings which contains the extracted variables, a bool flag to indicate if matches were found and the error string if the referencing of parameters is invalid. If the string does not contain the input prefix then the output will contain a slice of strings with length 0.

func StripStarVarSubExpression added in v0.38.0

func StripStarVarSubExpression(s string) string

StripStarVarSubExpression strips "$(target[*])"" to get "target"

func TrimArrayIndex added in v0.38.0

func TrimArrayIndex(s string) string

TrimArrayIndex replaces all `[i]` and `[*]` to "".

func ValidateNoReferencesToEntireProhibitedVariables added in v0.48.0

func ValidateNoReferencesToEntireProhibitedVariables(value, prefix string, vars sets.String) *apis.FieldError

ValidateNoReferencesToEntireProhibitedVariables returns an error if the input string contains any whole array/object references to any variables in vars. References to array indexes or object keys are permitted.

Inputs: - value: a string containing a reference to a variable that can be substituted, e.g. "echo $(params.foo)" - prefix: the prefix of the substitutable variable, e.g. "params" or "context.pipeline" - vars: names of known variables

func ValidateNoReferencesToProhibitedVariables added in v0.48.0

func ValidateNoReferencesToProhibitedVariables(value, prefix string, vars sets.String) *apis.FieldError

ValidateNoReferencesToProhibitedVariables returns an error if the input string contains any references to any variables in vars, except for array indexing references.

Inputs: - value: a string containing a reference to a variable that can be substituted, e.g. "echo $(params.foo)" - prefix: the prefix of the substitutable variable, e.g. "params" or "context.pipeline" - vars: names of known variables

func ValidateNoReferencesToUnknownVariables added in v0.48.0

func ValidateNoReferencesToUnknownVariables(value, prefix string, vars sets.String) *apis.FieldError

ValidateNoReferencesToUnknownVariables returns an error if the input string contains references to unknown variables Inputs: - value: a string containing a reference to a variable that can be substituted, e.g. "echo $(params.foo)" - prefix: the prefix of the substitutable variable, e.g. "params" or "context.pipeline" - vars: names of known variables

func ValidateVariableReferenceIsIsolated added in v0.48.0

func ValidateVariableReferenceIsIsolated(value, prefix string, vars sets.String) *apis.FieldError

ValidateVariableReferenceIsIsolated returns an error if the input string contains characters in addition to references to known parameters. For example, if "foo" is a known parameter, a value of "foo: $(params.foo)" returns an error, but a value of "$(params.foo)" does not. Inputs: - value: a string containing a reference to a variable that can be substituted, e.g. "echo $(params.foo)" - prefix: the prefix of the substitutable variable, e.g. "params" or "context.pipeline" - vars: names of known variables

func ValidateWholeArrayOrObjectRefInStringVariable added in v0.38.0

func ValidateWholeArrayOrObjectRefInStringVariable(name, value, prefix string, vars sets.String) (isIsolated bool, errs *apis.FieldError)

ValidateWholeArrayOrObjectRefInStringVariable validates if a single string field uses references to the whole array/object appropriately valid example: "$(params.myObject[*])" invalid example: "$(params.name-not-exist[*])"

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL