mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:12:02 +00:00
Chore: simplify enterprise init in worker (#57393)
This commit is contained in:
parent
51727a9d73
commit
5571852e2a
@ -57,6 +57,5 @@ go_library(
|
||||
"//internal/symbols",
|
||||
"//lib/errors",
|
||||
"@com_github_prometheus_client_golang//prometheus",
|
||||
"@com_github_sourcegraph_log//:log",
|
||||
],
|
||||
)
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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{}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user