generated from SAP/repository-template
/
findvaluefiles.go
53 lines (44 loc) · 1.09 KB
/
findvaluefiles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package generate
import (
"path/filepath"
"github.com/SAP/configuration-tools-for-gitops/v2/cmd/coco/inputfile"
)
func readValueFiles(
basepath, configFileName string,
includeOr, includeAnd, exclude []string,
) (map[string]interface{}, error) {
valueFiles, err := inputfile.FindAll(basepath, configFileName, includeOr, includeAnd, exclude)
if err != nil {
return nil, err
}
res := make(map[string]interface{}, len(valueFiles))
for path, file := range valueFiles {
if file.IsDir {
continue
}
coco, err := inputfile.Load(path)
if err != nil {
return nil, err
}
if !coco.IsEnvironment() {
continue
}
dir := filepath.Dir(path)
valueFilesForEnv := make([]string, 0, len(coco.Values))
for _, v := range coco.Values {
valueFilesForEnv = append(valueFilesForEnv, filepath.Join(dir, v))
}
merged, err := mergeValues(valueFilesForEnv)
if err != nil {
return nil, err
}
var finalValues interface{}
err = merged.Decode(&finalValues)
if err != nil {
return nil, err
}
res[coco.Name] = finalValues
res[coco.Name] = finalValues
}
return res, nil
}