forked from Cloud-Foundations/keymaster
/
config.go
41 lines (37 loc) · 943 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
package main
import (
"io/ioutil"
"text/template"
"github.com/Cloud-Foundations/keymaster/lib/constants"
"gopkg.in/yaml.v2"
)
func loadConfig(filename string) (*configurationType, error) {
rawConfig, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
config := &configurationType{
KeymasterServerPortNum: constants.DefaultKeymasterAdminPortNumber,
}
if err := yaml.Unmarshal(rawConfig, config); err != nil {
return nil, err
}
if err := parseCommand(&config.SshCertParametersCommand); err != nil {
return nil, err
}
if err := parseCommand(&config.X509CertParametersCommand); err != nil {
return nil, err
}
return config, nil
}
func parseCommand(command *certCommand) error {
for _, parameter := range command.Parameters {
templ := template.New("")
templ, err := templ.Parse(parameter)
if err != nil {
return err
}
command.templates = append(command.templates, templ)
}
return nil
}