| OLD | NEW |
| 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 module | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 | 9 |
| 10 // Importing pprof implicitly installs "/debug/*" profiling handlers. | 10 // Importing pprof implicitly installs "/debug/*" profiling handlers. |
| 11 _ "net/http/pprof" | 11 _ "net/http/pprof" |
| 12 | 12 |
| 13 "github.com/luci/luci-go/appengine/gaemiddleware" | 13 "github.com/luci/luci-go/appengine/gaemiddleware" |
| 14 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
| 15 "github.com/luci/luci-go/grpc/discovery" | 15 "github.com/luci/luci-go/grpc/discovery" |
| 16 "github.com/luci/luci-go/grpc/prpc" | 16 "github.com/luci/luci-go/grpc/prpc" |
| 17 adminPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator/admin/
v1" | 17 adminPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator/admin/
v1" |
| 18 logsPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1
" | 18 logsPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1
" |
| 19 registrationPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator
/registration/v1" | 19 registrationPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator
/registration/v1" |
| 20 servicesPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator/ser
vices/v1" | 20 servicesPb "github.com/luci/luci-go/logdog/api/endpoints/coordinator/ser
vices/v1" |
| 21 "github.com/luci/luci-go/logdog/appengine/coordinator" | 21 "github.com/luci/luci-go/logdog/appengine/coordinator" |
| 22 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | 22 "github.com/luci/luci-go/logdog/appengine/coordinator/config" |
| 23 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/admin" | 23 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/admin" |
| 24 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/logs" | 24 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/logs" |
| 25 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/registra
tion" | 25 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/registra
tion" |
| 26 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/services
" | 26 "github.com/luci/luci-go/logdog/appengine/coordinator/endpoints/services
" |
| 27 "github.com/luci/luci-go/server/router" | 27 "github.com/luci/luci-go/server/router" |
| 28 | 28 |
| 29 "golang.org/x/net/context" | 29 "golang.org/x/net/context" |
| 30 "google.golang.org/appengine" |
| 30 | 31 |
| 31 // Include mutations package so its Mutations will register with tumble
via | 32 // Include mutations package so its Mutations will register with tumble
via |
| 32 // init(). | 33 // init(). |
| 33 _ "github.com/luci/luci-go/logdog/appengine/coordinator/mutations" | 34 _ "github.com/luci/luci-go/logdog/appengine/coordinator/mutations" |
| 34 ) | 35 ) |
| 35 | 36 |
| 36 // Run installs and executes this site. | 37 // Run installs and executes this site. |
| 37 func init() { | 38 func main() { |
| 38 r := router.New() | 39 r := router.New() |
| 39 | 40 |
| 40 // Setup Cloud Endpoints. | 41 // Setup Cloud Endpoints. |
| 41 svr := prpc.Server{ | 42 svr := prpc.Server{ |
| 42 AccessControl: accessControl, | 43 AccessControl: accessControl, |
| 43 } | 44 } |
| 44 adminPb.RegisterAdminServer(&svr, admin.New()) | 45 adminPb.RegisterAdminServer(&svr, admin.New()) |
| 45 servicesPb.RegisterServicesServer(&svr, services.New()) | 46 servicesPb.RegisterServicesServer(&svr, services.New()) |
| 46 registrationPb.RegisterRegistrationServer(&svr, registration.New()) | 47 registrationPb.RegisterRegistrationServer(&svr, registration.New()) |
| 47 logsPb.RegisterLogsServer(&svr, logs.New()) | 48 logsPb.RegisterLogsServer(&svr, logs.New()) |
| 48 discovery.Enable(&svr) | 49 discovery.Enable(&svr) |
| 49 | 50 |
| 50 // Standard HTTP endpoints. | 51 // Standard HTTP endpoints. |
| 51 base := gaemiddleware.BaseProd().Extend(coordinator.ProdCoordinatorServi
ce) | 52 base := gaemiddleware.BaseProd().Extend(coordinator.ProdCoordinatorServi
ce) |
| 52 gaemiddleware.InstallHandlers(r, base) | 53 gaemiddleware.InstallHandlers(r, base) |
| 53 svr.InstallHandlers(r, base) | 54 svr.InstallHandlers(r, base) |
| 54 | 55 |
| 55 // Redirect "/" to "/app/". | 56 // Redirect "/" to "/app/". |
| 56 r.GET("/", router.MiddlewareChain{}, func(c *router.Context) { | 57 r.GET("/", router.MiddlewareChain{}, func(c *router.Context) { |
| 57 http.Redirect(c.Writer, c.Request, "/app/", http.StatusFound) | 58 http.Redirect(c.Writer, c.Request, "/app/", http.StatusFound) |
| 58 }) | 59 }) |
| 59 | 60 |
| 60 http.Handle("/", r) | 61 http.Handle("/", r) |
| 62 appengine.Main() |
| 61 } | 63 } |
| 62 | 64 |
| 63 func accessControl(c context.Context, origin string) bool { | 65 func accessControl(c context.Context, origin string) bool { |
| 64 cfg, err := config.Load(c) | 66 cfg, err := config.Load(c) |
| 65 if err != nil { | 67 if err != nil { |
| 66 log.WithError(err).Errorf(c, "Failed to get config for access co
ntrol check.") | 68 log.WithError(err).Errorf(c, "Failed to get config for access co
ntrol check.") |
| 67 return false | 69 return false |
| 68 } | 70 } |
| 69 | 71 |
| 70 ccfg := cfg.GetCoordinator() | 72 ccfg := cfg.GetCoordinator() |
| 71 if ccfg == nil { | 73 if ccfg == nil { |
| 72 return false | 74 return false |
| 73 } | 75 } |
| 74 | 76 |
| 75 for _, o := range ccfg.RpcAllowOrigins { | 77 for _, o := range ccfg.RpcAllowOrigins { |
| 76 if o == origin { | 78 if o == origin { |
| 77 return true | 79 return true |
| 78 } | 80 } |
| 79 } | 81 } |
| 80 return false | 82 return false |
| 81 } | 83 } |
| OLD | NEW |