Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
[#181] templating attributes after merge with override
Browse files Browse the repository at this point in the history
  • Loading branch information
n0rad committed Jul 26, 2016
1 parent c5ef774 commit d98b9d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 5 additions & 0 deletions bin-templater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func Run(overrideEnvVarName string, target string, templaterDir string, continue
}
attributes := attrMerger.Merge()
attributes = overrideWithJsonIfNeeded(overrideEnvVarName, attributes)
tt, err := merger.ProcessAttributesTemplating(attributes, attributes)
attributes = tt.(map[string]interface{})
if err != nil {
logs.WithField("dir", templaterDir+pathTemplates).Fatal("Failed to template attributes")
}
logs.WithField("content", attributes).Debug("Final attributes resolution")

info, _ := os.Stat(templaterDir + pathTemplates)
Expand Down
13 changes: 4 additions & 9 deletions bin-templater/merger/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ func MergeAttributesFilesForMap(omap map[string]interface{}, files []string) map
omap = mergemap.Merge(newMap, json)
}
data := ProcessOverride(newMap)

data2, err := processAttributesTemplating(data, data)
if err != nil {
panic(err)
}
return data2.(map[string]interface{})
return data
}

func MergeAttributesFiles(files []string) map[string]interface{} {
Expand Down Expand Up @@ -159,12 +154,12 @@ func Merge(envName string, files []string) []byte {
return out
}

func processAttributesTemplating(in interface{}, attributes interface{}) (_ interface{}, err error) {
func ProcessAttributesTemplating(in interface{}, attributes interface{}) (_ interface{}, err error) {
switch in.(type) {
case map[string]interface{}:
o := make(map[string]interface{})
for k, v := range in.(map[string]interface{}) {
v, err = processAttributesTemplating(v, attributes)
v, err = ProcessAttributesTemplating(v, attributes)
if err != nil {
return nil, err
}
Expand All @@ -176,7 +171,7 @@ func processAttributesTemplating(in interface{}, attributes interface{}) (_ inte
len1 := len(in1)
o := make([]interface{}, len1)
for i := 0; i < len1; i++ {
o[i], err = processAttributesTemplating(in1[i], attributes)
o[i], err = ProcessAttributesTemplating(in1[i], attributes)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d98b9d3

Please sign in to comment.