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