go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/tokenserver/appengine/impl/main.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 holds code to initialize the server environment. 16 package impl 17 18 import ( 19 "go.chromium.org/luci/config/server/cfgmodule" 20 "go.chromium.org/luci/config/validation" 21 "go.chromium.org/luci/server" 22 "go.chromium.org/luci/server/auth" 23 "go.chromium.org/luci/server/cron" 24 "go.chromium.org/luci/server/gaeemulation" 25 "go.chromium.org/luci/server/module" 26 "go.chromium.org/luci/server/redisconn" 27 "go.chromium.org/luci/server/tq" 28 29 "go.chromium.org/luci/tokenserver/api/admin/v1" 30 "go.chromium.org/luci/tokenserver/api/minter/v1" 31 32 "go.chromium.org/luci/tokenserver/appengine/impl/services/admin/adminsrv" 33 "go.chromium.org/luci/tokenserver/appengine/impl/services/admin/certauthorities" 34 "go.chromium.org/luci/tokenserver/appengine/impl/services/minter/tokenminter" 35 ) 36 37 // Services carries concrete implementation of all Token Server RPC services. 38 type Services struct { 39 Admin admin.AdminServer 40 Certs admin.CertificateAuthoritiesServer 41 Minter minter.TokenMinterServer 42 } 43 44 // Main initializes and runs the server. 45 func Main(init func(srv *server.Server, services *Services) error) { 46 modules := []module.Module{ 47 cfgmodule.NewModuleFromFlags(), 48 cron.NewModuleFromFlags(), 49 gaeemulation.NewModuleFromFlags(), 50 redisconn.NewModuleFromFlags(), 51 tq.NewModuleFromFlags(), 52 } 53 54 server.Main(nil, modules, func(srv *server.Server) error { 55 signer := auth.GetSigner(srv.Context) 56 57 adminSrv := adminsrv.NewServer(signer) 58 adminSrv.ImportCAConfigsRPC.SetupConfigValidation(&validation.Rules) 59 adminSrv.ImportDelegationConfigsRPC.SetupConfigValidation(&validation.Rules) 60 adminSrv.ImportProjectIdentityConfigsRPC.SetupConfigValidation(&validation.Rules) 61 adminSrv.ImportProjectOwnedAccountsConfigsRPC.SetupConfigValidation(&validation.Rules) 62 63 return init(srv, &Services{ 64 Admin: adminSrv, 65 Certs: certauthorities.NewServer(), 66 Minter: tokenminter.NewServer(signer, srv.Options.Prod), 67 }) 68 }) 69 }