Skip to content
Snippets Groups Projects
Commit ff230d7d authored by Rohith Jayawardene's avatar Rohith Jayawardene Committed by GitHub
Browse files

Fixes (#179)

- making a few noop changes
parent 1aaebaef
Branches
Tags
No related merge requests found
...@@ -19,7 +19,6 @@ import ( ...@@ -19,7 +19,6 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"path" "path"
"strings"
"sync" "sync"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
...@@ -77,22 +76,16 @@ func (c *certificationRotation) watch() error { ...@@ -77,22 +76,16 @@ func (c *certificationRotation) watch() error {
if !containedIn(event.Name, filewatchPaths) { if !containedIn(event.Name, filewatchPaths) {
continue continue
} }
// step: we have to reload the certificate
log.WithFields(log.Fields{
"filename": event.Name,
"event": strings.ToLower(event.Op.String()),
}).Debugf("the certificate file has thrown a file event")
// step: reload the certificate // step: reload the certificate
certificate, err := tls.LoadX509KeyPair(c.certificateFile, c.privateKeyFile) certificate, err := tls.LoadX509KeyPair(c.certificateFile, c.privateKeyFile)
if err != nil { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"filename": event.Name, "filename": event.Name,
"error": err.Error(), "error": err.Error(),
}).Error("unable to load the new certificate") }).Error("unable to load the updated certificate")
} }
// step: load the new certificate // step: load the new certificate
c.loadCertificate(certificate) c.storeCertificate(certificate)
// step: print a debug message for us // step: print a debug message for us
log.Infof("replacing the server certifacte with updated version") log.Infof("replacing the server certifacte with updated version")
} }
...@@ -107,8 +100,8 @@ func (c *certificationRotation) watch() error { ...@@ -107,8 +100,8 @@ func (c *certificationRotation) watch() error {
return nil return nil
} }
// loadCertificate provides entrypoint to update the certificate // storeCertificate provides entrypoint to update the certificate
func (c *certificationRotation) loadCertificate(certifacte tls.Certificate) error { func (c *certificationRotation) storeCertificate(certifacte tls.Certificate) error {
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
c.certificate = certifacte c.certificate = certifacte
......
...@@ -62,7 +62,7 @@ func TestGetCertificate(t *testing.T) { ...@@ -62,7 +62,7 @@ func TestGetCertificate(t *testing.T) {
func TestLoadCertificate(t *testing.T) { func TestLoadCertificate(t *testing.T) {
c := newTestCertificateRotator(t) c := newTestCertificateRotator(t)
assert.NotEmpty(t, c.certificate) assert.NotEmpty(t, c.certificate)
c.loadCertificate(tls.Certificate{}) c.storeCertificate(tls.Certificate{})
crt, err := c.GetCertificate(nil) crt, err := c.GetCertificate(nil)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, &tls.Certificate{}, crt) assert.Equal(t, &tls.Certificate{}, crt)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment