server: modify error messages to use logrus.

This commit is contained in:
rithu john
2016-12-12 14:54:01 -08:00
parent 6033c45976
commit 9949a1313c
11 changed files with 151 additions and 137 deletions

View File

@@ -7,12 +7,12 @@ import (
"errors"
"fmt"
"io"
"log"
"time"
"golang.org/x/net/context"
"gopkg.in/square/go-jose.v2"
"github.com/Sirupsen/logrus"
"github.com/coreos/dex/storage"
)
@@ -57,18 +57,20 @@ type keyRotater struct {
strategy rotationStrategy
now func() time.Time
logger logrus.FieldLogger
}
// startKeyRotation begins key rotation in a new goroutine, closing once the context is canceled.
//
// The method blocks until after the first attempt to rotate keys has completed. That way
// healthy storages will return from this call with valid keys.
func startKeyRotation(ctx context.Context, s storage.Storage, strategy rotationStrategy, now func() time.Time) {
rotater := keyRotater{s, strategy, now}
func (s *Server) startKeyRotation(ctx context.Context, strategy rotationStrategy, now func() time.Time) {
rotater := keyRotater{s.storage, strategy, now, s.logger}
// Try to rotate immediately so properly configured storages will have keys.
if err := rotater.rotate(); err != nil {
log.Printf("failed to rotate keys: %v", err)
s.logger.Errorf("failed to rotate keys: %v", err)
}
go func() {
@@ -78,7 +80,7 @@ func startKeyRotation(ctx context.Context, s storage.Storage, strategy rotationS
return
case <-time.After(time.Second * 30):
if err := rotater.rotate(); err != nil {
log.Printf("failed to rotate keys: %v", err)
s.logger.Errorf("failed to rotate keys: %v", err)
}
}
}
@@ -94,7 +96,7 @@ func (k keyRotater) rotate() error {
if k.now().Before(keys.NextRotation) {
return nil
}
log.Println("keys expired, rotating")
k.logger.Infof("keys expired, rotating")
// Generate the key outside of a storage transaction.
key, err := k.strategy.key()
@@ -154,6 +156,6 @@ func (k keyRotater) rotate() error {
if err != nil {
return err
}
log.Printf("keys rotated, next rotation: %s", nextRotation)
k.logger.Infof("keys rotated, next rotation: %s", nextRotation)
return nil
}