github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/misc/env.go (about) 1 /* 2 Copyright 2019 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package misc 18 19 import ( 20 "fmt" 21 "strings" 22 23 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" 24 ) 25 26 // EvaluateEnv evaluates templated environment variables. 27 func EvaluateEnv(env []string) ([]string, error) { 28 var evaluated []string 29 30 for _, kv := range env { 31 kvp := strings.SplitN(kv, "=", 2) 32 if len(kvp) != 2 { 33 return nil, fmt.Errorf("invalid env variable: %s, should be using `key=value` form", kv) 34 } 35 36 k := kvp[0] 37 v := kvp[1] 38 39 value, err := util.ExpandEnvTemplate(v, nil) 40 if err != nil { 41 return nil, fmt.Errorf("unable to get value for env variable %q: %w", k, err) 42 } 43 44 evaluated = append(evaluated, k+"="+value) 45 } 46 47 return evaluated, nil 48 }