github.com/argoproj/argo-cd/v3@v3.2.1/applicationset/generators/value_interpolation.go (about) 1 package generators 2 3 import ( 4 "fmt" 5 ) 6 7 func appendTemplatedValues(values map[string]string, params map[string]any, useGoTemplate bool, goTemplateOptions []string) error { 8 // We create a local map to ensure that we do not fall victim to a billion-laughs attack. We iterate through the 9 // cluster values map and only replace values in said map if it has already been allowlisted in the params map. 10 // Once we iterate through all the cluster values we can then safely merge the `tmp` map into the main params map. 11 tmp := map[string]any{} 12 13 for key, value := range values { 14 result, err := replaceTemplatedString(value, params, useGoTemplate, goTemplateOptions) 15 if err != nil { 16 return fmt.Errorf("failed to replace templated string: %w", err) 17 } 18 19 if useGoTemplate { 20 if tmp["values"] == nil { 21 tmp["values"] = map[string]string{} 22 } 23 tmp["values"].(map[string]string)[key] = result 24 } else { 25 tmp["values."+key] = result 26 } 27 } 28 29 for key, value := range tmp { 30 params[key] = value 31 } 32 33 return nil 34 } 35 36 func replaceTemplatedString(value string, params map[string]any, useGoTemplate bool, goTemplateOptions []string) (string, error) { 37 replacedTmplStr, err := render.Replace(value, params, useGoTemplate, goTemplateOptions) 38 if err != nil { 39 return "", fmt.Errorf("failed to replace templated string with rendered values: %w", err) 40 } 41 return replacedTmplStr, nil 42 }