| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package gaemiddleware | 5 package gaemiddleware |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 | 9 |
| 10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
| 11 "google.golang.org/appengine" | 11 "google.golang.org/appengine" |
| 12 | 12 |
| 13 "github.com/luci/gae/filter/dscache" | 13 "github.com/luci/gae/filter/dscache" |
| 14 "github.com/luci/gae/impl/prod" | 14 "github.com/luci/gae/impl/prod" |
| 15 "github.com/luci/gae/service/urlfetch" | 15 "github.com/luci/gae/service/urlfetch" |
| 16 | 16 |
| 17 "github.com/luci/luci-go/common/config" | 17 "github.com/luci/luci-go/common/config" |
| 18 "github.com/luci/luci-go/common/data/caching/cacheContext" | 18 "github.com/luci/luci-go/common/data/caching/cacheContext" |
| 19 "github.com/luci/luci-go/common/data/caching/proccache" | 19 "github.com/luci/luci-go/common/data/caching/proccache" |
| 20 "github.com/luci/luci-go/common/data/rand/mathrand" | |
| 21 "github.com/luci/luci-go/common/logging" | 20 "github.com/luci/luci-go/common/logging" |
| 22 | 21 |
| 23 "github.com/luci/luci-go/server/auth" | 22 "github.com/luci/luci-go/server/auth" |
| 24 "github.com/luci/luci-go/server/auth/authdb" | 23 "github.com/luci/luci-go/server/auth/authdb" |
| 25 "github.com/luci/luci-go/server/middleware" | 24 "github.com/luci/luci-go/server/middleware" |
| 26 "github.com/luci/luci-go/server/router" | 25 "github.com/luci/luci-go/server/router" |
| 27 "github.com/luci/luci-go/server/settings" | 26 "github.com/luci/luci-go/server/settings" |
| 28 | 27 |
| 29 "github.com/luci/luci-go/appengine/gaeauth/client" | 28 "github.com/luci/luci-go/appengine/gaeauth/client" |
| 30 "github.com/luci/luci-go/appengine/gaeauth/server" | 29 "github.com/luci/luci-go/appengine/gaeauth/server" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 55 globalAuthConfig = auth.Config{ | 54 globalAuthConfig = auth.Config{ |
| 56 DBProvider: authdb.NewDBCache(server.GetAuthDB), | 55 DBProvider: authdb.NewDBCache(server.GetAuthDB), |
| 57 Signer: gaesigner.Signer{}, | 56 Signer: gaesigner.Signer{}, |
| 58 AccessTokenProvider: client.GetAccessToken, | 57 AccessTokenProvider: client.GetAccessToken, |
| 59 AnonymousTransport: urlfetch.Get, | 58 AnonymousTransport: urlfetch.Get, |
| 60 GlobalCache: &server.Memcache{Namespace: "__luciauth__"}
, | 59 GlobalCache: &server.Memcache{Namespace: "__luciauth__"}
, |
| 61 } | 60 } |
| 62 | 61 |
| 63 // globalTsMonState holds state related to time series monitoring. | 62 // globalTsMonState holds state related to time series monitoring. |
| 64 globalTsMonState = &tsmon.State{} | 63 globalTsMonState = &tsmon.State{} |
| 65 | |
| 66 // globalMathRand is a global "mathrand.Rand" instance. Get, as per its | |
| 67 // function signature, returns an instance that is protected by a lock,
so | |
| 68 // this is safe for its expected concurrent use. | |
| 69 globalMathRand = mathrand.Get(context.Background()) | |
| 70 ) | 64 ) |
| 71 | 65 |
| 72 // WithProd installs the set of standard production AppEngine services: | 66 // WithProd installs the set of standard production AppEngine services: |
| 73 // * github.com/luci/luci-go/common/logging (set default level to debug). | 67 // * github.com/luci/luci-go/common/logging (set default level to debug). |
| 74 // * github.com/luci/luci-go/common/data/rand/mathrand. | |
| 75 // * github.com/luci/gae/impl/prod (production appengine services) | 68 // * github.com/luci/gae/impl/prod (production appengine services) |
| 76 // * github.com/luci/luci-go/appengine/gaeauth/client (appengine urlfetch tran
sport) | 69 // * github.com/luci/luci-go/appengine/gaeauth/client (appengine urlfetch tran
sport) |
| 77 // * github.com/luci/luci-go/server/proccache (in process memory cache) | 70 // * github.com/luci/luci-go/server/proccache (in process memory cache) |
| 78 // * github.com/luci/luci-go/server/settings (global app settings) | 71 // * github.com/luci/luci-go/server/settings (global app settings) |
| 79 // * github.com/luci/luci-go/appengine/gaesecrets (access to secret keys in da
tastore) | 72 // * github.com/luci/luci-go/appengine/gaesecrets (access to secret keys in da
tastore) |
| 80 // * github.com/luci/luci-go/appengine/gaeauth/server/gaesigner (RSA signer) | 73 // * github.com/luci/luci-go/appengine/gaeauth/server/gaesigner (RSA signer) |
| 81 // * github.com/luci/luci-go/appengine/gaeauth/server/auth (user groups databa
se) | 74 // * github.com/luci/luci-go/appengine/gaeauth/server/auth (user groups databa
se) |
| 82 func WithProd(c context.Context, req *http.Request) context.Context { | 75 func WithProd(c context.Context, req *http.Request) context.Context { |
| 83 // These are needed to use fetchCachedSettings. | 76 // These are needed to use fetchCachedSettings. |
| 84 c = logging.SetLevel(c, logging.Debug) | 77 c = logging.SetLevel(c, logging.Debug) |
| 85 c = mathrand.SetRand(c, globalMathRand) | |
| 86 c = prod.Use(c, req) | 78 c = prod.Use(c, req) |
| 87 c = settings.Use(c, globalSettings) | 79 c = settings.Use(c, globalSettings) |
| 88 | 80 |
| 89 // Fetch and apply configuration stored in the datastore. | 81 // Fetch and apply configuration stored in the datastore. |
| 90 cachedSettings := fetchCachedSettings(c) | 82 cachedSettings := fetchCachedSettings(c) |
| 91 c = logging.SetLevel(c, cachedSettings.LoggingLevel) | 83 c = logging.SetLevel(c, cachedSettings.LoggingLevel) |
| 92 if !cachedSettings.DisableDSCache { | 84 if !cachedSettings.DisableDSCache { |
| 93 c = dscache.AlwaysFilterRDS(c) | 85 c = dscache.AlwaysFilterRDS(c) |
| 94 } | 86 } |
| 95 | 87 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 125 // BaseProd returns a list of middleware: WithProd middleware, a panic catcher i
f this | 117 // BaseProd returns a list of middleware: WithProd middleware, a panic catcher i
f this |
| 126 // is not a devserver, and the monitoring middleware. | 118 // is not a devserver, and the monitoring middleware. |
| 127 func BaseProd() router.MiddlewareChain { | 119 func BaseProd() router.MiddlewareChain { |
| 128 if appengine.IsDevAppServer() { | 120 if appengine.IsDevAppServer() { |
| 129 return router.NewMiddlewareChain(ProdServices, globalTsMonState.
Middleware) | 121 return router.NewMiddlewareChain(ProdServices, globalTsMonState.
Middleware) |
| 130 } | 122 } |
| 131 return router.NewMiddlewareChain( | 123 return router.NewMiddlewareChain( |
| 132 ProdServices, middleware.WithPanicCatcher, globalTsMonState.Midd
leware, | 124 ProdServices, middleware.WithPanicCatcher, globalTsMonState.Midd
leware, |
| 133 ) | 125 ) |
| 134 } | 126 } |
| OLD | NEW |