Files
grafana/pkg/plugins/manager/loader/finder/finder.go
Will Browne 68df83c86d Plugins: Add Plugin FS abstraction (#63734)
* unexport pluginDir from dto

* first pass

* tidy

* naming + add mutex

* add dupe checking

* fix func typo

* interface + move logic from renderer

* remote finder

* remote signing

* fix tests

* tidy up

* tidy markdown logic

* split changes

* fix tests

* slim interface down

* fix status code

* tidy exec path func

* fixup

* undo changes

* remove unused func

* remove unused func

* fix goimports

* fetch remotely

* simultaneous support

* fix linter

* use var

* add exception for gosec warning

* fixup

* fix tests

* tidy

* rework cfg pattern

* simplify

* PR feedback

* fix dupe field

* remove g304 nolint

* apply PR feedback

* remove unnecessary gosec nolint

* fix finder loop and update comment

* fix map alloc

* fix test

* remove commented code
2023-03-07 16:47:02 +01:00

45 lines
855 B
Go

package finder
import (
"context"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
)
type Service struct {
local *FS
log log.Logger
}
func NewService() *Service {
logger := log.New("plugin.finder")
return &Service{
local: newFS(logger),
log: logger,
}
}
func (f *Service) Find(ctx context.Context, pluginPaths ...string) ([]*plugins.FoundBundle, error) {
if len(pluginPaths) == 0 {
return []*plugins.FoundBundle{}, nil
}
fbs := make(map[string][]*plugins.FoundBundle)
for _, path := range pluginPaths {
local, err := f.local.Find(ctx, path)
if err != nil {
f.log.Warn("Error occurred when trying to find plugin", "path", path)
continue
}
fbs[path] = local
}
var found []*plugins.FoundBundle
for _, fb := range fbs {
found = append(found, fb...)
}
return found, nil
}