Error out if LDAP CA cert is not valid

If the configured LDAP CA cert can not be successfully loaded to the
Pool let the creation of the Graph Service fail.
This commit is contained in:
Ralf Haferkamp
2022-06-23 13:19:25 +02:00
parent ca5952fe34
commit 917f099751
2 changed files with 9 additions and 2 deletions

View File

@@ -59,6 +59,10 @@ func Server(opts ...Option) (http.Service, error) {
svc.EventsPublisher(publisher),
)
if handle == nil {
return http.Service{}, errors.New("could not initialize graph service")
}
{
handle = svc.NewInstrument(handle, options.Metrics)
handle = svc.NewLogging(handle, options.Logger)

View File

@@ -106,10 +106,13 @@ func NewService(opts ...Option) Service {
certs := x509.NewCertPool()
pemData, err := ioutil.ReadFile(options.Config.Identity.LDAP.CACert)
if err != nil {
options.Logger.Error().Msgf("Error initializing LDAP Backend: '%s'", err)
options.Logger.Error().Err(err).Msgf("Error initializing LDAP Backend")
return nil
}
if !certs.AppendCertsFromPEM(pemData) {
options.Logger.Error().Msgf("Error initializing LDAP Backend. Adding CA cert failed")
return nil
}
certs.AppendCertsFromPEM(pemData)
tlsConf.RootCAs = certs
}