-
Notifications
You must be signed in to change notification settings - Fork 6
/
approle.go
59 lines (49 loc) · 1.53 KB
/
approle.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
54
55
56
57
58
59
package initlib
import (
"fmt"
"os"
"strings"
eUtils "github.com/trimble-oss/tierceron/pkg/utils"
"gopkg.in/yaml.v2"
)
func GetApproleFileNames(config *eUtils.DriverConfig, namespace string) []string {
var approleFileNames []string
cwd, cwdErr := os.Getwd()
if cwdErr != nil {
fmt.Println("Error reading current directory. Cannot continue.")
eUtils.LogErrorObject(config, cwdErr, false)
os.Exit(-1)
}
approleFiles, approleFilesErr := os.ReadDir(cwd + "/vault_namespaces/" + namespace + "/approle_files")
if approleFilesErr != nil {
fmt.Println("Error reading approle_files directory. Cannot continue.")
eUtils.LogErrorObject(config, approleFilesErr, false)
os.Exit(-1)
}
for _, approleFile := range approleFiles {
if strings.Contains(approleFile.Name(), ".yml") {
approleFileNames = append(approleFileNames, strings.TrimSuffix(approleFile.Name(), ".yml"))
} else {
fmt.Println(approleFile.Name() + " is not a yaml file. Continuing with other files.")
eUtils.LogErrorObject(config, approleFilesErr, false)
continue
}
}
return approleFileNames
}
func ParseApproleYaml(fileName string, namespace string) (map[interface{}]interface{}, error) {
cwd, cwdErr := os.Getwd()
if cwdErr != nil {
return nil, cwdErr
}
file, err := os.ReadFile(cwd + "/vault_namespaces/" + namespace + "/approle_files/" + fileName + ".yml")
if err != nil {
return nil, err
}
parsedData := make(map[interface{}]interface{})
err2 := yaml.Unmarshal(file, &parsedData)
if err2 != nil {
return nil, err2
}
return parsedData, nil
}