mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 10:42:14 +08:00
feat(plugins): began work on supporting having plugins outside grafana, for example in grafana data dir, next step is to be able to easily specify what plugins you waant to install
This commit is contained in:
@ -8,52 +8,11 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
type PluginMeta struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type ExternalPluginRoute struct {
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
ReqSignedIn bool `json:"req_signed_in"`
|
||||
ReqGrafanaAdmin bool `json:"req_grafana_admin"`
|
||||
ReqRole models.RoleType `json:"req_role"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type ExternalPluginJs struct {
|
||||
Src string `json:"src"`
|
||||
}
|
||||
|
||||
type ExternalPluginMenuItem struct {
|
||||
Text string `json:"text"`
|
||||
Icon string `json:"icon"`
|
||||
Href string `json:"href"`
|
||||
}
|
||||
|
||||
type ExternalPluginCss struct {
|
||||
Href string `json:"href"`
|
||||
}
|
||||
|
||||
type ExternalPluginSettings struct {
|
||||
Routes []*ExternalPluginRoute `json:"routes"`
|
||||
Js []*ExternalPluginJs `json:"js"`
|
||||
Css []*ExternalPluginCss `json:"css"`
|
||||
MenuItems []*ExternalPluginMenuItem `json:"menu_items"`
|
||||
}
|
||||
|
||||
type ExternalPlugin struct {
|
||||
PluginType string `json:"pluginType"`
|
||||
Settings ExternalPluginSettings `json:"settings"`
|
||||
}
|
||||
|
||||
var (
|
||||
DataSources map[string]interface{}
|
||||
DataSources map[string]DataSourcePlugin
|
||||
ExternalPlugins []ExternalPlugin
|
||||
)
|
||||
|
||||
@ -63,13 +22,14 @@ type PluginScanner struct {
|
||||
}
|
||||
|
||||
func Init() {
|
||||
DataSources = make(map[string]DataSourcePlugin)
|
||||
ExternalPlugins = make([]ExternalPlugin, 0)
|
||||
|
||||
scan(path.Join(setting.StaticRootPath, "app/plugins"))
|
||||
scan(path.Join(setting.DataPath, "plugins"))
|
||||
}
|
||||
|
||||
func scan(pluginDir string) error {
|
||||
DataSources = make(map[string]interface{})
|
||||
ExternalPlugins = make([]ExternalPlugin, 0)
|
||||
|
||||
scanner := &PluginScanner{
|
||||
pluginPath: pluginDir,
|
||||
}
|
||||
@ -125,12 +85,19 @@ func (scanner *PluginScanner) loadPluginJson(path string) error {
|
||||
}
|
||||
|
||||
if pluginType == "datasource" {
|
||||
datasourceType, exists := pluginJson["type"]
|
||||
if !exists {
|
||||
p := DataSourcePlugin{}
|
||||
reader.Seek(0, 0)
|
||||
if err := jsonParser.Decode(&p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.Type == "" {
|
||||
return errors.New("Did not find type property in plugin.json")
|
||||
}
|
||||
DataSources[datasourceType.(string)] = pluginJson
|
||||
|
||||
DataSources[p.Type] = p
|
||||
}
|
||||
|
||||
if pluginType == "externalPlugin" {
|
||||
p := ExternalPlugin{}
|
||||
reader.Seek(0, 0)
|
||||
|
Reference in New Issue
Block a user