Plugins: Update renderer plugin source (#80643)

* rework renderer plugin source

* add tests
This commit is contained in:
Will Browne
2024-01-18 11:06:33 +01:00
committed by GitHub
parent 4b113f87f9
commit 3885497553
10 changed files with 233 additions and 41 deletions

View File

@ -2,9 +2,7 @@ package sources
import (
"context"
"os"
"path/filepath"
"slices"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
@ -34,33 +32,17 @@ func (s *Service) List(_ context.Context) []plugins.PluginSource {
}
func (s *Service) externalPluginSources() []plugins.PluginSource {
var sources []plugins.PluginSource
if s.cfg.PluginsPath == "" {
return sources
}
pluginsPath := s.cfg.PluginsPath
// It's safe to ignore gosec warning G304 since the variable part of the file path comes from a configuration
// variable.
// nolint:gosec
d, err := os.ReadDir(pluginsPath)
localSrcs, err := DirAsLocalSources(s.cfg.PluginsPath, plugins.ClassExternal)
if err != nil {
s.log.Error("Failed to open plugins path", "path", pluginsPath, "error", err)
return sources
s.log.Error("Failed to load external plugins", "error", err)
return []plugins.PluginSource{}
}
var pluginDirs []string
for _, dir := range d {
if dir.IsDir() || dir.Type()&os.ModeSymlink == os.ModeSymlink {
pluginDirs = append(pluginDirs, filepath.Join(pluginsPath, dir.Name()))
}
var srcs []plugins.PluginSource
for _, src := range localSrcs {
srcs = append(srcs, src)
}
slices.Sort(pluginDirs)
for _, dir := range pluginDirs {
sources = append(sources, NewLocalSource(plugins.ClassExternal, []string{dir}))
}
return sources
return srcs
}
func (s *Service) pluginSettingSources() []plugins.PluginSource {