Plugins: Refactor plugin config into separate env var and request scoped services (#83261)
* seperate services for env + req * merge with main * fix tests * undo changes to golden file * fix linter * remove unused fields * split out new config struct * provide config * undo go mod changes * more renaming * fix tests * undo bra.toml changes * update go.work.sum * undo changes * trigger * apply PR feedback
This commit is contained in:
@@ -29,10 +29,10 @@ var (
|
||||
|
||||
type Service struct {
|
||||
pluginRegistry registry.Service
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
}
|
||||
|
||||
func ProvideService(pluginRegistry registry.Service, cfg *config.Cfg) *Service {
|
||||
func ProvideService(pluginRegistry registry.Service, cfg *config.PluginManagementCfg) *Service {
|
||||
return &Service{
|
||||
pluginRegistry: pluginRegistry,
|
||||
cfg: cfg,
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
func TestQueryData(t *testing.T) {
|
||||
t.Run("Empty registry should return not registered error", func(t *testing.T) {
|
||||
registry := fakes.NewFakePluginRegistry()
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
_, err := client.QueryData(context.Background(), &backend.QueryDataRequest{})
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, plugins.ErrPluginNotRegistered)
|
||||
@@ -63,7 +63,7 @@ func TestQueryData(t *testing.T) {
|
||||
err := registry.Add(context.Background(), p)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
_, err = client.QueryData(context.Background(), &backend.QueryDataRequest{
|
||||
PluginContext: backend.PluginContext{
|
||||
PluginID: "grafana",
|
||||
@@ -79,7 +79,7 @@ func TestQueryData(t *testing.T) {
|
||||
func TestCheckHealth(t *testing.T) {
|
||||
t.Run("empty plugin registry should return plugin not registered error", func(t *testing.T) {
|
||||
registry := fakes.NewFakePluginRegistry()
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
_, err := client.CheckHealth(context.Background(), &backend.CheckHealthRequest{})
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, plugins.ErrPluginNotRegistered)
|
||||
@@ -125,7 +125,7 @@ func TestCheckHealth(t *testing.T) {
|
||||
err := registry.Add(context.Background(), p)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
_, err = client.CheckHealth(context.Background(), &backend.CheckHealthRequest{
|
||||
PluginContext: backend.PluginContext{
|
||||
PluginID: "grafana",
|
||||
@@ -189,7 +189,7 @@ func TestCallResource(t *testing.T) {
|
||||
err := registry.Add(context.Background(), p)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
|
||||
err = client.CallResource(context.Background(), req, sender)
|
||||
require.NoError(t, err)
|
||||
@@ -252,7 +252,7 @@ func TestCallResource(t *testing.T) {
|
||||
err := registry.Add(context.Background(), p)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
|
||||
err = client.CallResource(context.Background(), req, sender)
|
||||
require.NoError(t, err)
|
||||
@@ -298,7 +298,7 @@ func TestCallResource(t *testing.T) {
|
||||
err := registry.Add(context.Background(), p)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
|
||||
err = client.CallResource(context.Background(), req, sender)
|
||||
require.NoError(t, err)
|
||||
@@ -366,7 +366,7 @@ func TestCallResource(t *testing.T) {
|
||||
err := registry.Add(context.Background(), p)
|
||||
require.NoError(t, err)
|
||||
|
||||
client := ProvideService(registry, &config.Cfg{})
|
||||
client := ProvideService(registry, &config.PluginManagementCfg{})
|
||||
|
||||
err = client.CallResource(context.Background(), req, sender)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -255,6 +255,21 @@ func (s *FakePluginStorage) Extract(ctx context.Context, pluginID string, dirNam
|
||||
return &storage.ExtractedPluginArchive{}, nil
|
||||
}
|
||||
|
||||
type FakePluginEnvProvider struct {
|
||||
PluginEnvVarsFunc func(ctx context.Context, plugin *plugins.Plugin) []string
|
||||
}
|
||||
|
||||
func NewFakePluginEnvProvider() *FakePluginEnvProvider {
|
||||
return &FakePluginEnvProvider{}
|
||||
}
|
||||
|
||||
func (p *FakePluginEnvProvider) PluginEnvVars(ctx context.Context, plugin *plugins.Plugin) []string {
|
||||
if p.PluginEnvVarsFunc != nil {
|
||||
return p.PluginEnvVarsFunc(ctx, plugin)
|
||||
}
|
||||
return []string{}
|
||||
}
|
||||
|
||||
type FakeProcessManager struct {
|
||||
StartFunc func(_ context.Context, p *plugins.Plugin) error
|
||||
StopFunc func(_ context.Context, p *plugins.Plugin) error
|
||||
|
||||
@@ -28,7 +28,7 @@ type PluginInstaller struct {
|
||||
serviceRegistry auth.ExternalServiceRegistry
|
||||
}
|
||||
|
||||
func ProvideInstaller(cfg *config.Cfg, pluginRegistry registry.Service, pluginLoader loader.Service,
|
||||
func ProvideInstaller(cfg *config.PluginManagementCfg, pluginRegistry registry.Service, pluginLoader loader.Service,
|
||||
pluginRepo repo.Service, serviceRegistry auth.ExternalServiceRegistry) *PluginInstaller {
|
||||
return New(pluginRegistry, pluginLoader, pluginRepo,
|
||||
storage.FileSystem(log.NewPrettyLogger("installer.fs"), cfg.PluginsPath), storage.SimpleDirNameGeneratorFunc, serviceRegistry)
|
||||
|
||||
@@ -18,10 +18,10 @@ import (
|
||||
// on the plugins CDN, and it will switch to the correct implementation depending on the plugin and the config.
|
||||
type Service struct {
|
||||
cdn *pluginscdn.Service
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
}
|
||||
|
||||
func ProvideService(cfg *config.Cfg, cdn *pluginscdn.Service) *Service {
|
||||
func ProvideService(cfg *config.PluginManagementCfg, cdn *pluginscdn.Service) *Service {
|
||||
return &Service{cfg: cfg, cdn: cdn}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func NewPluginInfo(pluginJSON plugins.JSONData, class plugins.Class, fs plugins.
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultService(cfg *config.Cfg) *Service {
|
||||
func DefaultService(cfg *config.PluginManagementCfg) *Service {
|
||||
return &Service{cfg: cfg, cdn: pluginscdn.ProvideService(cfg)}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestService(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
cfg := &config.Cfg{
|
||||
cfg := &config.PluginManagementCfg{
|
||||
PluginsCDNURLTemplate: tc.cdnBaseURL,
|
||||
PluginSettings: map[string]map[string]string{
|
||||
"one": {"cdn": "true"},
|
||||
@@ -142,7 +142,7 @@ func TestService(t *testing.T) {
|
||||
appSubURL: "/grafana/",
|
||||
},
|
||||
} {
|
||||
cfg := &config.Cfg{GrafanaAppSubURL: tc.appSubURL}
|
||||
cfg := &config.PluginManagementCfg{GrafanaAppSubURL: tc.appSubURL}
|
||||
svc := ProvideService(cfg, pluginscdn.ProvideService(cfg))
|
||||
|
||||
dir := "/plugins/test-datasource"
|
||||
|
||||
@@ -37,7 +37,7 @@ func NewLocalFinder(devMode bool, features featuremgmt.FeatureToggles) *Local {
|
||||
}
|
||||
}
|
||||
|
||||
func ProvideLocalFinder(cfg *config.Cfg) *Local {
|
||||
func ProvideLocalFinder(cfg *config.PluginManagementCfg) *Local {
|
||||
return NewLocalFinder(cfg.DevMode, cfg.Features)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,14 +61,14 @@ func TestLoader_Load(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
class plugins.Class
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
pluginPaths []string
|
||||
want []*plugins.Plugin
|
||||
}{
|
||||
{
|
||||
name: "Load a Core plugin",
|
||||
class: plugins.ClassCore,
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{filepath.Join(corePluginDir, "app/plugins/datasource/cloudwatch")},
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
@@ -117,7 +117,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a Bundled plugin",
|
||||
class: plugins.ClassBundled,
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{"../testdata/valid-v2-signature"},
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
@@ -158,7 +158,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load plugin with symbolic links",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{"../testdata/symbolic-plugin-dirs"},
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
@@ -237,7 +237,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load an unsigned plugin (development)",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
cfg: &config.PluginManagementCfg{
|
||||
DevMode: true,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
@@ -277,14 +277,14 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load an unsigned plugin (production)",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{"../testdata/unsigned-datasource"},
|
||||
want: []*plugins.Plugin{},
|
||||
},
|
||||
{
|
||||
name: "Load an unsigned plugin using PluginsAllowUnsigned config (production)",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
cfg: &config.PluginManagementCfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
@@ -324,14 +324,14 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a plugin with v1 manifest should return signatureInvalid",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{Features: featuremgmt.WithFeatures()},
|
||||
cfg: &config.PluginManagementCfg{Features: featuremgmt.WithFeatures()},
|
||||
pluginPaths: []string{"../testdata/lacking-files"},
|
||||
want: []*plugins.Plugin{},
|
||||
},
|
||||
{
|
||||
name: "Load a plugin with v1 manifest using PluginsAllowUnsigned config (production) should return signatureInvali",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
cfg: &config.PluginManagementCfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
@@ -341,7 +341,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a plugin with manifest which has a file not found in plugin folder",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
cfg: &config.PluginManagementCfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
@@ -351,7 +351,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a plugin with file which is missing from the manifest",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
cfg: &config.PluginManagementCfg{
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
@@ -361,7 +361,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load an app with includes",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
cfg: &config.PluginManagementCfg{
|
||||
PluginsAllowUnsigned: []string{"test-app"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
},
|
||||
@@ -413,7 +413,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
{
|
||||
name: "Load a plugin with app sub url set",
|
||||
class: plugins.ClassExternal,
|
||||
cfg: &config.Cfg{
|
||||
cfg: &config.PluginManagementCfg{
|
||||
DevMode: true,
|
||||
GrafanaAppSubURL: "grafana",
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
|
||||
@@ -42,7 +42,7 @@ type Opts struct {
|
||||
}
|
||||
|
||||
// New returns a new Bootstrap stage.
|
||||
func New(cfg *config.Cfg, opts Opts) *Bootstrap {
|
||||
func New(cfg *config.PluginManagementCfg, opts Opts) *Bootstrap {
|
||||
if opts.ConstructFunc == nil {
|
||||
opts.ConstructFunc = DefaultConstructFunc(signature.DefaultCalculator(cfg), assetpath.DefaultService(cfg))
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func DefaultConstructFunc(signatureCalculator plugins.SignatureCalculator, asset
|
||||
}
|
||||
|
||||
// DefaultDecorateFuncs are the default DecorateFuncs used for the Decorate step of the Bootstrap stage.
|
||||
func DefaultDecorateFuncs(cfg *config.Cfg) []DecorateFunc {
|
||||
func DefaultDecorateFuncs(cfg *config.PluginManagementCfg) []DecorateFunc {
|
||||
return []DecorateFunc{
|
||||
AppDefaultNavURLDecorateFunc,
|
||||
TemplateDecorateFunc,
|
||||
@@ -161,7 +161,7 @@ func configureAppChildPlugin(parent *plugins.Plugin, child *plugins.Plugin) {
|
||||
// SkipHostEnvVarsDecorateFunc returns a DecorateFunc that configures the SkipHostEnvVars field of the plugin.
|
||||
// It will be set to true if the FlagPluginsSkipHostEnvVars feature flag is set, and the plugin is not present in the
|
||||
// ForwardHostEnvVars plugin ids list.
|
||||
func SkipHostEnvVarsDecorateFunc(cfg *config.Cfg) DecorateFunc {
|
||||
func SkipHostEnvVarsDecorateFunc(cfg *config.PluginManagementCfg) DecorateFunc {
|
||||
return func(_ context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
|
||||
p.SkipHostEnvVars = cfg.Features.IsEnabledGlobally(featuremgmt.FlagPluginsSkipHostEnvVars) &&
|
||||
!slices.Contains(cfg.ForwardHostEnvVars, p.ID)
|
||||
|
||||
@@ -144,7 +144,7 @@ func TestSkipEnvVarsDecorateFunc(t *testing.T) {
|
||||
const pluginID = "plugin-id"
|
||||
|
||||
t.Run("feature flag is not present", func(t *testing.T) {
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.Cfg{Features: featuremgmt.WithFeatures()})
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.PluginManagementCfg{Features: featuremgmt.WithFeatures()})
|
||||
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
|
||||
require.NoError(t, err)
|
||||
require.False(t, p.SkipHostEnvVars)
|
||||
@@ -152,7 +152,7 @@ func TestSkipEnvVarsDecorateFunc(t *testing.T) {
|
||||
|
||||
t.Run("feature flag is present", func(t *testing.T) {
|
||||
t.Run("no plugin settings should set SkipHostEnvVars to true", func(t *testing.T) {
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.Cfg{
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.PluginManagementCfg{
|
||||
Features: featuremgmt.WithFeatures(featuremgmt.FlagPluginsSkipHostEnvVars),
|
||||
})
|
||||
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
|
||||
@@ -188,7 +188,7 @@ func TestSkipEnvVarsDecorateFunc(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.Cfg{
|
||||
f := SkipHostEnvVarsDecorateFunc(&config.PluginManagementCfg{
|
||||
Features: featuremgmt.WithFeatures(featuremgmt.FlagPluginsSkipHostEnvVars),
|
||||
ForwardHostEnvVars: tc.forwardHostEnvVars,
|
||||
})
|
||||
|
||||
@@ -40,7 +40,7 @@ type Opts struct {
|
||||
}
|
||||
|
||||
// New returns a new Discovery stage.
|
||||
func New(cfg *config.Cfg, opts Opts) *Discovery {
|
||||
func New(cfg *config.PluginManagementCfg, opts Opts) *Discovery {
|
||||
if opts.FindFunc == nil {
|
||||
opts.FindFunc = DefaultFindFunc(cfg)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// DefaultFindFunc is the default function used for the Find step of the Discovery stage. It will scan the local
|
||||
// filesystem for plugins.
|
||||
func DefaultFindFunc(cfg *config.Cfg) FindFunc {
|
||||
func DefaultFindFunc(cfg *config.PluginManagementCfg) FindFunc {
|
||||
return finder.NewLocalFinder(cfg.DevMode, cfg.Features).Find
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ type Initializer interface {
|
||||
type InitializeFunc func(ctx context.Context, p *plugins.Plugin) (*plugins.Plugin, error)
|
||||
|
||||
type Initialize struct {
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
initializeSteps []InitializeFunc
|
||||
log log.Logger
|
||||
}
|
||||
@@ -27,7 +27,7 @@ type Opts struct {
|
||||
}
|
||||
|
||||
// New returns a new Initialization stage.
|
||||
func New(cfg *config.Cfg, opts Opts) *Initialize {
|
||||
func New(cfg *config.PluginManagementCfg, opts Opts) *Initialize {
|
||||
if opts.InitializeFuncs == nil {
|
||||
opts.InitializeFuncs = []InitializeFunc{}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func (b *BackendClientInit) Initialize(ctx context.Context, p *plugins.Plugin) (
|
||||
}
|
||||
|
||||
// this will ensure that the env variables are calculated every time a plugin is started
|
||||
envFunc := func() []string { return b.envVarProvider.Get(ctx, p) }
|
||||
envFunc := func() []string { return b.envVarProvider.PluginEnvVars(ctx, p) }
|
||||
|
||||
if backendClient, err := backendFactory(p.ID, p.Logger(), envFunc); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -121,12 +121,12 @@ func (f *fakeBackendProvider) BackendFactory(_ context.Context, _ *plugins.Plugi
|
||||
}
|
||||
|
||||
type fakeEnvVarsProvider struct {
|
||||
GetFunc func(ctx context.Context, p *plugins.Plugin) []string
|
||||
PluginEnvVarsFunc func(ctx context.Context, p *plugins.Plugin) []string
|
||||
}
|
||||
|
||||
func (f *fakeEnvVarsProvider) Get(ctx context.Context, p *plugins.Plugin) []string {
|
||||
if f.GetFunc != nil {
|
||||
return f.GetFunc(ctx, p)
|
||||
func (f *fakeEnvVarsProvider) PluginEnvVars(ctx context.Context, p *plugins.Plugin) []string {
|
||||
if f.PluginEnvVarsFunc != nil {
|
||||
return f.PluginEnvVars(ctx, p)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ type Terminator interface {
|
||||
type TerminateFunc func(ctx context.Context, p *plugins.Plugin) error
|
||||
|
||||
type Terminate struct {
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
terminateSteps []TerminateFunc
|
||||
log log.Logger
|
||||
}
|
||||
@@ -27,7 +27,7 @@ type Opts struct {
|
||||
}
|
||||
|
||||
// New returns a new Termination stage.
|
||||
func New(cfg *config.Cfg, opts Opts) (*Terminate, error) {
|
||||
func New(cfg *config.PluginManagementCfg, opts Opts) (*Terminate, error) {
|
||||
if opts.TerminateFuncs == nil {
|
||||
opts.TerminateFuncs = []TerminateFunc{}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
// DefaultValidateFuncs are the default ValidateFunc used for the Validate step of the Validation stage.
|
||||
func DefaultValidateFuncs(cfg *config.Cfg) []ValidateFunc {
|
||||
func DefaultValidateFuncs(cfg *config.PluginManagementCfg) []ValidateFunc {
|
||||
return []ValidateFunc{
|
||||
SignatureValidationStep(signature.NewValidator(signature.NewUnsignedAuthorizer(cfg))),
|
||||
ModuleJSValidationStep(),
|
||||
@@ -74,16 +74,16 @@ func (v *ModuleJSValidator) Validate(_ context.Context, p *plugins.Plugin) error
|
||||
}
|
||||
|
||||
type AngularDetector struct {
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
angularInspector angularinspector.Inspector
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func AngularDetectionStep(cfg *config.Cfg, angularInspector angularinspector.Inspector) ValidateFunc {
|
||||
func AngularDetectionStep(cfg *config.PluginManagementCfg, angularInspector angularinspector.Inspector) ValidateFunc {
|
||||
return newAngularDetector(cfg, angularInspector).Validate
|
||||
}
|
||||
|
||||
func newAngularDetector(cfg *config.Cfg, angularInspector angularinspector.Inspector) *AngularDetector {
|
||||
func newAngularDetector(cfg *config.PluginManagementCfg, angularInspector angularinspector.Inspector) *AngularDetector {
|
||||
return &AngularDetector{
|
||||
cfg: cfg,
|
||||
angularInspector: angularInspector,
|
||||
|
||||
@@ -17,7 +17,7 @@ type Validator interface {
|
||||
type ValidateFunc func(ctx context.Context, p *plugins.Plugin) error
|
||||
|
||||
type Validate struct {
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
validateSteps []ValidateFunc
|
||||
log log.Logger
|
||||
}
|
||||
@@ -27,7 +27,7 @@ type Opts struct {
|
||||
}
|
||||
|
||||
// New returns a new Validation stage.
|
||||
func New(cfg *config.Cfg, opts Opts) *Validate {
|
||||
func New(cfg *config.PluginManagementCfg, opts Opts) *Validate {
|
||||
if opts.ValidateFuncs == nil {
|
||||
opts.ValidateFuncs = DefaultValidateFuncs(cfg)
|
||||
}
|
||||
|
||||
@@ -5,18 +5,18 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
)
|
||||
|
||||
func ProvideOSSAuthorizer(cfg *config.Cfg) *UnsignedPluginAuthorizer {
|
||||
func ProvideOSSAuthorizer(cfg *config.PluginManagementCfg) *UnsignedPluginAuthorizer {
|
||||
return NewUnsignedAuthorizer(cfg)
|
||||
}
|
||||
|
||||
func NewUnsignedAuthorizer(cfg *config.Cfg) *UnsignedPluginAuthorizer {
|
||||
func NewUnsignedAuthorizer(cfg *config.PluginManagementCfg) *UnsignedPluginAuthorizer {
|
||||
return &UnsignedPluginAuthorizer{
|
||||
cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
type UnsignedPluginAuthorizer struct {
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
}
|
||||
|
||||
func (u *UnsignedPluginAuthorizer) CanLoadPlugin(p *plugins.Plugin) bool {
|
||||
|
||||
@@ -59,17 +59,17 @@ func (m *PluginManifest) isV2() bool {
|
||||
|
||||
type Signature struct {
|
||||
kr plugins.KeyRetriever
|
||||
cfg *config.Cfg
|
||||
cfg *config.PluginManagementCfg
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
var _ plugins.SignatureCalculator = &Signature{}
|
||||
|
||||
func ProvideService(cfg *config.Cfg, kr plugins.KeyRetriever) *Signature {
|
||||
func ProvideService(cfg *config.PluginManagementCfg, kr plugins.KeyRetriever) *Signature {
|
||||
return NewCalculator(cfg, kr)
|
||||
}
|
||||
|
||||
func NewCalculator(cfg *config.Cfg, kr plugins.KeyRetriever) *Signature {
|
||||
func NewCalculator(cfg *config.PluginManagementCfg, kr plugins.KeyRetriever) *Signature {
|
||||
return &Signature{
|
||||
kr: kr,
|
||||
cfg: cfg,
|
||||
@@ -77,7 +77,7 @@ func NewCalculator(cfg *config.Cfg, kr plugins.KeyRetriever) *Signature {
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultCalculator(cfg *config.Cfg) *Signature {
|
||||
func DefaultCalculator(cfg *config.PluginManagementCfg) *Signature {
|
||||
return &Signature{
|
||||
kr: statickey.New(),
|
||||
cfg: cfg,
|
||||
|
||||
@@ -52,7 +52,7 @@ NR7DnB0CCQHO+4FlSPtXFTzNepoc+CytQyDAeOLMLmf2Tqhk2YShk+G/YlVX
|
||||
-----END PGP SIGNATURE-----`
|
||||
|
||||
t.Run("valid manifest", func(t *testing.T) {
|
||||
s := ProvideService(&config.Cfg{}, statickey.New())
|
||||
s := ProvideService(&config.PluginManagementCfg{}, statickey.New())
|
||||
manifest, err := s.readPluginManifest(context.Background(), []byte(txt))
|
||||
|
||||
require.NoError(t, err)
|
||||
@@ -69,7 +69,7 @@ NR7DnB0CCQHO+4FlSPtXFTzNepoc+CytQyDAeOLMLmf2Tqhk2YShk+G/YlVX
|
||||
|
||||
t.Run("invalid manifest", func(t *testing.T) {
|
||||
modified := strings.ReplaceAll(txt, "README.md", "xxxxxxxxxx")
|
||||
s := ProvideService(&config.Cfg{}, statickey.New())
|
||||
s := ProvideService(&config.PluginManagementCfg{}, statickey.New())
|
||||
_, err := s.readPluginManifest(context.Background(), []byte(modified))
|
||||
require.Error(t, err)
|
||||
})
|
||||
@@ -107,7 +107,7 @@ khdr/tZ1PDgRxMqB/u+Vtbpl0xSxgblnrDOYMSI=
|
||||
-----END PGP SIGNATURE-----`
|
||||
|
||||
t.Run("valid manifest", func(t *testing.T) {
|
||||
s := ProvideService(&config.Cfg{}, statickey.New())
|
||||
s := ProvideService(&config.PluginManagementCfg{}, statickey.New())
|
||||
manifest, err := s.readPluginManifest(context.Background(), []byte(txt))
|
||||
|
||||
require.NoError(t, err)
|
||||
@@ -155,7 +155,7 @@ func TestCalculate(t *testing.T) {
|
||||
|
||||
for _, tc := range tcs {
|
||||
basePath := filepath.Join(parentDir, "testdata/non-pvt-with-root-url/plugin")
|
||||
s := ProvideService(&config.Cfg{GrafanaAppURL: tc.appURL}, statickey.New())
|
||||
s := ProvideService(&config.PluginManagementCfg{GrafanaAppURL: tc.appURL}, statickey.New())
|
||||
sig, err := s.Calculate(context.Background(), &fakes.FakePluginSource{
|
||||
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
||||
return plugins.ClassExternal
|
||||
@@ -183,7 +183,7 @@ func TestCalculate(t *testing.T) {
|
||||
basePath := "../testdata/renderer-added-file/plugin"
|
||||
|
||||
runningWindows = true
|
||||
s := ProvideService(&config.Cfg{}, statickey.New())
|
||||
s := ProvideService(&config.PluginManagementCfg{}, statickey.New())
|
||||
sig, err := s.Calculate(context.Background(), &fakes.FakePluginSource{
|
||||
PluginClassFunc: func(ctx context.Context) plugins.Class {
|
||||
return plugins.ClassExternal
|
||||
@@ -247,7 +247,7 @@ func TestCalculate(t *testing.T) {
|
||||
toSlash = tc.platform.toSlashFunc()
|
||||
fromSlash = tc.platform.fromSlashFunc()
|
||||
|
||||
s := ProvideService(&config.Cfg{}, statickey.New())
|
||||
s := ProvideService(&config.PluginManagementCfg{}, statickey.New())
|
||||
pfs, err := tc.fsFactory()
|
||||
require.NoError(t, err)
|
||||
pfs, err = newPathSeparatorOverrideFS(string(tc.platform.separator), pfs)
|
||||
@@ -715,7 +715,7 @@ func Test_validateManifest(t *testing.T) {
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s := ProvideService(&config.Cfg{}, statickey.New())
|
||||
s := ProvideService(&config.PluginManagementCfg{}, statickey.New())
|
||||
err := s.validateManifest(context.Background(), *tc.manifest, nil)
|
||||
require.Errorf(t, err, tc.expectedErr)
|
||||
})
|
||||
@@ -811,7 +811,7 @@ pHo=
|
||||
}
|
||||
|
||||
func Test_VerifyRevokedKey(t *testing.T) {
|
||||
s := ProvideService(&config.Cfg{}, &revokedKeyProvider{})
|
||||
s := ProvideService(&config.PluginManagementCfg{}, &revokedKeyProvider{})
|
||||
m := createV2Manifest(t)
|
||||
txt := `-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA512
|
||||
|
||||
Reference in New Issue
Block a user