| Index: appengine/cmd/cron/ui/common.go
|
| diff --git a/appengine/cmd/cron/ui/common.go b/appengine/cmd/cron/ui/common.go
|
| index 4e21ca07d7957556f9da77dd089fd1617bdc12f5..b603fe8e355097b421bd9091130672cdad6338ed 100644
|
| --- a/appengine/cmd/cron/ui/common.go
|
| +++ b/appengine/cmd/cron/ui/common.go
|
| @@ -1,61 +1,59 @@
|
| // 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 ui implements request handlers that serve user facing HTML pages.
|
| package ui
|
|
|
| import (
|
| "strings"
|
|
|
| - "github.com/julienschmidt/httprouter"
|
| "golang.org/x/net/context"
|
| "google.golang.org/appengine"
|
|
|
| "github.com/luci/gae/service/info"
|
|
|
| "github.com/luci/luci-go/server/auth"
|
| "github.com/luci/luci-go/server/auth/xsrf"
|
| - "github.com/luci/luci-go/server/middleware"
|
| + "github.com/luci/luci-go/server/router"
|
| "github.com/luci/luci-go/server/templates"
|
|
|
| "github.com/luci/luci-go/appengine/cmd/cron/engine"
|
| )
|
|
|
| // Config is global configuration of UI handlers.
|
| type Config struct {
|
| Engine engine.Engine
|
| TemplatesPath string // path to templates directory deployed to GAE
|
| }
|
|
|
| // InstallHandlers adds HTTP handlers that render HTML pages.
|
| -func InstallHandlers(r *httprouter.Router, base middleware.Base, cfg Config) {
|
| +func InstallHandlers(r *router.Router, base router.MiddlewareChain, cfg Config) {
|
| tmpl := prepareTemplates(cfg.TemplatesPath)
|
|
|
| - wrap := func(h middleware.Handler) httprouter.Handle {
|
| - h = auth.Authenticate(h)
|
| - h = templates.WithTemplates(h, tmpl)
|
| - h = middleware.WithContextValue(h, configContextKey(0), &cfg)
|
| - return base(h)
|
| - }
|
| + m := append(base, func(c *router.Context, next router.Handler) {
|
| + c.Context = context.WithValue(c.Context, configContextKey(0), &cfg)
|
| + next(c)
|
| + }, templates.WithTemplates(tmpl), auth.Authenticate)
|
|
|
| - r.GET("/", wrap(indexPage))
|
| - r.GET("/jobs/:ProjectID", wrap(projectPage))
|
| - r.GET("/jobs/:ProjectID/:JobID", wrap(jobPage))
|
| - r.GET("/jobs/:ProjectID/:JobID/:InvID", wrap(invocationPage))
|
| + r.GET("/", m, indexPage)
|
| + r.GET("/jobs/:ProjectID", m, projectPage)
|
| + r.GET("/jobs/:ProjectID/:JobID", m, jobPage)
|
| + r.GET("/jobs/:ProjectID/:JobID/:InvID", m, invocationPage)
|
|
|
| // All POST forms must be protected with XSRF token.
|
| - r.POST("/actions/runJob/:ProjectID/:JobID", wrap(xsrf.WithTokenCheck(runJobAction)))
|
| - r.POST("/actions/pauseJob/:ProjectID/:JobID", wrap(xsrf.WithTokenCheck(pauseJobAction)))
|
| - r.POST("/actions/resumeJob/:ProjectID/:JobID", wrap(xsrf.WithTokenCheck(resumeJobAction)))
|
| - r.POST("/actions/abortInvocation/:ProjectID/:JobID/:InvID", wrap(xsrf.WithTokenCheck(abortInvocationAction)))
|
| + mxsrf := append(m, xsrf.WithTokenCheck)
|
| + r.POST("/actions/runJob/:ProjectID/:JobID", mxsrf, runJobAction)
|
| + r.POST("/actions/pauseJob/:ProjectID/:JobID", mxsrf, pauseJobAction)
|
| + r.POST("/actions/resumeJob/:ProjectID/:JobID", mxsrf, resumeJobAction)
|
| + r.POST("/actions/abortInvocation/:ProjectID/:JobID/:InvID", mxsrf, abortInvocationAction)
|
| }
|
|
|
| type configContextKey int
|
|
|
| // config returns Config passed to InstallHandlers.
|
| func config(c context.Context) *Config {
|
| cfg, _ := c.Value(configContextKey(0)).(*Config)
|
| if cfg == nil {
|
| panic("impossible, configContextKey is not set")
|
| }
|
|
|