mirror of https://github.com/grafana/grafana.git
48 lines
986 B
Go
48 lines
986 B
Go
package finder
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
"github.com/grafana/grafana/pkg/services/org"
|
|
)
|
|
|
|
func ReadPluginJSON(reader io.Reader) (plugins.JSONData, error) {
|
|
plugin := plugins.JSONData{}
|
|
if err := json.NewDecoder(reader).Decode(&plugin); err != nil {
|
|
return plugins.JSONData{}, err
|
|
}
|
|
|
|
if err := validatePluginJSON(plugin); err != nil {
|
|
return plugins.JSONData{}, err
|
|
}
|
|
|
|
if plugin.ID == "grafana-piechart-panel" {
|
|
plugin.Name = "Pie Chart (old)"
|
|
}
|
|
|
|
if len(plugin.Dependencies.Plugins) == 0 {
|
|
plugin.Dependencies.Plugins = []plugins.Dependency{}
|
|
}
|
|
|
|
if plugin.Dependencies.GrafanaVersion == "" {
|
|
plugin.Dependencies.GrafanaVersion = "*"
|
|
}
|
|
|
|
for _, include := range plugin.Includes {
|
|
if include.Role == "" {
|
|
include.Role = org.RoleViewer
|
|
}
|
|
}
|
|
|
|
return plugin, nil
|
|
}
|
|
|
|
func validatePluginJSON(data plugins.JSONData) error {
|
|
if data.ID == "" || !data.Type.IsValid() {
|
|
return ErrInvalidPluginJSON
|
|
}
|
|
return nil
|
|
}
|