From 5571852e2a3fe5faa806c0fc20cc1bad3ec34c08 Mon Sep 17 00:00:00 2001 From: Camden Cheek Date: Thu, 5 Oct 2023 14:36:51 -0500 Subject: [PATCH] Chore: simplify enterprise init in `worker` (#57393) --- cmd/worker/shared/BUILD.bazel | 1 - cmd/worker/shared/main.go | 26 ++++++++------------------ cmd/worker/shared/service.go | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/cmd/worker/shared/BUILD.bazel b/cmd/worker/shared/BUILD.bazel index 695cdd63ebc..8ae0d483136 100644 --- a/cmd/worker/shared/BUILD.bazel +++ b/cmd/worker/shared/BUILD.bazel @@ -57,6 +57,5 @@ go_library( "//internal/symbols", "//lib/errors", "@com_github_prometheus_client_golang//prometheus", - "@com_github_sourcegraph_log//:log", ], ) diff --git a/cmd/worker/shared/main.go b/cmd/worker/shared/main.go index 69e4c8a8038..d00999eb86e 100644 --- a/cmd/worker/shared/main.go +++ b/cmd/worker/shared/main.go @@ -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)) - } - } -} diff --git a/cmd/worker/shared/service.go b/cmd/worker/shared/service.go index 0b8fc44ddb8..d26b4a007cf 100644 --- a/cmd/worker/shared/service.go +++ b/cmd/worker/shared/service.go @@ -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{}