Chore: simplify enterprise init in worker (#57393)

This commit is contained in:
Camden Cheek 2023-10-05 14:36:51 -05:00 committed by GitHub
parent 51727a9d73
commit 5571852e2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 20 deletions

View File

@ -57,6 +57,5 @@ go_library(
"//internal/symbols",
"//lib/errors",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_sourcegraph_log//:log",
],
)

View File

@ -10,7 +10,6 @@ import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/cmd/frontend/globals"
"github.com/sourcegraph/sourcegraph/cmd/worker/internal/auth"
@ -149,18 +148,19 @@ func LoadConfig(registerEnterpriseMigrators oobmigration.RegisterMigratorsFunc)
}
// Start runs the worker.
func Start(ctx context.Context, observationCtx *observation.Context, ready service.ReadyFunc, config *Config, enterpriseInit EnterpriseInit) error {
func Start(ctx context.Context, observationCtx *observation.Context, ready service.ReadyFunc, config *Config) error {
if err := keyring.Init(ctx); err != nil {
return errors.Wrap(err, "initializing keyring")
}
if enterpriseInit != nil {
db, err := workerdb.InitDB(observationCtx)
if err != nil {
return errors.Wrap(err, "Failed to create database connection")
}
db, err := workerdb.InitDB(observationCtx)
if err != nil {
return errors.Wrap(err, "failed to create database connection")
}
enterpriseInit(db)
authz.DefaultSubRepoPermsChecker, err = srp.NewSubRepoPermsClient(db.SubRepoPerms())
if err != nil {
return errors.Wrap(err, "failed to create sub-repo client")
}
// Emit metrics to help site admins detect instances that accidentally
@ -399,13 +399,3 @@ func setAuthzProviders(ctx context.Context, observationCtx *observation.Context)
authz.SetProviders(allowAccessByDefault, authzProviders)
}
}
func getEnterpriseInit(logger log.Logger) func(database.DB) {
return func(db database.DB) {
var err error
authz.DefaultSubRepoPermsChecker, err = srp.NewSubRepoPermsClient(db.SubRepoPerms())
if err != nil {
logger.Fatal("Failed to create sub-repo client", log.Error(err))
}
}
}

View File

@ -26,7 +26,7 @@ func (svc) Start(ctx context.Context, observationCtx *observation.Context, ready
// so we init the built-in auth provider just in case.
userpasswd.Init()
return Start(ctx, observationCtx, ready, config.(*Config), getEnterpriseInit(observationCtx.Logger))
return Start(ctx, observationCtx, ready, config.(*Config))
}
var Service service.Service = svc{}