3 // configuration file handling for orchestra.
10 "github.com/kuroneko/configureit"
16 var configFile = configureit.New()
19 configFile.Add("x509 certificate", configureit.NewStringOption("/etc/orchestra/player_crt.pem"))
20 configFile.Add("x509 private key", configureit.NewStringOption("/etc/orchestra/player_key.pem"))
21 configFile.Add("ca certificates", configureit.NewPathListOption(nil))
22 configFile.Add("master", configureit.NewStringOption("conductor"))
23 configFile.Add("score directory", configureit.NewStringOption("/usr/lib/orchestra/scores"))
24 configFile.Add("player name", configureit.NewStringOption(""))
27 func GetStringOpt(key string) string {
28 cnode := configFile.Get(key)
30 o.Assert("tried to get a configuration option that doesn't exist.")
32 sopt, ok := cnode.(*configureit.StringOption)
34 o.Assert("tried to get a non-string configuration option with GetStringOpt")
36 return strings.TrimSpace(sopt.Value)
39 func GetCACertList() []string {
40 cnode := configFile.Get("ca certificates")
42 o.Assert("tried to get a configuration option that doesn't exist.")
44 plopt, _ := cnode.(*configureit.PathListOption)
49 // attempt to open the configuration file.
50 fh, err := os.Open(*ConfigFile)
53 // reset the config File data, then reload it.
55 ierr := configFile.Read(fh, 1)
56 o.MightFail(ierr, "Couldn't parse configuration")
58 o.Warn("Couldn't open configuration file: %s. Proceeding anyway.", err)
61 // load the x509 certificates
62 x509CertFilename := GetStringOpt("x509 certificate")
63 x509PrivateKeyFilename := GetStringOpt("x509 private key")
64 CertPair, err = tls.LoadX509KeyPair(x509CertFilename, x509PrivateKeyFilename)
65 o.MightFail(err, "Couldn't load certificates")
68 CACertPool = x509.NewCertPool()
69 caCertNames := GetCACertList()
70 if caCertNames != nil {
71 for _, filename := range caCertNames {
72 fh, err := os.Open(filename)
74 o.Warn("Whilst parsing CA certs, couldn't open %s: %s", filename, err)
79 o.MightFail(err, "Couldn't stat CA certificate file: %s", filename)
80 data := make([]byte, fi.Size)
82 CACertPool.AppendCertsFromPEM(data)