| 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" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // * 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) |
| 73 // * github.com/luci/luci-go/appengine/gaeauth/server/gaesigner (RSA signer) | 73 // * github.com/luci/luci-go/appengine/gaeauth/server/gaesigner (RSA signer) |
| 74 // * 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) |
| 75 func WithProd(c context.Context, req *http.Request) context.Context { | 75 func WithProd(c context.Context, req *http.Request) context.Context { |
| 76 // These are needed to use fetchCachedSettings. | 76 // These are needed to use fetchCachedSettings. |
| 77 c = logging.SetLevel(c, logging.Debug) | 77 c = logging.SetLevel(c, logging.Debug) |
| 78 c = prod.Use(c, req) | 78 c = prod.Use(c, req) |
| 79 c = settings.Use(c, globalSettings) | 79 c = settings.Use(c, globalSettings) |
| 80 | 80 |
| 81 // Fetch and apply configuration stored in the datastore. | 81 // Fetch and apply configuration stored in the datastore. |
| 82 » settings := fetchCachedSettings(c) | 82 » cachedSettings := fetchCachedSettings(c) |
| 83 » c = logging.SetLevel(c, settings.LoggingLevel) | 83 » c = logging.SetLevel(c, cachedSettings.LoggingLevel) |
| 84 » if !settings.DisableDSCache { | 84 » if !cachedSettings.DisableDSCache { |
| 85 c = dscache.AlwaysFilterRDS(c, nil) | 85 c = dscache.AlwaysFilterRDS(c, nil) |
| 86 } | 86 } |
| 87 | 87 |
| 88 // The rest of the service may use applied configuration. | 88 // The rest of the service may use applied configuration. |
| 89 c = proccache.Use(c, globalProcessCache) | 89 c = proccache.Use(c, globalProcessCache) |
| 90 c = config.SetImplementation(c, gaeconfig.New(c)) | 90 c = config.SetImplementation(c, gaeconfig.New(c)) |
| 91 c = gaesecrets.Use(c, nil) | 91 c = gaesecrets.Use(c, nil) |
| 92 c = auth.SetConfig(c, globalAuthConfig) | 92 c = auth.SetConfig(c, globalAuthConfig) |
| 93 return cacheContext.Wrap(c) | 93 return cacheContext.Wrap(c) |
| 94 } | 94 } |
| 95 | 95 |
| 96 // ProdServices is a middleware that installs the set of standard production | 96 // ProdServices is a middleware that installs the set of standard production |
| 97 // AppEngine services by calling WithProd. | 97 // AppEngine services by calling WithProd. |
| 98 func ProdServices(c *router.Context, next router.Handler) { | 98 func ProdServices(c *router.Context, next router.Handler) { |
| 99 c.Context = WithProd(c.Context, c.Request) | 99 c.Context = WithProd(c.Context, c.Request) |
| 100 next(c) | 100 next(c) |
| 101 } | 101 } |
| 102 | 102 |
| 103 // BaseProd returns a list of middleware: WithProd middleware, a panic catcher i
f this | 103 // BaseProd returns a list of middleware: WithProd middleware, a panic catcher i
f this |
| 104 // is not a devserver, and the monitoring middleware. | 104 // is not a devserver, and the monitoring middleware. |
| 105 func BaseProd() router.MiddlewareChain { | 105 func BaseProd() router.MiddlewareChain { |
| 106 if appengine.IsDevAppServer() { | 106 if appengine.IsDevAppServer() { |
| 107 return router.NewMiddlewareChain(ProdServices, globalTsMonState.
Middleware) | 107 return router.NewMiddlewareChain(ProdServices, globalTsMonState.
Middleware) |
| 108 } | 108 } |
| 109 return router.NewMiddlewareChain( | 109 return router.NewMiddlewareChain( |
| 110 ProdServices, middleware.WithPanicCatcher, globalTsMonState.Midd
leware, | 110 ProdServices, middleware.WithPanicCatcher, globalTsMonState.Midd
leware, |
| 111 ) | 111 ) |
| 112 } | 112 } |
| OLD | NEW |