Skip to content
Snippets Groups Projects
Commit 21af8873db19 authored by Florent Aide's avatar Florent Aide
Browse files

expand vars with vars

parent 0ead0f9469e1
No related tags found
No related merge requests found
Pipeline #68325 failed
......@@ -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
......
package runner
import "testing"
func TestPrepareVariables(t *testing.T) {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment