diff --git a/runner/cmd_config.go b/runner/cmd_config.go index 0ead0f9469e11d5fa4246d04611ee188b048e448_cnVubmVyL2NtZF9jb25maWcuZ28=..21af8873db192102afa98abc3a455ece219bd34f_cnVubmVyL2NtZF9jb25maWcuZ28= 100644 --- a/runner/cmd_config.go +++ b/runner/cmd_config.go @@ -9,6 +9,7 @@ "strings" "github.com/rs/zerolog" + "bytes" ) const ( @@ -318,9 +319,11 @@ } } -func (c *CmdConfig) prepareVariables(doSha bool) (map[string]interface{}, error) { +type Vars map[string]interface{} + +func (c *CmdConfig) prepareVariables(doSha bool) (Vars, error) { variables := make(map[string]interface{}) for _, variable := range c.Spec.Variables { variables[variable.Name] = variable.Value } variables["namespace"] = c.Namespace @@ -322,8 +325,13 @@ variables := make(map[string]interface{}) for _, variable := range c.Spec.Variables { variables[variable.Name] = variable.Value } variables["namespace"] = c.Namespace + resVars, err := c.hydrateVariables(variables) + if err != nil { + return variables, err + } + shavars := map[string]interface{}{} for _, sha := range c.Spec.Shas { if doSha { @@ -336,8 +344,31 @@ shavars[sha.Key] = fmt.Sprintf("<[sha.%s]>", sha.Key) } } - variables["sha"] = shavars - return variables, nil + resVars["sha"] = shavars + return resVars, nil +} + +func (c *CmdConfig) hydrateVariables(vars Vars) (Vars, error) { + resultVars := make(map[string]interface{}) + for k, v := range vars { + switch v.(type) { + case string: + w := bytes.NewBuffer([]byte{}) + s := vars[k].(string) + if err := hydrateString(s, w, vars); err != nil { + return resultVars, err + } + resultVars[k] = w.String() + + case map[string]interface{}: + intermediateVars, err := c.hydrateVariables(v.(map[string]interface{})) + if err != nil { + return resultVars, err + } + resultVars[k] = intermediateVars + } + } + return resultVars, nil } // MergeVariables takes a config (from a file, not a cmd one) and import its diff --git a/runner/cmd_config_test.go b/runner/cmd_config_test.go new file mode 100644 index 0000000000000000000000000000000000000000..21af8873db192102afa98abc3a455ece219bd34f_cnVubmVyL2NtZF9jb25maWdfdGVzdC5nbw== --- /dev/null +++ b/runner/cmd_config_test.go @@ -0,0 +1,7 @@ +package runner + +import "testing" + +func TestPrepareVariables(t *testing.T) { + +}