Merge pull request #1408 from sagikazarmark/logger-interface

Add logger interface and stop relying on Logrus directly
This commit is contained in:
Eric Chiang 2019-02-22 12:51:31 -08:00 committed by GitHub
commit c113df2730
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 103 additions and 100 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":

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

@ -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) {

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

@ -0,0 +1,15 @@
// 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 {
Info(args ...interface{})
Warn(args ...interface{})
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Errorf(format string, args ...interface{})
}

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)

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

@ -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]
@ -486,7 +485,7 @@ func (s *Server) OpenConnector(conn storage.Connector) (Connector, error) {
c = newPasswordDB(s.storage) c = newPasswordDB(s.storage)
} else { } else {
var err error var err error
c, err = openConnector(s.logger.WithField("connector", conn.Name), conn) c, err = openConnector(s.logger, conn)
if err != nil { if err != nil {
return Connector{}, fmt.Errorf("failed to open connector: %v", err) return Connector{}, fmt.Errorf("failed to open connector: %v", err)
} }

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

@ -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

@ -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

@ -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

@ -6,11 +6,11 @@ import (
"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"
"github.com/dexidp/dex/pkg/log"
) )
// flavor represents a specific SQL implementation, and is used to translate query strings // flavor represents a specific SQL implementation, and is used to translate query strings
@ -113,7 +113,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.