go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gce/appengine/frontend/main.go (about) 1 // Copyright 2018 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package main is the main entry point for the app. 16 package main 17 18 import ( 19 "net/http" 20 21 "google.golang.org/appengine" 22 23 gaeserver "go.chromium.org/luci/appengine/gaeauth/server" 24 "go.chromium.org/luci/appengine/gaemiddleware/standard" 25 "go.chromium.org/luci/grpc/discovery" 26 "go.chromium.org/luci/grpc/grpcmon" 27 "go.chromium.org/luci/grpc/grpcutil" 28 "go.chromium.org/luci/grpc/prpc" 29 "go.chromium.org/luci/server/auth" 30 "go.chromium.org/luci/server/router" 31 "go.chromium.org/luci/web/rpcexplorer" 32 33 server "go.chromium.org/luci/gce/api/config/v1" 34 "go.chromium.org/luci/gce/api/instances/v1" 35 "go.chromium.org/luci/gce/api/projects/v1" 36 "go.chromium.org/luci/gce/appengine/backend" 37 "go.chromium.org/luci/gce/appengine/config" 38 "go.chromium.org/luci/gce/appengine/rpc" 39 "go.chromium.org/luci/gce/vmtoken" 40 ) 41 42 func main() { 43 api := prpc.Server{ 44 UnaryServerInterceptor: grpcutil.ChainUnaryServerInterceptors( 45 grpcmon.UnaryServerInterceptor, 46 auth.AuthenticatingInterceptor([]auth.Method{ 47 &gaeserver.OAuth2Method{Scopes: []string{gaeserver.EmailScope}}, 48 }).Unary(), 49 ), 50 } 51 server.RegisterConfigurationServer(&api, rpc.NewConfigurationServer()) 52 instances.RegisterInstancesServer(&api, rpc.NewInstancesServer()) 53 projects.RegisterProjectsServer(&api, rpc.NewProjectsServer()) 54 discovery.Enable(&api) 55 56 r := router.New() 57 58 standard.InstallHandlers(r) 59 rpcexplorer.Install(r, nil) 60 61 mw := standard.Base() 62 api.InstallHandlers(r, mw.Extend(vmtoken.Middleware)) 63 backend.InstallHandlers(r, mw) 64 config.InstallHandlers(r, mw) 65 66 http.DefaultServeMux.Handle("/", r) 67 appengine.Main() 68 }