1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2026-10-29 05:32:31 +00:00

feat: reload TLS certificates when their files change (#625)

This commit is contained in:
Antoine Deschênes
2026-10-05 17:49:35 -04:00
committed by GitHub
parent 9876bb2bd9
commit 8075e8d2a3
6 changed files with 447 additions and 6 deletions
+3 -3
View File
@@ -14,6 +14,7 @@ import (
"github.com/inbucket/inbucket/v3/pkg/message"
"github.com/inbucket/inbucket/v3/pkg/metric"
"github.com/inbucket/inbucket/v3/pkg/policy"
"github.com/inbucket/inbucket/v3/pkg/server/tlscert"
"github.com/rs/zerolog/log"
)
@@ -79,14 +80,13 @@ func NewServer(
slog := log.With().Str("module", "smtp").Str("phase", "tls").Logger()
tlsConfig := &tls.Config{}
if smtpConfig.TLSEnabled {
var err error
tlsConfig.Certificates = make([]tls.Certificate, 1)
tlsConfig.Certificates[0], err = tls.LoadX509KeyPair(smtpConfig.TLSCert, smtpConfig.TLSPrivKey)
reloader, err := tlscert.NewReloader(smtpConfig.TLSCert, smtpConfig.TLSPrivKey, slog)
if err != nil {
slog.Error().Msgf("Failed loading X509 KeyPair: %v", err)
slog.Error().Msg("Disabling STARTTLS support")
smtpConfig.TLSEnabled = false
} else {
tlsConfig.GetCertificate = reloader.GetCertificate
slog.Debug().Msg("STARTTLS feature available")
}
}