MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / ApplyBinding

Function ApplyBinding

pkg/templates/templates.go:27–54  ·  view source on GitHub ↗

ApplyBinding renders an input template using bindings in Go templating format

(input string, bindings map[string]string)

Source from the content-addressed store, hash-verified

25
26// ApplyBinding renders an input template using bindings in Go templating format
27func ApplyBinding(input string, bindings map[string]string) (string, error) {
28 if input == "" {
29 return "", nil
30 }
31
32 if bindings == nil {
33 bindings = make(map[string]string)
34 }
35
36 // Support both `.inputs.foo` and `inputs.foo`
37 input = inputsPrefixRegexp.ReplaceAllString(input, "{{ .inputs.")
38
39 tmpl, err := template.New("chainloop").Option("missingkey=zero").Parse(input)
40 if err != nil {
41 return "", err
42 }
43
44 // Only support placeholders that are prefixed with "inputs.", ex `{{ inputs.foo }}
45 namespacedBinding := map[string]any{"inputs": bindings}
46
47 buffer := new(bytes.Buffer)
48 err = tmpl.Execute(buffer, namespacedBinding)
49 if err != nil {
50 return "", err
51 }
52
53 return buffer.String(), nil
54}

Callers 2

InterpolateGroupMaterialFunction · 0.92
ComputeArgumentsFunction · 0.92

Calls 3

ParseMethod · 0.80
ExecuteMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected