Skip to content

Commit

Permalink
Add changes
Browse files Browse the repository at this point in the history
Signed-off-by: FlamingSaint <raghuramkannan400@gmail.com>
  • Loading branch information
FlamingSaint committed Jun 5, 2024
1 parent 1c45eeb commit 8e19489
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/config/tlscfg/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Options struct {
MaxVersion string `mapstructure:"max_version"`
SkipHostVerify bool `mapstructure:"skip_host_verify"`
ReloadInterval time.Duration `mapstructure:"reload_interval"`
CertWatcher *certWatcher `mapstructure:"-"`
certWatcher *certWatcher
}

var systemCertPool = x509.SystemCertPool // to allow overriding in unit test
Expand Down Expand Up @@ -102,18 +102,18 @@ func (o *Options) Config(logger *zap.Logger) (*tls.Config, error) {
if err != nil {
return nil, err
}
o.CertWatcher = certWatcher
o.certWatcher = certWatcher

if (o.CertPath == "" && o.KeyPath != "") || (o.CertPath != "" && o.KeyPath == "") {
return nil, fmt.Errorf("for client auth via TLS, either both client certificate and key must be supplied, or neither")
}
if o.CertPath != "" && o.KeyPath != "" {
tlsCfg.GetCertificate = func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
return o.CertWatcher.certificate(), nil
return o.certWatcher.certificate(), nil
}
// GetClientCertificate is used on the client side when server is configured with tls.RequireAndVerifyClientCert e.g. mTLS
tlsCfg.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
return o.CertWatcher.certificate(), nil
return o.certWatcher.certificate(), nil
}
}

Expand Down Expand Up @@ -169,8 +169,8 @@ var _ io.Closer = (*Options)(nil)

// Close shuts down the embedded certificate watcher.
func (o *Options) Close() error {
if o.CertWatcher != nil {
return o.CertWatcher.Close()
if o.certWatcher != nil {
return o.certWatcher.Close()
}
return nil
}

0 comments on commit 8e19489

Please sign in to comment.