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

Side by Side Diff: scheduler/appengine/frontend/handler.go

Issue 2830443003: auth: Refactor how authentication methods are passed to server/auth library. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
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 frontend implements GAE web server for luci-scheduler service. 5 // Package frontend implements GAE web server for luci-scheduler service.
6 // 6 //
7 // Due to the way classic GAE imports work, this package can not have 7 // Due to the way classic GAE imports work, this package can not have
8 // subpackages (or at least subpackages referenced via absolute import path). 8 // subpackages (or at least subpackages referenced via absolute import path).
9 // We can't use relative imports because luci-go will then become unbuildable 9 // We can't use relative imports because luci-go will then become unbuildable
10 // by regular (non GAE) toolset. 10 // by regular (non GAE) toolset.
(...skipping 12 matching lines...) Expand all
23 23
24 "golang.org/x/net/context" 24 "golang.org/x/net/context"
25 "google.golang.org/appengine" 25 "google.golang.org/appengine"
26 26
27 "github.com/luci/gae/service/info" 27 "github.com/luci/gae/service/info"
28 tq "github.com/luci/gae/service/taskqueue" 28 tq "github.com/luci/gae/service/taskqueue"
29 29
30 "github.com/luci/luci-go/grpc/discovery" 30 "github.com/luci/luci-go/grpc/discovery"
31 "github.com/luci/luci-go/grpc/grpcmon" 31 "github.com/luci/luci-go/grpc/grpcmon"
32 "github.com/luci/luci-go/grpc/prpc" 32 "github.com/luci/luci-go/grpc/prpc"
33 "github.com/luci/luci-go/server/auth"
34 "github.com/luci/luci-go/server/router" 33 "github.com/luci/luci-go/server/router"
35 34
36 "github.com/luci/luci-go/appengine/gaeauth/server"
37 "github.com/luci/luci-go/appengine/gaemiddleware" 35 "github.com/luci/luci-go/appengine/gaemiddleware"
38 36
39 "github.com/luci/luci-go/common/data/rand/mathrand" 37 "github.com/luci/luci-go/common/data/rand/mathrand"
40 "github.com/luci/luci-go/common/errors" 38 "github.com/luci/luci-go/common/errors"
41 "github.com/luci/luci-go/common/logging" 39 "github.com/luci/luci-go/common/logging"
42 40
43 "github.com/luci/luci-go/scheduler/api/scheduler/v1" 41 "github.com/luci/luci-go/scheduler/api/scheduler/v1"
44 42
45 "github.com/luci/luci-go/scheduler/appengine/apiservers" 43 "github.com/luci/luci-go/scheduler/appengine/apiservers"
46 "github.com/luci/luci-go/scheduler/appengine/catalog" 44 "github.com/luci/luci-go/scheduler/appengine/catalog"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 132 }
135 globalEngine = engine.NewEngine(engine.Config{ 133 globalEngine = engine.NewEngine(engine.Config{
136 Catalog: globalCatalog, 134 Catalog: globalCatalog,
137 TimersQueuePath: "/internal/tasks/timers", 135 TimersQueuePath: "/internal/tasks/timers",
138 TimersQueueName: "timers", 136 TimersQueueName: "timers",
139 InvocationsQueuePath: "/internal/tasks/invocations", 137 InvocationsQueuePath: "/internal/tasks/invocations",
140 InvocationsQueueName: "invocations", 138 InvocationsQueueName: "invocations",
141 PubSubPushPath: "/pubsub", 139 PubSubPushPath: "/pubsub",
142 }) 140 })
143 141
144 » // Middleware chains. 'baseUI' is used for web interface routes, 'base' for 142 » // Do global init before handling requests.
145 » // everything else.
146 base := gaemiddleware.BaseProd().Extend( 143 base := gaemiddleware.BaseProd().Extend(
147 func(c *router.Context, next router.Handler) { 144 func(c *router.Context, next router.Handler) {
148 globalInit.Do(func() { initializeGlobalState(c.Context) }) 145 globalInit.Do(func() { initializeGlobalState(c.Context) })
149 next(c) 146 next(c)
150 }, 147 },
151 ) 148 )
152 baseUI := base.Extend(auth.Use(auth.Authenticator{server.CookieAuth}))
Vadim Sh. 2017/04/18 23:46:24 moved to ui.InstallHandlers
153 149
154 // Setup HTTP routes. 150 // Setup HTTP routes.
155 r := router.New() 151 r := router.New()
156 152
157 gaemiddleware.InstallHandlersWithMiddleware(r, base) 153 gaemiddleware.InstallHandlersWithMiddleware(r, base)
158 154
159 » ui.InstallHandlers(r, baseUI, ui.Config{ 155 » ui.InstallHandlers(r, base, ui.Config{
160 Engine: globalEngine, 156 Engine: globalEngine,
161 Catalog: globalCatalog, 157 Catalog: globalCatalog,
162 TemplatesPath: "templates", 158 TemplatesPath: "templates",
163 }) 159 })
164 160
165 r.POST("/pubsub", base, pubsubPushHandler) // auth is via custom tokens 161 r.POST("/pubsub", base, pubsubPushHandler) // auth is via custom tokens
166 r.GET("/internal/cron/read-config", base.Extend(gaemiddleware.RequireCro n), readConfigCron) 162 r.GET("/internal/cron/read-config", base.Extend(gaemiddleware.RequireCro n), readConfigCron)
167 r.POST("/internal/tasks/read-project-config", base.Extend(gaemiddleware. RequireTaskQueue("read-project-config")), readProjectConfigTask) 163 r.POST("/internal/tasks/read-project-config", base.Extend(gaemiddleware. RequireTaskQueue("read-project-config")), readProjectConfigTask)
168 r.POST("/internal/tasks/timers", base.Extend(gaemiddleware.RequireTaskQu eue("timers")), actionTask) 164 r.POST("/internal/tasks/timers", base.Extend(gaemiddleware.RequireTaskQu eue("timers")), actionTask)
169 r.POST("/internal/tasks/invocations", base.Extend(gaemiddleware.RequireT askQueue("invocations")), actionTask) 165 r.POST("/internal/tasks/invocations", base.Extend(gaemiddleware.RequireT askQueue("invocations")), actionTask)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return 292 return
297 } 293 }
298 count, _ := strconv.Atoi(rc.Request.Header.Get("X-AppEngine-TaskExecutio nCount")) 294 count, _ := strconv.Atoi(rc.Request.Header.Get("X-AppEngine-TaskExecutio nCount"))
299 err = globalEngine.ExecuteSerializedAction(rc.Context, body, count) 295 err = globalEngine.ExecuteSerializedAction(rc.Context, body, count)
300 if err != nil { 296 if err != nil {
301 rc.err(err, "Error when executing the action") 297 rc.err(err, "Error when executing the action")
302 return 298 return
303 } 299 }
304 rc.ok() 300 rc.ok()
305 } 301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698