Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Unified Diff: milo/appengine/common/middleware.go

Issue 2796743004: Milo flex raw log viewer endpoint (Closed)
Patch Set: More review Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/Makefile ('k') | milo/appengine/frontend/dispatch.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/common/middleware.go
diff --git a/milo/appengine/common/middleware.go b/milo/appengine/common/middleware.go
index 5e74b389009f209479d749880b8f6d6cfa2a4e2f..3397d6e808d3ef7de65f1297f5e7e77caeb93592 100644
--- a/milo/appengine/common/middleware.go
+++ b/milo/appengine/common/middleware.go
@@ -10,10 +10,13 @@ import (
"golang.org/x/net/context"
+ "github.com/luci/gae/impl/cloud"
"github.com/luci/gae/service/info"
"github.com/luci/luci-go/appengine/gaeauth/server"
"github.com/luci/luci-go/appengine/gaemiddleware"
"github.com/luci/luci-go/common/clock"
+ "github.com/luci/luci-go/common/cloudlogging"
+ "github.com/luci/luci-go/common/logging/cloudlog"
"github.com/luci/luci-go/server/analytics"
"github.com/luci/luci-go/server/auth"
"github.com/luci/luci-go/server/auth/identity"
@@ -21,6 +24,8 @@ import (
"github.com/luci/luci-go/server/templates"
)
+var authconfig *auth.Config
+
// GetTemplateBundles is used to render HTML templates. It provides base args
// passed to all templates.
func GetTemplateBundle() *templates.Bundle {
@@ -64,6 +69,35 @@ func Base() router.MiddlewareChain {
)
}
+// FlexBase returns the basic middleware for use on appengine flex. Flex does not
+// allow the use of appengine APIs.
+func FlexBase() router.MiddlewareChain {
+ // Use the cloud logger.
+ logger := func(c *router.Context, next router.Handler) {
+ project := info.AppID(c.Context)
+ logClient, err := cloudlogging.NewClient(
+ cloudlogging.ClientOptions{
+ ProjectID: project,
+ LogID: "gae_app",
+ ResourceType: "gae_app",
+ },
+ // TODO(hinoka): This may require authentication to actually work.
+ http.DefaultClient)
+ if err != nil {
+ panic(err)
+ }
+ c.Context = cloudlog.Use(c.Context, cloudlog.Config{}, logClient)
+ next(c)
+ }
+ // Installs the Info and Datastore services.
+ base := func(c *router.Context, next router.Handler) {
+ c.Context = cloud.UseFlex(c.Context)
+ next(c)
+ }
+ // Now chain it all together!
+ return router.NewMiddlewareChain(base, logger)
+}
+
// The context key, so that we can embed the http.Request object into
// the context.
var requestKey = "http.request"
« no previous file with comments | « milo/Makefile ('k') | milo/appengine/frontend/dispatch.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698