go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/auth_service/impl/service.go (about)

     1  // Copyright 2021 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 impl contains code shared by `frontend` and `backend` services.
    16  package impl
    17  
    18  import (
    19  	"go.chromium.org/luci/config/server/cfgmodule"
    20  	"go.chromium.org/luci/server"
    21  	"go.chromium.org/luci/server/gaeemulation"
    22  	"go.chromium.org/luci/server/module"
    23  	"go.chromium.org/luci/server/secrets"
    24  	"go.chromium.org/luci/server/tq"
    25  
    26  	"go.chromium.org/luci/auth_service/impl/info"
    27  )
    28  
    29  // Main launches a server with some default modules and configuration installed.
    30  func Main(modules []module.Module, cb func(srv *server.Server) error) {
    31  	authDBProvider := &AuthDBProvider{}
    32  
    33  	opts := &server.Options{
    34  		// Use the AuthDB built directly from the datastore entities.
    35  		AuthDBProvider: authDBProvider.GetAuthDB,
    36  	}
    37  
    38  	modules = append([]module.Module{
    39  		gaeemulation.NewModuleFromFlags(), // for accessing Datastore
    40  		secrets.NewModuleFromFlags(),      // for accessing Cloud Secret Manager
    41  		tq.NewModuleFromFlags(),
    42  		cfgmodule.NewModuleFromFlags(), // for accessing luci-cfg configs.
    43  	}, modules...)
    44  
    45  	server.Main(opts, modules, func(srv *server.Server) error {
    46  		// Inject app version into the root context so request handlers can use it.
    47  		srv.Context = info.SetImageVersion(srv.Context, srv.Options.ImageVersion())
    48  
    49  		srv.RunInBackground("authdb", authDBProvider.RefreshPeriodically)
    50  		return cb(srv)
    51  	})
    52  }