| Index: appengine/gaeauth/server/internal/authdb/handlers.go
|
| diff --git a/appengine/gaeauth/server/internal/authdb/handlers.go b/appengine/gaeauth/server/internal/authdb/handlers.go
|
| index 574604ea2d969bfc12e2a438031b6a06e4b70642..db604f13925f5c5f59506421aaf2eb53d01674f6 100644
|
| --- a/appengine/gaeauth/server/internal/authdb/handlers.go
|
| +++ b/appengine/gaeauth/server/internal/authdb/handlers.go
|
| @@ -10,7 +10,6 @@ import (
|
| "net/http"
|
| "net/url"
|
|
|
| - "github.com/julienschmidt/httprouter"
|
| "golang.org/x/net/context"
|
| "google.golang.org/appengine"
|
|
|
| @@ -20,7 +19,7 @@ import (
|
| "github.com/luci/luci-go/common/errors"
|
| "github.com/luci/luci-go/common/logging"
|
| "github.com/luci/luci-go/server/auth/service"
|
| - "github.com/luci/luci-go/server/middleware"
|
| + "github.com/luci/luci-go/server/router"
|
| )
|
|
|
| const (
|
| @@ -29,11 +28,11 @@ const (
|
| )
|
|
|
| // InstallHandlers installs PubSub related HTTP handlers.
|
| -func InstallHandlers(r *httprouter.Router, base middleware.Base) {
|
| +func InstallHandlers(r *router.Router, handlers []router.Handler) {
|
| if appengine.IsDevAppServer() {
|
| - r.GET(pubSubPullURLPath, base(pubSubPull))
|
| + r.GET(pubSubPullURLPath, append(handlers, pubSubPull)...)
|
| }
|
| - r.POST(pubSubPushURLPath, base(pubSubPush))
|
| + r.POST(pubSubPushURLPath, append(handlers, pubSubPush)...)
|
| }
|
|
|
| // authenticatePubSub injects into a context a transport that authenticates
|
| @@ -82,12 +81,13 @@ func subscriptionName(c context.Context, authServiceURL string) string {
|
| //
|
| // Used only on dev server for manual testing. Prod services use push-based
|
| // delivery.
|
| -func pubSubPull(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
| +func pubSubPull(ctx *router.Context) {
|
| if !appengine.IsDevAppServer() {
|
| - replyError(c, rw, errors.New("not a dev server"))
|
| + replyError(ctx.Context, ctx.Writer, errors.New("not a dev server"))
|
| + ctx.Abort()
|
| return
|
| }
|
| - processPubSubRequest(c, rw, r, func(c context.Context, srv authService, serviceURL string) (*service.Notification, error) {
|
| + processPubSubRequest(ctx, func(c context.Context, srv authService, serviceURL string) (*service.Notification, error) {
|
| return srv.PullPubSub(c, subscriptionName(c, serviceURL))
|
| })
|
| }
|
| @@ -96,9 +96,9 @@ func pubSubPull(c context.Context, rw http.ResponseWriter, r *http.Request, p ht
|
| //
|
| // It uses the signature inside PubSub message body for authentication. Skips
|
| // messages not signed by currently configured auth service.
|
| -func pubSubPush(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
| - processPubSubRequest(c, rw, r, func(c context.Context, srv authService, serviceURL string) (*service.Notification, error) {
|
| - body, err := ioutil.ReadAll(r.Body)
|
| +func pubSubPush(ctx *router.Context) {
|
| + processPubSubRequest(ctx, func(c context.Context, srv authService, serviceURL string) (*service.Notification, error) {
|
| + body, err := ioutil.ReadAll(ctx.Request.Body)
|
| if err != nil {
|
| return nil, err
|
| }
|
| @@ -113,30 +113,32 @@ type notifcationGetter func(context.Context, authService, string) (*service.Noti
|
| // It implements most logic of notification handling. Calls supplied callback
|
| // to actually get service.Notification, since this part is different from Pull
|
| // and Push subscriptions.
|
| -func processPubSubRequest(c context.Context, rw http.ResponseWriter, r *http.Request, callback notifcationGetter) {
|
| - c = defaultNS(c)
|
| - c = authenticatePubSub(c)
|
| - info, err := GetLatestSnapshotInfo(c)
|
| +func processPubSubRequest(c *router.Context, callback notifcationGetter) {
|
| + c.Context = defaultNS(c.Context)
|
| + c.Context = authenticatePubSub(c.Context)
|
| + info, err := GetLatestSnapshotInfo(c.Context)
|
| if err != nil {
|
| - replyError(c, rw, err)
|
| + replyError(c.Context, c.Writer, err)
|
| + c.Abort()
|
| return
|
| }
|
| if info == nil {
|
| // Return HTTP 200 to avoid a redelivery.
|
| - replyOK(c, rw, "Auth Service URL is not configured, skipping the message")
|
| + replyOK(c.Context, c.Writer, "Auth Service URL is not configured, skipping the message")
|
| return
|
| }
|
| - srv := getAuthService(c, info.AuthServiceURL)
|
| + srv := getAuthService(c.Context, info.AuthServiceURL)
|
|
|
| - notify, err := callback(c, srv, info.AuthServiceURL)
|
| + notify, err := callback(c.Context, srv, info.AuthServiceURL)
|
| if err != nil {
|
| - replyError(c, rw, err)
|
| + replyError(c.Context, c.Writer, err)
|
| + c.Abort()
|
| return
|
| }
|
|
|
| // notify may be nil if PubSub messages didn't pass authentication.
|
| if notify == nil {
|
| - replyOK(c, rw, "No new valid AuthDB change notifications")
|
| + replyOK(c.Context, c.Writer, "No new valid AuthDB change notifications")
|
| return
|
| }
|
|
|
| @@ -144,19 +146,21 @@ func processPubSubRequest(c context.Context, rw http.ResponseWriter, r *http.Req
|
| latest := info
|
| if notify.Revision > info.Rev {
|
| var err error
|
| - if latest, err = syncAuthDB(c); err != nil {
|
| - replyError(c, rw, err)
|
| + if latest, err = syncAuthDB(c.Context); err != nil {
|
| + replyError(c.Context, c.Writer, err)
|
| + c.Abort()
|
| return
|
| }
|
| }
|
|
|
| - if err := notify.Acknowledge(c); err != nil {
|
| - replyError(c, rw, err)
|
| + if err := notify.Acknowledge(c.Context); err != nil {
|
| + replyError(c.Context, c.Writer, err)
|
| + c.Abort()
|
| return
|
| }
|
|
|
| replyOK(
|
| - c, rw, "Processed PubSub notification for rev %d: %d -> %d",
|
| + c.Context, c.Writer, "Processed PubSub notification for rev %d: %d -> %d",
|
| notify.Revision, info.Rev, latest.Rev)
|
| }
|
|
|
|
|