mirror of https://github.com/grafana/grafana.git
Plugins: Identify plugin ID when provisioning fails for any reason (#111543)
This commit is contained in:
parent
a98870f8f9
commit
6c8ca56651
|
@ -3,6 +3,7 @@ package plugins
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
|
@ -10,6 +11,11 @@ import (
|
|||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPluginProvisioningNotFound = errors.New("plugin not found")
|
||||
ErrPluginProvisioningAutoEnabled = errors.New("plugin is auto enabled and cannot be disabled")
|
||||
)
|
||||
|
||||
// Provision scans a directory for provisioning config files
|
||||
// and provisions the app in those files.
|
||||
func Provision(ctx context.Context, configDirectory string, pluginStore pluginstore.Store, pluginSettings pluginsettings.Service, orgService org.Service) error {
|
||||
|
@ -49,10 +55,10 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
|||
|
||||
p, found := ap.pluginStore.Plugin(ctx, app.PluginID)
|
||||
if !found {
|
||||
return errors.New("plugin not found")
|
||||
return fmt.Errorf("%w: %s", ErrPluginProvisioningNotFound, app.PluginID)
|
||||
}
|
||||
if p.AutoEnabled && !app.Enabled {
|
||||
return errors.New("plugin is auto enabled and cannot be disabled")
|
||||
return fmt.Errorf("%w: %s", ErrPluginProvisioningAutoEnabled, app.PluginID)
|
||||
}
|
||||
|
||||
ps, err := ap.pluginSettings.GetPluginSettingByPluginID(ctx, &pluginsettings.GetByPluginIDArgs{
|
||||
|
@ -61,7 +67,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
|||
})
|
||||
if err != nil {
|
||||
if !errors.Is(err, pluginsettings.ErrPluginSettingNotFound) {
|
||||
return err
|
||||
return fmt.Errorf("%w: %s", err, app.PluginID)
|
||||
}
|
||||
} else {
|
||||
app.PluginVersion = ps.PluginVersion
|
||||
|
@ -77,7 +83,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
|||
SecureJSONData: app.SecureJSONData,
|
||||
PluginVersion: app.PluginVersion,
|
||||
}); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("%w: %s", err, app.PluginID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,8 +100,28 @@ func TestPluginProvisioner(t *testing.T) {
|
|||
}
|
||||
|
||||
err := ap.applyChanges(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "plugin is auto enabled and cannot be disabled")
|
||||
require.ErrorIs(t, err, ErrPluginProvisioningAutoEnabled)
|
||||
})
|
||||
|
||||
t.Run("Should return error trying to configure a non-existing plugin", func(t *testing.T) {
|
||||
cfg := []*pluginsAsConfig{
|
||||
{
|
||||
Apps: []*appFromConfig{
|
||||
{PluginID: "test-plugin", OrgID: 2, Enabled: false},
|
||||
},
|
||||
},
|
||||
}
|
||||
reader := &testConfigReader{result: cfg}
|
||||
store := &mockStore{}
|
||||
ap := PluginProvisioner{
|
||||
log: log.New("test"),
|
||||
cfgProvider: reader,
|
||||
pluginSettings: store,
|
||||
pluginStore: pluginstore.NewFakePluginStore(),
|
||||
}
|
||||
|
||||
err := ap.applyChanges(context.Background(), "")
|
||||
require.ErrorIs(t, err, ErrPluginProvisioningNotFound)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue