mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 05:02:35 +08:00
Plugin loader: refactor step evaluation (#85881)
This commit is contained in:

committed by
GitHub

parent
1e9841b1c9
commit
f375af793f
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Validator is responsible for the Validation stage of the plugin loader pipeline.
|
||||
type Validator interface {
|
||||
Validate(ctx context.Context, ps []*plugins.Plugin) ([]*plugins.Plugin, error)
|
||||
Validate(ctx context.Context, ps *plugins.Plugin) error
|
||||
}
|
||||
|
||||
// ValidateFunc is the function used for the Validate step of the Validation stage.
|
||||
@ -40,26 +40,18 @@ func New(cfg *config.PluginManagementCfg, opts Opts) *Validate {
|
||||
}
|
||||
|
||||
// Validate will execute the Validate steps of the Validation stage.
|
||||
func (v *Validate) Validate(ctx context.Context, ps []*plugins.Plugin) ([]*plugins.Plugin, error) {
|
||||
func (v *Validate) Validate(ctx context.Context, ps *plugins.Plugin) error {
|
||||
if len(v.validateSteps) == 0 {
|
||||
return ps, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
validatedPlugins := make([]*plugins.Plugin, 0, len(ps))
|
||||
for _, p := range ps {
|
||||
stepFailed := false
|
||||
for _, validate := range v.validateSteps {
|
||||
err := validate(ctx, p)
|
||||
if err != nil {
|
||||
stepFailed = true
|
||||
v.log.Error("Plugin validation failed", "pluginId", p.ID, "error", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !stepFailed {
|
||||
validatedPlugins = append(validatedPlugins, p)
|
||||
for _, validate := range v.validateSteps {
|
||||
err := validate(ctx, ps)
|
||||
if err != nil {
|
||||
v.log.Error("Plugin validation failed", "pluginId", ps.ID, "error", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return validatedPlugins, nil
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user