Add logger interface and stop relying on Logrus directly
This commit is contained in:
@@ -6,13 +6,12 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/dexidp/dex/pkg/log"
|
||||
"github.com/dexidp/dex/storage"
|
||||
)
|
||||
|
||||
// New returns an in memory storage.
|
||||
func New(logger logrus.FieldLogger) storage.Storage {
|
||||
func New(logger log.Logger) storage.Storage {
|
||||
return &memStorage{
|
||||
clients: make(map[string]storage.Client),
|
||||
authCodes: make(map[string]storage.AuthCode),
|
||||
@@ -33,7 +32,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
// Open always returns a new in memory storage.
|
||||
func (c *Config) Open(logger logrus.FieldLogger) (storage.Storage, error) {
|
||||
func (c *Config) Open(logger log.Logger) (storage.Storage, error) {
|
||||
return New(logger), nil
|
||||
}
|
||||
|
||||
@@ -50,7 +49,7 @@ type memStorage struct {
|
||||
|
||||
keys storage.Keys
|
||||
|
||||
logger logrus.FieldLogger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
type offlineSessionID struct {
|
||||
|
@@ -6,16 +6,17 @@ import (
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/dexidp/dex/pkg/log"
|
||||
"github.com/dexidp/dex/storage"
|
||||
"github.com/dexidp/dex/storage/conformance"
|
||||
)
|
||||
|
||||
func TestStorage(t *testing.T) {
|
||||
logger := &logrus.Logger{
|
||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
||||
Out: os.Stderr,
|
||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||
Level: logrus.DebugLevel,
|
||||
}
|
||||
})
|
||||
|
||||
newStorage := func() storage.Storage {
|
||||
return New(logger)
|
||||
|
@@ -8,15 +8,16 @@ import (
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/dexidp/dex/pkg/log"
|
||||
"github.com/dexidp/dex/storage"
|
||||
)
|
||||
|
||||
func TestStaticClients(t *testing.T) {
|
||||
logger := &logrus.Logger{
|
||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
||||
Out: os.Stderr,
|
||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||
Level: logrus.DebugLevel,
|
||||
}
|
||||
})
|
||||
backing := New(logger)
|
||||
|
||||
c1 := storage.Client{ID: "foo", Secret: "foo_secret"}
|
||||
@@ -99,11 +100,11 @@ func TestStaticClients(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStaticPasswords(t *testing.T) {
|
||||
logger := &logrus.Logger{
|
||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
||||
Out: os.Stderr,
|
||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||
Level: logrus.DebugLevel,
|
||||
}
|
||||
})
|
||||
backing := New(logger)
|
||||
|
||||
p1 := storage.Password{Email: "foo@example.com", Username: "foo_secret"}
|
||||
@@ -211,11 +212,11 @@ func TestStaticPasswords(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStaticConnectors(t *testing.T) {
|
||||
logger := &logrus.Logger{
|
||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
||||
Out: os.Stderr,
|
||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||
Level: logrus.DebugLevel,
|
||||
}
|
||||
})
|
||||
backing := New(logger)
|
||||
|
||||
config1 := []byte(`{"issuer": "https://accounts.google.com"}`)
|
||||
|
Reference in New Issue
Block a user