2020-08-09 17:04:05 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 VMware, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
package provider
|
|
|
|
|
2020-08-11 01:53:53 +00:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"k8s.io/apiserver/pkg/server/dynamiccertificates"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DynamicTLSServingCertProvider interface {
|
|
|
|
dynamiccertificates.CertKeyContentProvider
|
|
|
|
Set(certPEM, keyPEM []byte)
|
|
|
|
}
|
|
|
|
|
|
|
|
type dynamicTLSServingCertProvider struct {
|
|
|
|
certPEM []byte
|
|
|
|
keyPEM []byte
|
|
|
|
mutex sync.RWMutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDynamicTLSServingCertProvider() DynamicTLSServingCertProvider {
|
|
|
|
return &dynamicTLSServingCertProvider{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *dynamicTLSServingCertProvider) Set(certPEM, keyPEM []byte) {
|
|
|
|
p.mutex.Lock() // acquire a write lock
|
|
|
|
defer p.mutex.Unlock()
|
|
|
|
p.certPEM = certPEM
|
|
|
|
p.keyPEM = keyPEM
|
2020-08-09 17:04:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 01:53:53 +00:00
|
|
|
func (p *dynamicTLSServingCertProvider) Name() string {
|
2020-08-09 17:04:05 +00:00
|
|
|
return "DynamicTLSServingCertProvider"
|
|
|
|
}
|
|
|
|
|
2020-08-11 01:53:53 +00:00
|
|
|
func (p *dynamicTLSServingCertProvider) CurrentCertKeyContent() (cert []byte, key []byte) {
|
|
|
|
p.mutex.RLock() // acquire a read lock
|
|
|
|
defer p.mutex.RUnlock()
|
|
|
|
return p.certPEM, p.keyPEM
|
2020-08-09 17:04:05 +00:00
|
|
|
}
|