-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
42 lines (33 loc) · 833 Bytes
/
config.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
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/commondream/yamlast"
)
// Config represents the configuration of cftool for an execution.
type Config struct {
VaultKey []byte
VaultAST *yamlast.Node
}
// LoadConfig loads a config.
func LoadConfig() *Config {
config := Config{}
vaultKey, keyErr := LoadVaultKey()
if keyErr == nil {
config.VaultKey = vaultKey
}
if config.VaultKey != nil {
path := "vault"
encryptedVaultData, vaultFileErr := ioutil.ReadFile(path)
if vaultFileErr == nil && len(encryptedVaultData) > 0 {
decryptedVault := Decrypt(string(encryptedVaultData), config.VaultKey)
var err error
config.VaultAST, err = yamlast.Parse([]byte(decryptedVault))
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing vault yaml: %s\n", err.Error())
}
}
}
return &config
}