Plugins: Add file store abstraction for handling plugin files (#65432)

* add file store

* fix markdown fetch bug

* add markdown tests

* fix var name
This commit is contained in:
Will Browne
2023-03-29 12:55:55 +02:00
committed by GitHub
parent 562d8dba5d
commit 7bbe255150
13 changed files with 212 additions and 189 deletions
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log"
pluginDashboardsManager "github.com/grafana/grafana/pkg/plugins/manager/dashboards"
"github.com/grafana/grafana/pkg/services/dashboards"
@@ -115,13 +116,7 @@ func (s Service) LoadPluginDashboard(ctx context.Context, req *plugindashboards.
return nil, err
}
defer func() {
if err = resp.Content.Close(); err != nil {
s.logger.Warn("Failed to close plugin dashboard file", "reference", req.Reference, "err", err)
}
}()
data, err := simplejson.NewFromReader(resp.Content)
data, err := simplejson.NewJson(resp.Content)
if err != nil {
return nil, err
}
@@ -1,10 +1,8 @@
package service
import (
"bytes"
"context"
"fmt"
"io"
"sort"
"testing"
@@ -193,7 +191,7 @@ func (m pluginDashboardStoreMock) GetPluginDashboardFileContents(ctx context.Con
if dashboardFiles, exists := m.pluginDashboardFiles[args.PluginID]; exists {
if content, exists := dashboardFiles[args.FileReference]; exists {
return &dashboards.GetPluginDashboardFileContentsResult{
Content: io.NopCloser(bytes.NewReader(content)),
Content: content,
}, nil
}
} else if !exists {
@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/manager"
"github.com/grafana/grafana/pkg/plugins/manager/client"
"github.com/grafana/grafana/pkg/plugins/manager/filestore"
"github.com/grafana/grafana/pkg/plugins/manager/loader"
"github.com/grafana/grafana/pkg/plugins/manager/loader/assetpath"
"github.com/grafana/grafana/pkg/plugins/manager/loader/finder"
@@ -60,6 +61,8 @@ var WireSet = wire.NewSet(
sources.ProvideService,
pluginSettings.ProvideService,
wire.Bind(new(pluginsettings.Service), new(*pluginSettings.Service)),
filestore.ProvideService,
wire.Bind(new(plugins.FileStore), new(*filestore.Service)),
)
// WireExtensionSet provides a wire.ProviderSet of plugin providers that can be