forked from spiffe/spiffe-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (31 loc) · 802 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
package main
import (
"io/ioutil"
"github.com/hashicorp/hcl"
)
// SidecarConfig is HCL config data
type SidecarConfig struct {
AgentAddress string `hcl:"agentAddress"`
GhostunnelCmd string `hcl:"ghostunnelCmd"`
GhostunnelArgs string `hcl:"ghostunnelArgs"`
CertDir string `hcl:"certDir"`
}
// ParseConfig parses the given HCL file into a SidecarConfig struct
func ParseConfig(file string) (sidecarConfig *SidecarConfig, err error) {
sidecarConfig = &SidecarConfig{}
// Read HCL file
dat, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
hclText := string(dat)
// Parse HCL
hclParseTree, err := hcl.Parse(hclText)
if err != nil {
return nil, err
}
if err := hcl.DecodeObject(&sidecarConfig, hclParseTree); err != nil {
return nil, err
}
return
}