Plugins: Make renderer service load renderer plugin (#77854)

* rendering service loads renderer plugin

* update naming

* tidy

* apply PR feedback

* fix missing feature manager

* fix step

* set plugin
This commit is contained in:
Will Browne
2023-12-14 17:33:29 +01:00
committed by GitHub
parent a7a51bf2d8
commit ce8fd14f1f
15 changed files with 220 additions and 71 deletions
@@ -2,6 +2,7 @@ package discovery
import (
"context"
"slices"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/config"
@@ -53,3 +54,39 @@ func (d *DuplicatePluginValidation) Filter(ctx context.Context, bundles []*plugi
return res, nil
}
// PermittedPluginTypesFilter is a filter step that will filter out any plugins that are not of a permitted type.
type PermittedPluginTypesFilter struct {
permittedTypes []plugins.Type
}
// NewPermittedPluginTypesFilterStep returns a new FindFilterFunc for filtering out any plugins that are not of a
// permitted type. This includes both the primary plugin and any child plugins.
func NewPermittedPluginTypesFilterStep(permittedTypes []plugins.Type) FindFilterFunc {
f := &PermittedPluginTypesFilter{
permittedTypes: permittedTypes,
}
return f.Filter
}
// Filter will filter out any plugins that are not of a permitted type.
func (n *PermittedPluginTypesFilter) Filter(_ context.Context, _ plugins.Class, bundles []*plugins.FoundBundle) ([]*plugins.FoundBundle, error) {
var r []*plugins.FoundBundle
for _, b := range bundles {
if !slices.Contains(n.permittedTypes, b.Primary.JSONData.Type) {
continue
}
prohibitedType := false
for _, child := range b.Children {
if !slices.Contains(n.permittedTypes, child.JSONData.Type) {
prohibitedType = true
break
}
}
if !prohibitedType {
r = append(r, b)
}
}
return r, nil
}