mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
76abbef32d
* chore: refactor SecretMigrationProviderImpl as a dskit service
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package registry
|
|
|
|
import (
|
|
"github.com/grafana/dskit/services"
|
|
"github.com/grafana/grafana-apiserver/pkg/certgenerator"
|
|
|
|
"github.com/grafana/grafana/pkg/api"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/modules"
|
|
"github.com/grafana/grafana/pkg/server/backgroundsvcs"
|
|
grafanaapiserver "github.com/grafana/grafana/pkg/services/grafana-apiserver"
|
|
"github.com/grafana/grafana/pkg/services/provisioning"
|
|
"github.com/grafana/grafana/pkg/services/secrets/kvstore/migrations"
|
|
)
|
|
|
|
type Registry interface{}
|
|
|
|
type registry struct {
|
|
moduleManager modules.Manager
|
|
log log.Logger
|
|
}
|
|
|
|
func ProvideRegistry(
|
|
moduleManager modules.Manager,
|
|
apiServer grafanaapiserver.Service,
|
|
backgroundServiceRunner *backgroundsvcs.BackgroundServiceRunner,
|
|
certGenerator certgenerator.ServiceInterface,
|
|
httpServer *api.HTTPServer,
|
|
provisioningService *provisioning.ProvisioningServiceImpl,
|
|
secretsMigrator *migrations.SecretMigrationProviderImpl,
|
|
) *registry {
|
|
return newRegistry(
|
|
log.New("modules.registry"),
|
|
moduleManager,
|
|
apiServer,
|
|
backgroundServiceRunner,
|
|
certGenerator,
|
|
httpServer,
|
|
provisioningService,
|
|
secretsMigrator,
|
|
)
|
|
}
|
|
|
|
func newRegistry(logger log.Logger, moduleManager modules.Manager, svcs ...services.NamedService) *registry {
|
|
r := ®istry{
|
|
log: logger,
|
|
moduleManager: moduleManager,
|
|
}
|
|
|
|
// Register (invisible) modules which act solely as dependencies to module targets
|
|
for _, svc := range svcs {
|
|
s := svc
|
|
logger.Debug("Registering invisible module", "name", s.ServiceName())
|
|
r.moduleManager.RegisterInvisibleModule(s.ServiceName(), func() (services.Service, error) {
|
|
return s, nil
|
|
})
|
|
}
|
|
|
|
logger.Debug("Registering module", "name", modules.All)
|
|
r.moduleManager.RegisterModule(modules.All, nil)
|
|
|
|
return r
|
|
}
|