mirror of
https://github.com/adnanh/webhook.git
synced 2025-10-04 13:41:03 +00:00
Reload TLS key pair on HUP signal
This commit is contained in:
parent
1c72898604
commit
50a690a5e4
3 changed files with 34 additions and 0 deletions
|
@ -38,6 +38,20 @@ func NewKeyPairReloader(certPath, keyPath string) (*KeyPairReloader, error) {
|
|||
return res, nil
|
||||
}
|
||||
|
||||
// Reload attempts to reload the TLS key pair.
|
||||
func (kpr *KeyPairReloader) Reload() error {
|
||||
cert, err := tls.LoadX509KeyPair(kpr.certPath, kpr.keyPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kpr.certMu.Lock()
|
||||
defer kpr.certMu.Unlock()
|
||||
|
||||
kpr.cert = &cert
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCertificateFunc provides a function for tls.Config.GetCertificate.
|
||||
func (kpr *KeyPairReloader) GetCertificateFunc() func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||
return func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue