go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/appengine/cmd/coordinator/services/main.go (about)

     1  // Copyright 2015 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
    16  
    17  import (
    18  	"net/http"
    19  
    20  	"google.golang.org/appengine"
    21  
    22  	gaeserver "go.chromium.org/luci/appengine/gaeauth/server"
    23  	"go.chromium.org/luci/appengine/gaemiddleware/standard"
    24  	"go.chromium.org/luci/grpc/grpcmon"
    25  	"go.chromium.org/luci/grpc/grpcutil"
    26  	"go.chromium.org/luci/grpc/prpc"
    27  
    28  	registrationPb "go.chromium.org/luci/logdog/api/endpoints/coordinator/registration/v1"
    29  	servicesPb "go.chromium.org/luci/logdog/api/endpoints/coordinator/services/v1"
    30  	"go.chromium.org/luci/logdog/appengine/coordinator/endpoints/registration"
    31  	"go.chromium.org/luci/logdog/appengine/coordinator/endpoints/services"
    32  	"go.chromium.org/luci/logdog/server/config"
    33  	"go.chromium.org/luci/server/auth"
    34  	"go.chromium.org/luci/server/router"
    35  )
    36  
    37  // Run installs and executes this site.
    38  func main() {
    39  	// Disable cookie-based authentication for this service.
    40  	// It should not be used as all RPCs served by this instance are
    41  	// made by Logdog backend. Moreover, the default implementation retains
    42  	// user email addresses in datastore indefinitely which is not acceptable
    43  	// for privacy reasons.
    44  	gaeserver.DisableCookieAuth()
    45  
    46  	r := router.New()
    47  
    48  	// Setup Cloud Endpoints.
    49  	svr := prpc.Server{
    50  		UnaryServerInterceptor: grpcutil.ChainUnaryServerInterceptors(
    51  			grpcmon.UnaryServerInterceptor,
    52  			auth.AuthenticatingInterceptor([]auth.Method{
    53  				&gaeserver.OAuth2Method{Scopes: []string{gaeserver.EmailScope}},
    54  			}).Unary(),
    55  		),
    56  	}
    57  	servicesPb.RegisterServicesServer(&svr, services.New(services.ServerSettings{
    58  		NumQueues: 10,
    59  	}))
    60  	registrationPb.RegisterRegistrationServer(&svr, registration.New())
    61  
    62  	// Standard HTTP endpoints.
    63  	base := standard.Base().Extend(config.Middleware(&config.Store{}))
    64  	svr.InstallHandlers(r, base)
    65  	standard.InstallHandlers(r)
    66  
    67  	http.Handle("/", r)
    68  	appengine.Main()
    69  }