| Index: server/auth/db.go
|
| diff --git a/server/auth/db.go b/server/auth/db.go
|
| index 61ca54c985f49dedcc81ae1554443c862807a67e..e69f3d26f9ff504352a658e931bc0b7bc8b4909e 100644
|
| --- a/server/auth/db.go
|
| +++ b/server/auth/db.go
|
| @@ -1,35 +1,33 @@
|
| // Copyright 2015 The LUCI Authors. All rights reserved.
|
| // Use of this source code is governed under the Apache License, Version 2.0
|
| // that can be found in the LICENSE file.
|
|
|
| package auth
|
|
|
| import (
|
| "errors"
|
| "fmt"
|
| "net"
|
| - "net/http"
|
| "strings"
|
| "time"
|
|
|
| - "github.com/julienschmidt/httprouter"
|
| "golang.org/x/net/context"
|
|
|
| "github.com/luci/luci-go/common/clock"
|
| "github.com/luci/luci-go/common/lazyslot"
|
| "github.com/luci/luci-go/common/logging"
|
| "github.com/luci/luci-go/common/mathrand"
|
|
|
| "github.com/luci/luci-go/server/auth/identity"
|
| "github.com/luci/luci-go/server/auth/service/protocol"
|
| - "github.com/luci/luci-go/server/middleware"
|
| + "github.com/luci/luci-go/server/router"
|
| "github.com/luci/luci-go/server/secrets"
|
| )
|
|
|
| // ErrNoDB is returned by default DB returned from GetDB if no DBFactory is
|
| // installed in the context.
|
| var ErrNoDB = errors.New("auth: using default auth.DB, install a properly mocked one instead")
|
|
|
| // DB is interface to access a database of authorization related information.
|
| //
|
| // It is static read only object that represent snapshot of auth data at some
|
| @@ -79,24 +77,25 @@ type DBCacheUpdater func(c context.Context, prev DB) (DB, error)
|
|
|
| // dbKey is used for context.Context key of DBFactory.
|
| type dbKey int
|
|
|
| // UseDB sets a factory that creates DB instances.
|
| func UseDB(c context.Context, f DBFactory) context.Context {
|
| return context.WithValue(c, dbKey(0), f)
|
| }
|
|
|
| // WithDB is middleware that sets given DBFactory in the context before calling
|
| -// a handler.
|
| -func WithDB(h middleware.Handler, f DBFactory) middleware.Handler {
|
| - return func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
| - h(UseDB(c, f), rw, r, p)
|
| +// the next handler.
|
| +func WithDB(f DBFactory) router.Middleware {
|
| + return func(c *router.Context, next router.Handler) {
|
| + c.Context = UseDB(c.Context, f)
|
| + next(c)
|
| }
|
| }
|
|
|
| // GetDB returns most recent snapshot of authorization database using factory
|
| // installed in the context via `UseDB`.
|
| //
|
| // If no factory is installed, returns DB that forbids everything and logs
|
| // errors. It is often good enough for unit tests that do not care about
|
| // authorization, and still not horribly bad if accidentally used in production.
|
| //
|
|
|