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

Unified Diff: appengine/cmd/cron/ui/job.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update tests Created 4 years, 6 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
Index: appengine/cmd/cron/ui/job.go
diff --git a/appengine/cmd/cron/ui/job.go b/appengine/cmd/cron/ui/job.go
index b6735f093e323acd42cf21d57041cd39fb6853e6..8409ac66fb6fcaa9bd88d9195317704ad91b3d9a 100644
--- a/appengine/cmd/cron/ui/job.go
+++ b/appengine/cmd/cron/ui/job.go
@@ -17,10 +17,13 @@ import (
"github.com/luci/gae/service/memcache"
"github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/server/auth"
+ "github.com/luci/luci-go/server/router"
"github.com/luci/luci-go/server/templates"
)
-func jobPage(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
+func jobPage(ctx *router.Context) {
+ c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params
+
projectID := p.ByName("ProjectID")
jobID := p.ByName("JobID")
cursor := r.URL.Query().Get("c")
@@ -32,6 +35,7 @@ func jobPage(c context.Context, w http.ResponseWriter, r *http.Request, p httpro
}
if job == nil {
http.Error(w, "No such job", http.StatusNotFound)
+ ctx.Abort()
return
}
@@ -83,11 +87,14 @@ func jobPage(c context.Context, w http.ResponseWriter, r *http.Request, p httpro
////////////////////////////////////////////////////////////////////////////////
// Actions.
-func runJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
+func runJobAction(ctx *router.Context) {
+ c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params
+
projectID := p.ByName("ProjectID")
jobID := p.ByName("JobID")
if !isJobOwner(c, projectID, jobID) {
http.Error(w, "Forbidden", 403)
+ ctx.Abort()
return
}
@@ -108,6 +115,7 @@ func runJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p h
invNonce, err := e.TriggerInvocation(c, fullJobID, auth.CurrentIdentity(c))
if err != nil {
genericReply(err)
+ ctx.Abort()
return
}
@@ -140,17 +148,17 @@ func runJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p h
}
}
-func pauseJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- handleJobAction(c, w, r, p, func(jobID string) error {
- who := auth.CurrentIdentity(c)
- return config(c).Engine.PauseJob(c, jobID, who)
+func pauseJobAction(c *router.Context) {
+ handleJobAction(c.Context, c.Writer, c.Request, c.Params, func(jobID string) error {
+ who := auth.CurrentIdentity(c.Context)
+ return config(c.Context).Engine.PauseJob(c.Context, jobID, who)
})
}
-func resumeJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- handleJobAction(c, w, r, p, func(jobID string) error {
- who := auth.CurrentIdentity(c)
- return config(c).Engine.ResumeJob(c, jobID, who)
+func resumeJobAction(c *router.Context) {
+ handleJobAction(c.Context, c.Writer, c.Request, c.Params, func(jobID string) error {
+ who := auth.CurrentIdentity(c.Context)
+ return config(c.Context).Engine.ResumeJob(c.Context, jobID, who)
})
}

Powered by Google App Engine
This is Rietveld 408576698