Check xcerts.Manager is initialized before adding certificates (#673)

This commit is contained in:
Lenin Alevski
2021-03-27 15:35:45 -07:00
committed by GitHub
parent 901358e8d4
commit b6938a5888
3 changed files with 19 additions and 10 deletions

View File

@@ -228,3 +228,14 @@ func GetAllCertificatesAndCAs() (*x509.CertPool, []*x509.Certificate, *xcerts.Ma
logger.FatalIf(err, "Unable to load the TLS configuration")
return GlobalRootCAs, globalPublicCerts, globalTLSCertsManager
}
// AddCertificate check if Manager is initialized and then append a new certificate to it
func AddCertificate(ctx context.Context, manager *xcerts.Manager, publicKey, privateKey string) (err error) {
// If Cert Manager is not nil add more certificates
if manager != nil {
return manager.AddCertificate(publicKey, privateKey)
}
// Initialize cert manager
manager, err = xcerts.NewManager(ctx, publicKey, privateKey, config.LoadX509KeyPair)
return err
}