MCPcopy Create free account
hub / github.com/buildpacks/pack / ParseBuildConfigEnv

Function ParseBuildConfigEnv

builder/config_reader.go:188–228  ·  view source on GitHub ↗
(env []BuildConfigEnv, path string)

Source from the content-addressed store, hash-verified

186}
187
188func ParseBuildConfigEnv(env []BuildConfigEnv, path string) (envMap map[string]string, warnings []string, err error) {
189 envMap = map[string]string{}
190 var appendOrPrependWithoutDelim = 0
191 for _, v := range env {
192 if name := v.Name; name == "" || len(name) == 0 {
193 return nil, nil, errors.Wrapf(errors.Errorf("env name should not be empty"), "parse contents of '%s'", path)
194 }
195 if val := v.Value; val == "" || len(val) == 0 {
196 warnings = append(warnings, fmt.Sprintf("empty value for key/name %s", style.Symbol(v.Name)))
197 }
198 suffixName, delimName, err := getBuildConfigEnvFileName(v)
199 if err != nil {
200 return envMap, warnings, err
201 }
202 if val, e := envMap[suffixName]; e {
203 warnings = append(warnings, fmt.Sprintf(errors.Errorf("overriding env with name: %s and suffix: %s from %s to %s", style.Symbol(v.Name), style.Symbol(string(v.Suffix)), style.Symbol(val), style.Symbol(v.Value)).Error(), "parse contents of '%s'", path))
204 }
205 if val, e := envMap[delimName]; e {
206 warnings = append(warnings, fmt.Sprintf(errors.Errorf("overriding env with name: %s and delim: %s from %s to %s", style.Symbol(v.Name), style.Symbol(v.Delim), style.Symbol(val), style.Symbol(v.Value)).Error(), "parse contents of '%s'", path))
207 }
208 if delim := v.Delim; (delim != "" || len(delim) != 0) && (delimName != "" || len(delimName) != 0) {
209 envMap[delimName] = delim
210 }
211 envMap[suffixName] = v.Value
212 }
213
214 for k := range envMap {
215 name, suffix, err := getFilePrefixSuffix(k)
216 if err != nil {
217 continue
218 }
219 if _, ok := envMap[name+".delim"]; (suffix == "append" || suffix == "prepend") && !ok {
220 warnings = append(warnings, fmt.Sprintf(errors.Errorf("env with name/key %s with suffix %s must to have a %s value", style.Symbol(name), style.Symbol(suffix), style.Symbol("delim")).Error(), "parse contents of '%s'", path))
221 appendOrPrependWithoutDelim++
222 }
223 }
224 if appendOrPrependWithoutDelim > 0 {
225 return envMap, warnings, errors.Errorf("error parsing [[build.env]] in file '%s'", path)
226 }
227 return envMap, warnings, err
228}
229
230func getBuildConfigEnvFileName(env BuildConfigEnv) (suffixName, delimName string, err error) {
231 suffix, err := getActionType(env.Suffix)

Callers 3

BuilderCreateFunction · 0.92
testCreateCommandFunction · 0.92
testConfigFunction · 0.92

Calls 4

getFilePrefixSuffixFunction · 0.85
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by 2

testCreateCommandFunction · 0.74
testConfigFunction · 0.74