substitution

package
v0.0.0-...-4fc8c9b Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

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

func ExtractArrayIndexingParamsExpressions(s string) []string

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

func ExtractIndex

func ExtractIndex(s string) (int, error)

ExtractIndex will extract int from `[int]`

func ExtractIndexString

func ExtractIndexString(s string) string

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

func ExtractVariableExpressions

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

func ExtractVariablesFromString

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

func StripStarVarSubExpression(s string) string

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

func TrimArrayIndex

func TrimArrayIndex(s string) string

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

func ValidateNoReferencesToEntireProhibitedVariables

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

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

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

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

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