Auth package should return an error to the calling function
instead of erroring out with log.Fatal
Issue-ID: AAF-99
Change-Id: I9f1abd3710a85df85ac6e1d623dc16d77b977f1a
Signed-off-by: Kiran <kiran.k.kamineni@intel.com>
"crypto/tls"
"crypto/x509"
"io/ioutil"
- "log"
)
var tlsConfig *tls.Config
// GetTLSConfig initializes a tlsConfig using the CA's certificate
// This config is then used to enable the server for mutual TLS
-func GetTLSConfig(caCertFile string) *tls.Config {
+func GetTLSConfig(caCertFile string) (*tls.Config, error) {
// Initialize tlsConfig once
if tlsConfig == nil {
caCert, err := ioutil.ReadFile(caCertFile)
if err != nil {
- log.Fatal("Error reading CA Certificate")
- log.Fatal(err)
+ return nil, err
}
caCertPool := x509.NewCertPool()
}
tlsConfig.BuildNameToCertificate()
}
- return tlsConfig
+ return tlsConfig, nil
}
httpRouter := smshandler.CreateRouter(backendImpl)
// TODO: Use CA certificate from AAF
- tlsConfig := smsauth.GetTLSConfig(smsConf.CAFile)
+ tlsConfig, err := smsauth.GetTLSConfig(smsConf.CAFile)
+ if err != nil {
+ log.Fatal(err)
+ }
httpServer := &http.Server{
Handler: httpRouter,