Add logger interface and stop relying on Logrus directly

This commit is contained in:
Mark Sagi-Kazar 2019-02-22 13:19:23 +01:00
parent ca66289077
commit be581fa7ff
No known key found for this signature in database
GPG key ID: 34CC109EB5ED1C2A
38 changed files with 203 additions and 133 deletions

View file

@ -6,9 +6,9 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/server" "github.com/dexidp/dex/server"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/etcd" "github.com/dexidp/dex/storage/etcd"
@ -127,7 +127,7 @@ type Storage struct {
// StorageConfig is a configuration that can create a storage. // StorageConfig is a configuration that can create a storage.
type StorageConfig interface { type StorageConfig interface {
Open(logrus.FieldLogger) (storage.Storage, error) Open(logger log.Logger) (storage.Storage, error)
} }
var storages = map[string]func() StorageConfig{ var storages = map[string]func() StorageConfig{

View file

@ -23,6 +23,7 @@ import (
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"github.com/dexidp/dex/api" "github.com/dexidp/dex/api"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/server" "github.com/dexidp/dex/server"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
) )
@ -324,7 +325,7 @@ func (f *utcFormatter) Format(e *logrus.Entry) ([]byte, error) {
return f.f.Format(e) return f.f.Format(e)
} }
func newLogger(level string, format string) (logrus.FieldLogger, error) { func newLogger(level string, format string) (log.Logger, error) {
var logLevel logrus.Level var logLevel logrus.Level
switch strings.ToLower(level) { switch strings.ToLower(level) {
case "debug": case "debug":
@ -347,9 +348,9 @@ func newLogger(level string, format string) (logrus.FieldLogger, error) {
return nil, fmt.Errorf("log format is not one of the supported values (%s): %s", strings.Join(logFormats, ", "), format) return nil, fmt.Errorf("log format is not one of the supported values (%s): %s", strings.Join(logFormats, ", "), format)
} }
return &logrus.Logger{ return log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &formatter, Formatter: &formatter,
Level: logLevel, Level: logLevel,
}, nil }), nil
} }

View file

@ -8,9 +8,8 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
// Config holds the configuration parameters for a connector which returns an // Config holds the configuration parameters for a connector which returns an
@ -18,14 +17,14 @@ import (
type Config struct{} type Config struct{}
// Open returns an authentication strategy which requires no user interaction. // Open returns an authentication strategy which requires no user interaction.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &callback{logger: logger, pathSuffix: "/" + id}, nil return &callback{logger: logger, pathSuffix: "/" + id}, nil
} }
// Callback is a connector which returns an identity with the HTTP header // Callback is a connector which returns an identity with the HTTP header
// X-Remote-User as verified email. // X-Remote-User as verified email.
type callback struct { type callback struct {
logger logrus.FieldLogger logger log.Logger
pathSuffix string pathSuffix string
} }

View file

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/dexidp/dex/pkg/log"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"sync" "sync"
@ -14,8 +15,6 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/bitbucket" "golang.org/x/oauth2/bitbucket"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
) )
@ -40,7 +39,7 @@ type Config struct {
} }
// Open returns a strategy for logging in through Bitbucket. // Open returns a strategy for logging in through Bitbucket.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
b := bitbucketConnector{ b := bitbucketConnector{
redirectURI: c.RedirectURI, redirectURI: c.RedirectURI,
@ -70,7 +69,7 @@ type bitbucketConnector struct {
teams []string teams []string
clientID string clientID string
clientSecret string clientSecret string
logger logrus.FieldLogger logger log.Logger
apiURL string apiURL string
// the following are used only for tests // the following are used only for tests

View file

@ -16,11 +16,11 @@ import (
"strings" "strings"
"time" "time"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/github" "golang.org/x/oauth2/github"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
const ( const (
@ -53,7 +53,6 @@ type Config struct {
// Org holds org-team filters, in which teams are optional. // Org holds org-team filters, in which teams are optional.
type Org struct { type Org struct {
// Organization name in github (not slug, full name). Only users in this github // Organization name in github (not slug, full name). Only users in this github
// organization can authenticate. // organization can authenticate.
Name string `json:"name"` Name string `json:"name"`
@ -66,14 +65,14 @@ type Org struct {
} }
// Open returns a strategy for logging in through GitHub. // Open returns a strategy for logging in through GitHub.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
if c.Org != "" { if c.Org != "" {
// Return error if both 'org' and 'orgs' fields are used. // Return error if both 'org' and 'orgs' fields are used.
if len(c.Orgs) > 0 { if len(c.Orgs) > 0 {
return nil, errors.New("github: cannot use both 'org' and 'orgs' fields simultaneously") return nil, errors.New("github: cannot use both 'org' and 'orgs' fields simultaneously")
} }
logger.Warnln("github: legacy field 'org' being used. Switch to the newer 'orgs' field structure") logger.Warn("github: legacy field 'org' being used. Switch to the newer 'orgs' field structure")
} }
g := githubConnector{ g := githubConnector{
@ -137,7 +136,7 @@ type githubConnector struct {
orgs []Org orgs []Org
clientID string clientID string
clientSecret string clientSecret string
logger logrus.FieldLogger logger log.Logger
// apiURL defaults to "https://api.github.com" // apiURL defaults to "https://api.github.com"
apiURL string apiURL string
// hostName of the GitHub enterprise account. // hostName of the GitHub enterprise account.

View file

@ -10,10 +10,10 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
const ( const (
@ -42,7 +42,7 @@ type gitlabUser struct {
} }
// Open returns a strategy for logging in through GitLab. // Open returns a strategy for logging in through GitLab.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
if c.BaseURL == "" { if c.BaseURL == "" {
c.BaseURL = "https://gitlab.com" c.BaseURL = "https://gitlab.com"
} }
@ -71,7 +71,7 @@ type gitlabConnector struct {
org string org string
clientID string clientID string
clientSecret string clientSecret string
logger logrus.FieldLogger logger log.Logger
} }
func (c *gitlabConnector) oauth2Config(scopes connector.Scopes) *oauth2.Config { func (c *gitlabConnector) oauth2Config(scopes connector.Scopes) *oauth2.Config {

View file

@ -9,9 +9,8 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
type conn struct { type conn struct {
@ -19,7 +18,7 @@ type conn struct {
Host string Host string
AdminUsername string AdminUsername string
AdminPassword string AdminPassword string
Logger logrus.FieldLogger Logger log.Logger
} }
type userKeystone struct { type userKeystone struct {
@ -102,7 +101,7 @@ var (
) )
// Open returns an authentication strategy using Keystone. // Open returns an authentication strategy using Keystone.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &conn{ return &conn{
c.Domain, c.Domain,
c.Host, c.Host,

View file

@ -12,9 +12,8 @@ import (
"gopkg.in/ldap.v2" "gopkg.in/ldap.v2"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
// Config holds the configuration parameters for the LDAP connector. The LDAP // Config holds the configuration parameters for the LDAP connector. The LDAP
@ -165,7 +164,7 @@ func parseScope(s string) (int, bool) {
} }
// Open returns an authentication strategy using LDAP. // Open returns an authentication strategy using LDAP.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
conn, err := c.OpenConnector(logger) conn, err := c.OpenConnector(logger)
if err != nil { if err != nil {
return nil, err return nil, err
@ -179,7 +178,7 @@ type refreshData struct {
} }
// OpenConnector is the same as Open but returns a type with all implemented connector interfaces. // OpenConnector is the same as Open but returns a type with all implemented connector interfaces.
func (c *Config) OpenConnector(logger logrus.FieldLogger) (interface { func (c *Config) OpenConnector(logger log.Logger) (interface {
connector.Connector connector.Connector
connector.PasswordConnector connector.PasswordConnector
connector.RefreshConnector connector.RefreshConnector
@ -187,7 +186,7 @@ func (c *Config) OpenConnector(logger logrus.FieldLogger) (interface {
return c.openConnector(logger) return c.openConnector(logger)
} }
func (c *Config) openConnector(logger logrus.FieldLogger) (*ldapConnector, error) { func (c *Config) openConnector(logger log.Logger) (*ldapConnector, error) {
requiredFields := []struct { requiredFields := []struct {
name string name string
@ -259,7 +258,7 @@ type ldapConnector struct {
tlsConfig *tls.Config tlsConfig *tls.Config
logger logrus.FieldLogger logger log.Logger
} }
var ( var (

View file

@ -17,6 +17,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
const envVar = "DEX_LDAP_TESTS" const envVar = "DEX_LDAP_TESTS"
@ -875,7 +876,7 @@ func runTests(t *testing.T, schema string, connMethod connectionMethod, config *
c.BindDN = "cn=admin,dc=example,dc=org" c.BindDN = "cn=admin,dc=example,dc=org"
c.BindPW = "admin" c.BindPW = "admin"
l := &logrus.Logger{Out: ioutil.Discard, Formatter: &logrus.TextFormatter{}} l := log.NewLogrusLogger(&logrus.Logger{Out: ioutil.Discard, Formatter: &logrus.TextFormatter{}})
conn, err := c.openConnector(l) conn, err := c.openConnector(l)
if err != nil { if err != nil {

View file

@ -11,9 +11,8 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
const ( const (
@ -30,7 +29,7 @@ type Config struct {
} }
// Open returns a strategy for logging in through LinkedIn // Open returns a strategy for logging in through LinkedIn
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &linkedInConnector{ return &linkedInConnector{
oauth2Config: &oauth2.Config{ oauth2Config: &oauth2.Config{
ClientID: c.ClientID, ClientID: c.ClientID,
@ -52,7 +51,7 @@ type connectorData struct {
type linkedInConnector struct { type linkedInConnector struct {
oauth2Config *oauth2.Config oauth2Config *oauth2.Config
logger logrus.FieldLogger logger log.Logger
} }
// LinkedIn doesn't provide refresh tokens, so refresh tokens issued by Dex // LinkedIn doesn't provide refresh tokens, so refresh tokens issued by Dex

View file

@ -14,9 +14,8 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
const ( const (
@ -39,7 +38,7 @@ type Config struct {
} }
// Open returns a strategy for logging in through Microsoft. // Open returns a strategy for logging in through Microsoft.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
m := microsoftConnector{ m := microsoftConnector{
redirectURI: c.RedirectURI, redirectURI: c.RedirectURI,
clientID: c.ClientID, clientID: c.ClientID,
@ -76,7 +75,7 @@ type microsoftConnector struct {
tenant string tenant string
onlySecurityGroups bool onlySecurityGroups bool
groups []string groups []string
logger logrus.FieldLogger logger log.Logger
} }
func (c *microsoftConnector) isOrgTenant() bool { func (c *microsoftConnector) isOrgTenant() bool {

View file

@ -8,14 +8,13 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
// NewCallbackConnector returns a mock connector which requires no user interaction. It always returns // NewCallbackConnector returns a mock connector which requires no user interaction. It always returns
// the same (fake) identity. // the same (fake) identity.
func NewCallbackConnector(logger logrus.FieldLogger) connector.Connector { func NewCallbackConnector(logger log.Logger) connector.Connector {
return &Callback{ return &Callback{
Identity: connector.Identity{ Identity: connector.Identity{
UserID: "0-385-28089-0", UserID: "0-385-28089-0",
@ -40,7 +39,7 @@ var (
type Callback struct { type Callback struct {
// The returned identity. // The returned identity.
Identity connector.Identity Identity connector.Identity
Logger logrus.FieldLogger Logger log.Logger
} }
// LoginURL returns the URL to redirect the user to login with. // LoginURL returns the URL to redirect the user to login with.
@ -71,7 +70,7 @@ func (m *Callback) Refresh(ctx context.Context, s connector.Scopes, identity con
type CallbackConfig struct{} type CallbackConfig struct{}
// Open returns an authentication strategy which requires no user interaction. // Open returns an authentication strategy which requires no user interaction.
func (c *CallbackConfig) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *CallbackConfig) Open(id string, logger log.Logger) (connector.Connector, error) {
return NewCallbackConnector(logger), nil return NewCallbackConnector(logger), nil
} }
@ -83,7 +82,7 @@ type PasswordConfig struct {
} }
// Open returns an authentication strategy which prompts for a predefined username and password. // Open returns an authentication strategy which prompts for a predefined username and password.
func (c *PasswordConfig) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *PasswordConfig) Open(id string, logger log.Logger) (connector.Connector, error) {
if c.Username == "" { if c.Username == "" {
return nil, errors.New("no username supplied") return nil, errors.New("no username supplied")
} }
@ -96,7 +95,7 @@ func (c *PasswordConfig) Open(id string, logger logrus.FieldLogger) (connector.C
type passwordConnector struct { type passwordConnector struct {
username string username string
password string password string
logger logrus.FieldLogger logger log.Logger
} }
func (p passwordConnector) Close() error { return nil } func (p passwordConnector) Close() error { return nil }

View file

@ -11,10 +11,10 @@ import (
"sync" "sync"
"github.com/coreos/go-oidc" "github.com/coreos/go-oidc"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
) )
// Config holds configuration options for OpenID Connect logins. // Config holds configuration options for OpenID Connect logins.
@ -75,7 +75,7 @@ func registerBrokenAuthHeaderProvider(url string) {
// Open returns a connector which can be used to login users through an upstream // Open returns a connector which can be used to login users through an upstream
// OpenID Connect provider. // OpenID Connect provider.
func (c *Config) Open(id string, logger logrus.FieldLogger) (conn connector.Connector, err error) { func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, err error) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
provider, err := oidc.NewProvider(ctx, c.Issuer) provider, err := oidc.NewProvider(ctx, c.Issuer)
@ -130,7 +130,7 @@ type oidcConnector struct {
verifier *oidc.IDTokenVerifier verifier *oidc.IDTokenVerifier
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
logger logrus.FieldLogger logger log.Logger
hostedDomains []string hostedDomains []string
} }

View file

@ -14,11 +14,10 @@ import (
"time" "time"
"github.com/beevik/etree" "github.com/beevik/etree"
"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
dsig "github.com/russellhaering/goxmldsig" dsig "github.com/russellhaering/goxmldsig"
"github.com/russellhaering/goxmldsig/etreeutils" "github.com/russellhaering/goxmldsig/etreeutils"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector"
) )
const ( const (
@ -126,11 +125,11 @@ func (c certStore) Certificates() (roots []*x509.Certificate, err error) {
// Open validates the config and returns a connector. It does not actually // Open validates the config and returns a connector. It does not actually
// validate connectivity with the provider. // validate connectivity with the provider.
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return c.openConnector(logger) return c.openConnector(logger)
} }
func (c *Config) openConnector(logger logrus.FieldLogger) (*provider, error) { func (c *Config) openConnector(logger log.Logger) (*provider, error) {
requiredFields := []struct { requiredFields := []struct {
name, val string name, val string
}{ }{
@ -241,7 +240,7 @@ type provider struct {
nameIDPolicyFormat string nameIDPolicyFormat string
logger logrus.FieldLogger logger log.Logger
} }
func (p *provider) POSTData(s connector.Scopes, id string) (action, value string, err error) { func (p *provider) POSTData(s connector.Scopes, id string) (action, value string, err error) {

View file

@ -5,6 +5,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/pem" "encoding/pem"
"errors" "errors"
"github.com/dexidp/dex/pkg/log"
"io/ioutil" "io/ioutil"
"sort" "sort"
"testing" "testing"
@ -304,7 +305,7 @@ func (r responseTest) run(t *testing.T) {
t.Fatalf("parse test time: %v", err) t.Fatalf("parse test time: %v", err)
} }
conn, err := c.openConnector(logrus.New()) conn, err := c.openConnector(log.NewLogrusLogger(logrus.New()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -338,7 +339,7 @@ func (r responseTest) run(t *testing.T) {
} }
func TestConfigCAData(t *testing.T) { func TestConfigCAData(t *testing.T) {
logger := logrus.New() logger := log.NewLogrusLogger(logrus.New())
validPEM, err := ioutil.ReadFile("testdata/ca.crt") validPEM, err := ioutil.ReadFile("testdata/ca.crt")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -475,7 +476,7 @@ func newProvider(ssoIssuer string, redirectURI string) *provider {
usernameAttr: "user", usernameAttr: "user",
emailAttr: "email", emailAttr: "email",
redirectURI: redirectURI, redirectURI: redirectURI,
logger: logrus.New(), logger: log.NewLogrusLogger(logrus.New()),
} }
} }

17
pkg/log/logger.go Normal file
View file

@ -0,0 +1,17 @@
// Package log provides a logger interface for logger libraries
// so that dex does not depend on any of them directly.
// It also includes a default implementation using Logrus (used by dex previously).
package log
// Logger serves as an adapter interface for logger libraries
// so that dex does not depend on any of them directly.
type Logger interface {
WithField(key string, value interface{}) Logger
Info(msg string)
Warn(msg string)
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Errorf(format string, args ...interface{})
}

45
pkg/log/logrus.go Normal file
View file

@ -0,0 +1,45 @@
package log
import "github.com/sirupsen/logrus"
// LogrusLogger is an adapter for Logrus implementing the Logger interface.
type LogrusLogger struct {
logger logrus.FieldLogger
}
// NewLogrusLogger returns a new Logger wrapping Logrus.
func NewLogrusLogger(logger logrus.FieldLogger) *LogrusLogger {
return &LogrusLogger{
logger: logger,
}
}
// WithField adds a field to the log entry.
func (l *LogrusLogger) WithField(key string, value interface{}) Logger {
return NewLogrusLogger(l.logger.WithField(key, value))
}
// Info logs an Info level event.
func (l *LogrusLogger) Info(msg string) {
l.logger.Info(msg)
}
// Warn logs a Warn level event.
func (l *LogrusLogger) Warn(msg string) {
l.logger.Warn(msg)
}
// Debugf formats and logs a Debug level event.
func (l *LogrusLogger) Debugf(format string, args ...interface{}) {
l.logger.Debugf(format, args...)
}
// Infof formats and logs an Info level event.
func (l *LogrusLogger) Infof(format string, args ...interface{}) {
l.logger.Infof(format, args...)
}
// Errorf formats and logs n Error level event.
func (l *LogrusLogger) Errorf(format string, args ...interface{}) {
l.logger.Errorf(format, args...)
}

10
pkg/log/logrus_test.go Normal file
View file

@ -0,0 +1,10 @@
package log
import "testing"
func TestLogrusLoggerImplementsLoggerInterface(t *testing.T) {
var i interface{} = new(LogrusLogger)
if _, ok := i.(Logger); !ok {
t.Errorf("expected %T to implement Logger interface", i)
}
}

View file

@ -10,9 +10,8 @@ import (
// https://github.com/grpc/grpc-go/issues/711 // https://github.com/grpc/grpc-go/issues/711
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/api" "github.com/dexidp/dex/api"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/server/internal" "github.com/dexidp/dex/server/internal"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/version" "github.com/dexidp/dex/version"
@ -34,7 +33,7 @@ const (
) )
// NewAPI returns a server which implements the gRPC API interface. // NewAPI returns a server which implements the gRPC API interface.
func NewAPI(s storage.Storage, logger logrus.FieldLogger) api.DexServer { func NewAPI(s storage.Storage, logger log.Logger) api.DexServer {
return dexAPI{ return dexAPI{
s: s, s: s,
logger: logger, logger: logger,
@ -43,7 +42,7 @@ func NewAPI(s storage.Storage, logger logrus.FieldLogger) api.DexServer {
type dexAPI struct { type dexAPI struct {
s storage.Storage s storage.Storage
logger logrus.FieldLogger logger log.Logger
} }
func (d dexAPI) CreateClient(ctx context.Context, req *api.CreateClientReq) (*api.CreateClientResp, error) { func (d dexAPI) CreateClient(ctx context.Context, req *api.CreateClientReq) (*api.CreateClientResp, error) {

View file

@ -11,6 +11,7 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"github.com/dexidp/dex/api" "github.com/dexidp/dex/api"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/server/internal" "github.com/dexidp/dex/server/internal"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/memory" "github.com/dexidp/dex/storage/memory"
@ -28,7 +29,7 @@ type apiClient struct {
} }
// newAPI constructs a gRCP client connected to a backing server. // newAPI constructs a gRCP client connected to a backing server.
func newAPI(s storage.Storage, logger logrus.FieldLogger, t *testing.T) *apiClient { func newAPI(s storage.Storage, logger log.Logger, t *testing.T) *apiClient {
l, err := net.Listen("tcp", "127.0.0.1:0") l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -57,11 +58,11 @@ func newAPI(s storage.Storage, logger logrus.FieldLogger, t *testing.T) *apiClie
// Attempts to create, update and delete a test Password // Attempts to create, update and delete a test Password
func TestPassword(t *testing.T) { func TestPassword(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
s := memory.New(logger) s := memory.New(logger)
client := newAPI(s, logger, t) client := newAPI(s, logger, t)
@ -122,11 +123,11 @@ func TestPassword(t *testing.T) {
// Ensures checkCost returns expected values // Ensures checkCost returns expected values
func TestCheckCost(t *testing.T) { func TestCheckCost(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
s := memory.New(logger) s := memory.New(logger)
client := newAPI(s, logger, t) client := newAPI(s, logger, t)
@ -179,11 +180,11 @@ func TestCheckCost(t *testing.T) {
// Attempts to list and revoke an exisiting refresh token. // Attempts to list and revoke an exisiting refresh token.
func TestRefreshToken(t *testing.T) { func TestRefreshToken(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
s := memory.New(logger) s := memory.New(logger)
client := newAPI(s, logger, t) client := newAPI(s, logger, t)
@ -292,11 +293,11 @@ func TestRefreshToken(t *testing.T) {
} }
func TestUpdateClient(t *testing.T) { func TestUpdateClient(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
s := memory.New(logger) s := memory.New(logger)
client := newAPI(s, logger, t) client := newAPI(s, logger, t)

View file

@ -12,8 +12,7 @@ import (
"gopkg.in/square/go-jose.v2" "gopkg.in/square/go-jose.v2"
"github.com/sirupsen/logrus" "github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
) )
@ -62,7 +61,7 @@ type keyRotater struct {
strategy rotationStrategy strategy rotationStrategy
now func() time.Time now func() time.Time
logger logrus.FieldLogger logger log.Logger
} }
// startKeyRotation begins key rotation in a new goroutine, closing once the context is canceled. // startKeyRotation begins key rotation in a new goroutine, closing once the context is canceled.

View file

@ -8,6 +8,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/memory" "github.com/dexidp/dex/storage/memory"
) )
@ -67,11 +68,11 @@ func TestKeyRotater(t *testing.T) {
// Only the last 5 verification keys are expected to be kept around. // Only the last 5 verification keys are expected to be kept around.
maxVerificationKeys := 5 maxVerificationKeys := 5
l := &logrus.Logger{ l := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
r := &keyRotater{ r := &keyRotater{
Storage: memory.New(l), Storage: memory.New(l),

View file

@ -16,12 +16,6 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"github.com/felixge/httpsnoop"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/connector/authproxy" "github.com/dexidp/dex/connector/authproxy"
"github.com/dexidp/dex/connector/bitbucketcloud" "github.com/dexidp/dex/connector/bitbucketcloud"
@ -34,7 +28,12 @@ import (
"github.com/dexidp/dex/connector/mock" "github.com/dexidp/dex/connector/mock"
"github.com/dexidp/dex/connector/oidc" "github.com/dexidp/dex/connector/oidc"
"github.com/dexidp/dex/connector/saml" "github.com/dexidp/dex/connector/saml"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/felixge/httpsnoop"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
) )
// LocalConnector is the local passwordDB connector which is an internal // LocalConnector is the local passwordDB connector which is an internal
@ -80,7 +79,7 @@ type Config struct {
Web WebConfig Web WebConfig
Logger logrus.FieldLogger Logger log.Logger
PrometheusRegistry *prometheus.Registry PrometheusRegistry *prometheus.Registry
} }
@ -142,7 +141,7 @@ type Server struct {
idTokensValidFor time.Duration idTokensValidFor time.Duration
authRequestsValidFor time.Duration authRequestsValidFor time.Duration
logger logrus.FieldLogger logger log.Logger
} }
// NewServer constructs a server from the provided config. // NewServer constructs a server from the provided config.
@ -431,7 +430,7 @@ func (s *Server) startGarbageCollection(ctx context.Context, frequency time.Dura
// ConnectorConfig is a configuration that can open a connector. // ConnectorConfig is a configuration that can open a connector.
type ConnectorConfig interface { type ConnectorConfig interface {
Open(id string, logger logrus.FieldLogger) (connector.Connector, error) Open(id string, logger log.Logger) (connector.Connector, error)
} }
// ConnectorsConfig variable provides an easy way to return a config struct // ConnectorsConfig variable provides an easy way to return a config struct
@ -454,7 +453,7 @@ var ConnectorsConfig = map[string]func() ConnectorConfig{
} }
// openConnector will parse the connector config and open the connector. // openConnector will parse the connector config and open the connector.
func openConnector(logger logrus.FieldLogger, conn storage.Connector) (connector.Connector, error) { func openConnector(logger log.Logger, conn storage.Connector) (connector.Connector, error) {
var c connector.Connector var c connector.Connector
f, ok := ConnectorsConfig[conn.Type] f, ok := ConnectorsConfig[conn.Type]

View file

@ -30,6 +30,7 @@ import (
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
"github.com/dexidp/dex/connector/mock" "github.com/dexidp/dex/connector/mock"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/memory" "github.com/dexidp/dex/storage/memory"
) )
@ -74,11 +75,11 @@ FDWV28nTP9sqbtsmU8Tem2jzMvZ7C/Q0AuDoKELFUpux8shm8wfIhyaPnXUGZoAZ
Np4vUwMSYV5mopESLWOg3loBxKyLGFtgGKVCjGiQvy6zISQ4fQo= Np4vUwMSYV5mopESLWOg3loBxKyLGFtgGKVCjGiQvy6zISQ4fQo=
-----END RSA PRIVATE KEY-----`) -----END RSA PRIVATE KEY-----`)
var logger = &logrus.Logger{ var logger = log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Config)) (*httptest.Server, *Server) { func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Config)) (*httptest.Server, *Server) {
var server *Server var server *Server

View file

@ -6,8 +6,8 @@ import (
"github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3/namespace" "github.com/coreos/etcd/clientv3/namespace"
"github.com/coreos/etcd/pkg/transport" "github.com/coreos/etcd/pkg/transport"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
) )
@ -36,11 +36,11 @@ type Etcd struct {
} }
// Open creates a new storage implementation backed by Etcd // Open creates a new storage implementation backed by Etcd
func (p *Etcd) Open(logger logrus.FieldLogger) (storage.Storage, error) { func (p *Etcd) Open(logger log.Logger) (storage.Storage, error) {
return p.open(logger) return p.open(logger)
} }
func (p *Etcd) open(logger logrus.FieldLogger) (*conn, error) { func (p *Etcd) open(logger log.Logger) (*conn, error) {
cfg := clientv3.Config{ cfg := clientv3.Config{
Endpoints: p.Endpoints, Endpoints: p.Endpoints,
DialTimeout: defaultDialTimeout, DialTimeout: defaultDialTimeout,

View file

@ -8,8 +8,8 @@ import (
"time" "time"
"github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/clientv3"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
) )
@ -29,7 +29,7 @@ const (
type conn struct { type conn struct {
db *clientv3.Client db *clientv3.Client
logger logrus.FieldLogger logger log.Logger
} }
func (c *conn) Close() error { func (c *conn) Close() error {

View file

@ -3,6 +3,7 @@ package etcd
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/dexidp/dex/pkg/log"
"os" "os"
"runtime" "runtime"
"strings" "strings"
@ -53,11 +54,11 @@ func cleanDB(c *conn) error {
return nil return nil
} }
var logger = &logrus.Logger{ var logger = log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
func TestEtcd(t *testing.T) { func TestEtcd(t *testing.T) {
testEtcdEnv := "DEX_ETCD_ENDPOINTS" testEtcdEnv := "DEX_ETCD_ENDPOINTS"

View file

@ -24,9 +24,9 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/gtank/cryptopasta" "github.com/gtank/cryptopasta"
"github.com/sirupsen/logrus"
"golang.org/x/net/http2" "golang.org/x/net/http2"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/kubernetes/k8sapi" "github.com/dexidp/dex/storage/kubernetes/k8sapi"
) )
@ -35,7 +35,7 @@ type client struct {
client *http.Client client *http.Client
baseURL string baseURL string
namespace string namespace string
logger logrus.FieldLogger logger log.Logger
// Hash function to map IDs (which could span a large range) to Kubernetes names. // Hash function to map IDs (which could span a large range) to Kubernetes names.
// While this is not currently upgradable, it could be in the future. // While this is not currently upgradable, it could be in the future.
@ -253,7 +253,7 @@ func (c *client) put(resource, name string, v interface{}) error {
return checkHTTPErr(resp, http.StatusOK) return checkHTTPErr(resp, http.StatusOK)
} }
func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, logger logrus.FieldLogger, useTPR bool) (*client, error) { func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, logger log.Logger, useTPR bool) (*client, error) {
tlsConfig := cryptopasta.DefaultTLSConfig() tlsConfig := cryptopasta.DefaultTLSConfig()
data := func(b string, file string) ([]byte, error) { data := func(b string, file string) ([]byte, error) {
if b != "" { if b != "" {

View file

@ -7,8 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/sirupsen/logrus" "github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/kubernetes/k8sapi" "github.com/dexidp/dex/storage/kubernetes/k8sapi"
) )
@ -43,7 +42,7 @@ type Config struct {
} }
// Open returns a storage using Kubernetes third party resource. // Open returns a storage using Kubernetes third party resource.
func (c *Config) Open(logger logrus.FieldLogger) (storage.Storage, error) { func (c *Config) Open(logger log.Logger) (storage.Storage, error) {
cli, err := c.open(logger, false) cli, err := c.open(logger, false)
if err != nil { if err != nil {
return nil, err return nil, err
@ -56,7 +55,7 @@ func (c *Config) Open(logger logrus.FieldLogger) (storage.Storage, error) {
// //
// waitForResources controls if errors creating the resources cause this method to return // waitForResources controls if errors creating the resources cause this method to return
// immediately (used during testing), or if the client will asynchronously retry. // immediately (used during testing), or if the client will asynchronously retry.
func (c *Config) open(logger logrus.FieldLogger, waitForResources bool) (*client, error) { func (c *Config) open(logger log.Logger, waitForResources bool) (*client, error) {
if c.InCluster && (c.KubeConfigFile != "") { if c.InCluster && (c.KubeConfigFile != "") {
return nil, errors.New("cannot specify both 'inCluster' and 'kubeConfigFile'") return nil, errors.New("cannot specify both 'inCluster' and 'kubeConfigFile'")
} }

View file

@ -7,6 +7,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/conformance" "github.com/dexidp/dex/storage/conformance"
) )
@ -24,11 +25,11 @@ func loadClient(t *testing.T) *client {
if config.KubeConfigFile == "" { if config.KubeConfigFile == "" {
t.Skipf("test environment variable %q not set, skipping", testKubeConfigEnv) t.Skipf("test environment variable %q not set, skipping", testKubeConfigEnv)
} }
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
s, err := config.open(logger, true) s, err := config.open(logger, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View file

@ -6,13 +6,12 @@ import (
"sync" "sync"
"time" "time"
"github.com/sirupsen/logrus" "github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
) )
// New returns an in memory storage. // New returns an in memory storage.
func New(logger logrus.FieldLogger) storage.Storage { func New(logger log.Logger) storage.Storage {
return &memStorage{ return &memStorage{
clients: make(map[string]storage.Client), clients: make(map[string]storage.Client),
authCodes: make(map[string]storage.AuthCode), authCodes: make(map[string]storage.AuthCode),
@ -33,7 +32,7 @@ type Config struct {
} }
// Open always returns a new in memory storage. // 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 return New(logger), nil
} }
@ -50,7 +49,7 @@ type memStorage struct {
keys storage.Keys keys storage.Keys
logger logrus.FieldLogger logger log.Logger
} }
type offlineSessionID struct { type offlineSessionID struct {

View file

@ -6,16 +6,17 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/conformance" "github.com/dexidp/dex/storage/conformance"
) )
func TestStorage(t *testing.T) { func TestStorage(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
newStorage := func() storage.Storage { newStorage := func() storage.Storage {
return New(logger) return New(logger)

View file

@ -8,15 +8,16 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
) )
func TestStaticClients(t *testing.T) { func TestStaticClients(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
backing := New(logger) backing := New(logger)
c1 := storage.Client{ID: "foo", Secret: "foo_secret"} c1 := storage.Client{ID: "foo", Secret: "foo_secret"}
@ -99,11 +100,11 @@ func TestStaticClients(t *testing.T) {
} }
func TestStaticPasswords(t *testing.T) { func TestStaticPasswords(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
backing := New(logger) backing := New(logger)
p1 := storage.Password{Email: "foo@example.com", Username: "foo_secret"} p1 := storage.Password{Email: "foo@example.com", Username: "foo_secret"}
@ -211,11 +212,11 @@ func TestStaticPasswords(t *testing.T) {
} }
func TestStaticConnectors(t *testing.T) { func TestStaticConnectors(t *testing.T) {
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
backing := New(logger) backing := New(logger)
config1 := []byte(`{"issuer": "https://accounts.google.com"}`) config1 := []byte(`{"issuer": "https://accounts.google.com"}`)

View file

@ -11,8 +11,8 @@ import (
"github.com/lib/pq" "github.com/lib/pq"
sqlite3 "github.com/mattn/go-sqlite3" sqlite3 "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
) )
@ -28,7 +28,7 @@ type SQLite3 struct {
} }
// Open creates a new storage implementation backed by SQLite3 // Open creates a new storage implementation backed by SQLite3
func (s *SQLite3) Open(logger logrus.FieldLogger) (storage.Storage, error) { func (s *SQLite3) Open(logger log.Logger) (storage.Storage, error) {
conn, err := s.open(logger) conn, err := s.open(logger)
if err != nil { if err != nil {
return nil, err return nil, err
@ -36,7 +36,7 @@ func (s *SQLite3) Open(logger logrus.FieldLogger) (storage.Storage, error) {
return conn, nil return conn, nil
} }
func (s *SQLite3) open(logger logrus.FieldLogger) (*conn, error) { func (s *SQLite3) open(logger log.Logger) (*conn, error) {
db, err := sql.Open("sqlite3", s.File) db, err := sql.Open("sqlite3", s.File)
if err != nil { if err != nil {
return nil, err return nil, err
@ -99,7 +99,7 @@ type Postgres struct {
} }
// Open creates a new storage implementation backed by Postgres. // Open creates a new storage implementation backed by Postgres.
func (p *Postgres) Open(logger logrus.FieldLogger) (storage.Storage, error) { func (p *Postgres) Open(logger log.Logger) (storage.Storage, error) {
conn, err := p.open(logger, p.createDataSourceName()) conn, err := p.open(logger, p.createDataSourceName())
if err != nil { if err != nil {
return nil, err return nil, err
@ -179,7 +179,7 @@ func (p *Postgres) createDataSourceName() string {
return strings.Join(parameters, " ") return strings.Join(parameters, " ")
} }
func (p *Postgres) open(logger logrus.FieldLogger, dataSourceName string) (*conn, error) { func (p *Postgres) open(logger log.Logger, dataSourceName string) (*conn, error) {
db, err := sql.Open("postgres", dataSourceName) db, err := sql.Open("postgres", dataSourceName)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -9,6 +9,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/conformance" "github.com/dexidp/dex/storage/conformance"
) )
@ -43,11 +44,11 @@ func cleanDB(c *conn) error {
return err return err
} }
var logger = &logrus.Logger{ var logger = log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
func TestSQLite3(t *testing.T) { func TestSQLite3(t *testing.T) {
newStorage := func() storage.Storage { newStorage := func() storage.Storage {

View file

@ -7,6 +7,8 @@ import (
sqlite3 "github.com/mattn/go-sqlite3" sqlite3 "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/dexidp/dex/pkg/log"
) )
func TestMigrate(t *testing.T) { func TestMigrate(t *testing.T) {
@ -16,11 +18,11 @@ func TestMigrate(t *testing.T) {
} }
defer db.Close() defer db.Close()
logger := &logrus.Logger{ logger := log.NewLogrusLogger(&logrus.Logger{
Out: os.Stderr, Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true}, Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} })
errCheck := func(err error) bool { errCheck := func(err error) bool {
sqlErr, ok := err.(sqlite3.Error) sqlErr, ok := err.(sqlite3.Error)

View file

@ -3,11 +3,10 @@ package sql
import ( import (
"database/sql" "database/sql"
"github.com/dexidp/dex/pkg/log"
"regexp" "regexp"
"time" "time"
"github.com/sirupsen/logrus"
// import third party drivers // import third party drivers
_ "github.com/lib/pq" _ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -113,7 +112,7 @@ func (c *conn) translateArgs(args []interface{}) []interface{} {
type conn struct { type conn struct {
db *sql.DB db *sql.DB
flavor flavor flavor flavor
logger logrus.FieldLogger logger log.Logger
alreadyExistsCheck func(err error) bool alreadyExistsCheck func(err error) bool
} }

View file

@ -4,7 +4,7 @@ import (
"errors" "errors"
"strings" "strings"
"github.com/sirupsen/logrus" "github.com/dexidp/dex/pkg/log"
) )
// Tests for this code are in the "memory" package, since this package doesn't // Tests for this code are in the "memory" package, since this package doesn't
@ -89,11 +89,11 @@ type staticPasswordsStorage struct {
// A map of passwords that is indexed by lower-case email ids // A map of passwords that is indexed by lower-case email ids
passwordsByEmail map[string]Password passwordsByEmail map[string]Password
logger logrus.FieldLogger logger log.Logger
} }
// WithStaticPasswords returns a storage with a read-only set of passwords. // WithStaticPasswords returns a storage with a read-only set of passwords.
func WithStaticPasswords(s Storage, staticPasswords []Password, logger logrus.FieldLogger) Storage { func WithStaticPasswords(s Storage, staticPasswords []Password, logger log.Logger) Storage {
passwordsByEmail := make(map[string]Password, len(staticPasswords)) passwordsByEmail := make(map[string]Password, len(staticPasswords))
for _, p := range staticPasswords { for _, p := range staticPasswords {
//Enable case insensitive email comparison. //Enable case insensitive email comparison.