Chore: Remove bus.Dispatch from provisioning services (#44989)
* make getordbyname a method * remove one dispatch from plugins provisioner * remove bus from the plugins provisioner, skip test for now * remove bus from datasource provisioning * resolve tests in notifier provisioning * remove bus from the dashboards provisioning service * fix missing struct field * fix getorgbyid method calls * pass org store into dashboard provisioner * fix test function prototype * fix tests * attempt to fix tests after the rebase * fix integration test * avoid using transaction * remove comments
This commit is contained in:
@@ -4,19 +4,25 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
)
|
||||
|
||||
type Store interface {
|
||||
GetOrgByNameHandler(ctx context.Context, query *models.GetOrgByNameQuery) error
|
||||
GetPluginSettingById(ctx context.Context, query *models.GetPluginSettingByIdQuery) error
|
||||
UpdatePluginSetting(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error
|
||||
}
|
||||
|
||||
// Provision scans a directory for provisioning config files
|
||||
// and provisions the app in those files.
|
||||
func Provision(ctx context.Context, configDirectory string, pluginStore plugins.Store) error {
|
||||
func Provision(ctx context.Context, configDirectory string, store Store, pluginStore plugins.Store) error {
|
||||
logger := log.New("provisioning.plugins")
|
||||
ap := PluginProvisioner{
|
||||
log: logger,
|
||||
cfgProvider: newConfigReader(logger, pluginStore),
|
||||
store: store,
|
||||
}
|
||||
return ap.applyChanges(ctx, configDirectory)
|
||||
}
|
||||
@@ -26,13 +32,14 @@ func Provision(ctx context.Context, configDirectory string, pluginStore plugins.
|
||||
type PluginProvisioner struct {
|
||||
log log.Logger
|
||||
cfgProvider configReader
|
||||
store Store
|
||||
}
|
||||
|
||||
func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) error {
|
||||
for _, app := range cfg.Apps {
|
||||
if app.OrgID == 0 && app.OrgName != "" {
|
||||
getOrgQuery := &models.GetOrgByNameQuery{Name: app.OrgName}
|
||||
if err := bus.Dispatch(ctx, getOrgQuery); err != nil {
|
||||
if err := ap.store.GetOrgByNameHandler(ctx, getOrgQuery); err != nil {
|
||||
return err
|
||||
}
|
||||
app.OrgID = getOrgQuery.Result.Id
|
||||
@@ -41,7 +48,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
||||
}
|
||||
|
||||
query := &models.GetPluginSettingByIdQuery{OrgId: app.OrgID, PluginId: app.PluginID}
|
||||
err := bus.Dispatch(ctx, query)
|
||||
err := ap.store.GetPluginSettingById(ctx, query)
|
||||
if err != nil {
|
||||
if !errors.Is(err, models.ErrPluginSettingNotFound) {
|
||||
return err
|
||||
@@ -60,7 +67,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
||||
SecureJsonData: app.SecureJSONData,
|
||||
PluginVersion: app.PluginVersion,
|
||||
}
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
if err := ap.store.UpdatePluginSetting(ctx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user