| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package module | 5 package module |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 | 9 |
| 10 "golang.org/x/net/context" |
| 11 |
| 10 "github.com/julienschmidt/httprouter" | 12 "github.com/julienschmidt/httprouter" |
| 11 gaeauthServer "github.com/luci/luci-go/appengine/gaeauth/server" | |
| 12 "github.com/luci/luci-go/appengine/gaemiddleware" | |
| 13 "github.com/luci/luci-go/appengine/logdog/coordinator" | 13 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 14 "github.com/luci/luci-go/appengine/logdog/coordinator/backend" | |
| 15 "github.com/luci/luci-go/appengine/logdog/coordinator/config" | 14 "github.com/luci/luci-go/appengine/logdog/coordinator/config" |
| 16 "github.com/luci/luci-go/appengine/tumble" | 15 "github.com/luci/luci-go/appengine/tumble" |
| 17 "github.com/luci/luci-go/server/auth" | |
| 18 "github.com/luci/luci-go/server/middleware" | |
| 19 | 16 |
| 20 // Include mutations package so its Mutations will register with tumble
via | 17 // Include mutations package so its Mutations will register with tumble
via |
| 21 // init(). | 18 // init(). |
| 22 _ "github.com/luci/luci-go/appengine/logdog/coordinator/mutations" | 19 _ "github.com/luci/luci-go/appengine/logdog/coordinator/mutations" |
| 23 ) | 20 ) |
| 24 | 21 |
| 25 func authenticator(scopes ...string) auth.Authenticator { | 22 func init() { |
| 26 » return auth.Authenticator{ | 23 » tmb := tumble.Service{ |
| 27 » » &gaeauthServer.OAuth2Method{Scopes: scopes}, | 24 » » Middleware: func(c context.Context) context.Context { |
| 28 » » gaeauthServer.CookieAuth, | 25 » » » c = config.UseConfig(c) |
| 29 » » &gaeauthServer.InboundAppIDAuthMethod{}, | 26 » » » c = coordinator.UseProdServices(c) |
| 27 » » » return c |
| 28 » » }, |
| 30 } | 29 } |
| 31 } | |
| 32 | |
| 33 // base is the root of the middleware chain. | |
| 34 func base(h middleware.Handler) httprouter.Handle { | |
| 35 a := authenticator(gaeauthServer.EmailScope) | |
| 36 h = auth.Use(h, a) | |
| 37 h = config.WithConfig(h) | |
| 38 h = coordinator.WithProdServices(h) | |
| 39 return gaemiddleware.BaseProd(h) | |
| 40 } | |
| 41 | |
| 42 func init() { | |
| 43 b := backend.Backend{} | |
| 44 tmb := tumble.Service{} | |
| 45 | 30 |
| 46 router := httprouter.New() | 31 router := httprouter.New() |
| 47 b.InstallHandlers(router, base) | |
| 48 tmb.InstallHandlers(router) | 32 tmb.InstallHandlers(router) |
| 49 | 33 |
| 50 http.Handle("/", router) | 34 http.Handle("/", router) |
| 51 } | 35 } |
| OLD | NEW |