func (atcConfig ATCConfig) newConfig(configPath PathFlag, templateVariablesFiles []PathFlag, templateVariables template.Variables) atc.Config { configFile, err := ioutil.ReadFile(string(configPath)) if err != nil { failWithErrorf("could not read config file", err) } var resultVars template.Variables for _, path := range templateVariablesFiles { fileVars, templateErr := template.LoadVariablesFromFile(string(path)) if templateErr != nil { failWithErrorf("failed to load variables from file (%s)", templateErr, string(path)) } resultVars = resultVars.Merge(fileVars) } resultVars = resultVars.Merge(templateVariables) configFile, err = template.Evaluate(configFile, resultVars) if err != nil { failWithErrorf("failed to evaluate variables into template", err) } var newConfig atc.Config err = yaml.Unmarshal(configFile, &newConfig) if err != nil { failWithErrorf("failed to parse configuration file", err) } return newConfig }
func (atcConfig ATCConfig) newConfig(configPath string, templateVariablesFiles []string, templateVariables []string) (atc.Config, []byte) { configFile, err := ioutil.ReadFile(configPath) if err != nil { failWithErrorf("could not read config file", err) } var resultVars template.Variables for _, path := range templateVariablesFiles { fileVars, err := template.LoadVariablesFromFile(path) if err != nil { failWithErrorf("failed to load variables from file (%s)", err, path) } resultVars = resultVars.Merge(fileVars) } vars, err := template.LoadVariables(templateVariables) if err != nil { failWithErrorf("could not load template variables", err) } resultVars = resultVars.Merge(vars) configFile, err = template.Evaluate(configFile, resultVars) if err != nil { failWithErrorf("failed to evaluate variables into template", err) } var newConfig atc.Config err = yaml.Unmarshal(configFile, &newConfig) if err != nil { failWithErrorf("failed to parse configuration file", err) } fmt.Println("New Config Raw: %+v", newConfig) return newConfig, configFile }
package template_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/concourse/fly/template" ) var _ = Describe("Variables", func() { Describe("merging two sets of variables together", func() { It("merges the two sets into one", func() { a := template.Variables{ "a": "foo", } b := template.Variables{ "b": "bar", } result := a.Merge(b) Expect(result).To(Equal(template.Variables{ "a": "foo", "b": "bar", })) }) It("does not affect the original sets", func() { a := template.Variables{ "a": "foo",