go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/main.go (about)

     1  // Copyright 2019 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 internal
    16  
    17  import (
    18  	"go.chromium.org/luci/server"
    19  	"go.chromium.org/luci/server/auth"
    20  	"go.chromium.org/luci/server/gaeemulation"
    21  	"go.chromium.org/luci/server/gerritauth"
    22  	"go.chromium.org/luci/server/limiter"
    23  	"go.chromium.org/luci/server/module"
    24  	"go.chromium.org/luci/server/redisconn"
    25  	"go.chromium.org/luci/server/secrets"
    26  	"go.chromium.org/luci/server/span"
    27  	"go.chromium.org/luci/server/tq"
    28  )
    29  
    30  // Main registers all dependencies and runs a service.
    31  func Main(init func(srv *server.Server) error) {
    32  	MainWithModules([]module.Module{}, init)
    33  }
    34  
    35  // MainWithModules is like Main, but accepts additional modules to register.
    36  func MainWithModules(modules []module.Module, init func(srv *server.Server) error) {
    37  	defaultModules := []module.Module{
    38  		gaeemulation.NewModuleFromFlags(),
    39  		gerritauth.NewModuleFromFlags(),
    40  		limiter.NewModuleFromFlags(),
    41  		redisconn.NewModuleFromFlags(),
    42  		secrets.NewModuleFromFlags(),
    43  		span.NewModuleFromFlags(nil),
    44  		tq.NewModuleFromFlags(),
    45  	}
    46  	modules = append(modules, defaultModules...)
    47  	server.Main(nil, modules, func(srv *server.Server) error {
    48  		srv.SetRPCAuthMethods([]auth.Method{
    49  			// The default method used by majority of clients.
    50  			&auth.GoogleOAuth2Method{
    51  				Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"},
    52  			},
    53  			// For authenticating calls from Gerrit plugins.
    54  			&gerritauth.Method,
    55  		})
    56  		return init(srv)
    57  	})
    58  }