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

Unified Diff: appengine/gaeauth/server/internal/authdb/handlers.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd 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
« no previous file with comments | « appengine/gaeauth/server/default.go ('k') | appengine/gaeauth/server/internal/authdb/handlers_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7867f7388b981dd9d609b745f0b59e171f6c0b13 100644
--- a/appengine/gaeauth/server/internal/authdb/handlers.go
+++ b/appengine/gaeauth/server/internal/authdb/handlers.go
@@ -3,44 +3,43 @@
// that can be found in the LICENSE file.
package authdb
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
"google.golang.org/appengine"
"github.com/luci/gae/service/info"
"github.com/luci/luci-go/appengine/gaeauth/client"
"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 (
pubSubPullURLPath = "/auth/pubsub/authdb:pull" // dev server only
pubSubPushURLPath = "/auth/pubsub/authdb:push"
)
// InstallHandlers installs PubSub related HTTP handlers.
-func InstallHandlers(r *httprouter.Router, base middleware.Base) {
+func InstallHandlers(r *router.Router, base router.MiddlewareChain) {
if appengine.IsDevAppServer() {
- r.GET(pubSubPullURLPath, base(pubSubPull))
+ r.GET(pubSubPullURLPath, base, pubSubPull)
}
- r.POST(pubSubPushURLPath, base(pubSubPush))
+ r.POST(pubSubPushURLPath, base, pubSubPush)
}
// authenticatePubSub injects into a context a transport that authenticates
// calls with OAuth2 token with PubSub API scope needed for PubSub API calls.
func authenticatePubSub(c context.Context) context.Context {
scopes := []string{
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/pubsub",
}
return client.UseServiceAccountTransport(c, scopes, nil)
@@ -75,41 +74,41 @@ func subscriptionName(c context.Context, authServiceURL string) string {
panic(err)
}
return fmt.Sprintf("projects/%s/subscriptions/%s+%s", gaeInfo.AppID(), subIDPrefix, serviceURL.Host)
}
// pubSubPull is HTTP handler that pulls PubSub messages from AuthDB change
// notification topic.
//
// 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(c *router.Context) {
if !appengine.IsDevAppServer() {
- replyError(c, rw, errors.New("not a dev server"))
+ replyError(c.Context, c.Writer, errors.New("not a dev server"))
return
}
- processPubSubRequest(c, rw, r, func(c context.Context, srv authService, serviceURL string) (*service.Notification, error) {
+ processPubSubRequest(c.Context, c.Writer, c.Request, func(c context.Context, srv authService, serviceURL string) (*service.Notification, error) {
return srv.PullPubSub(c, subscriptionName(c, serviceURL))
})
}
// pubSubPush is HTTP handler that processes incoming PubSub push notifications.
//
// 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(c *router.Context) {
+ processPubSubRequest(c.Context, c.Writer, c.Request, func(ctx context.Context, srv authService, serviceURL string) (*service.Notification, error) {
+ body, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
return nil, err
}
- return srv.ProcessPubSubPush(c, body)
+ return srv.ProcessPubSubPush(ctx, body)
})
}
type notifcationGetter func(context.Context, authService, string) (*service.Notification, error)
// processPubSubRequest is common wrapper for pubSubPull and pubSubPush.
//
// 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.
« no previous file with comments | « appengine/gaeauth/server/default.go ('k') | appengine/gaeauth/server/internal/authdb/handlers_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698