feat(external plugins): worked on supporting external plugins better

This commit is contained in:
Torkel Ödegaard
2015-11-19 18:44:07 +01:00
parent 65a7fa320a
commit 69daede583
13 changed files with 58 additions and 60 deletions
+11 -16
View File
@@ -16,22 +16,21 @@ type DataSourcePlugin struct {
}
type StaticRootConfig struct {
Url string `json:"url"`
Path string `json:"path"`
PluginRoot string `json:"-"`
Url string `json:"url"`
Path string `json:"path"`
}
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"`
ReqSignedIn bool `json:"reqSignedIn"`
ReqGrafanaAdmin bool `json:"reqGrafanaAdmin"`
ReqRole models.RoleType `json:"reqRole"`
Url string `json:"url"`
}
type ExternalPluginJs struct {
Src string `json:"src"`
Module string `json:"module"`
}
type ExternalPluginMenuItem struct {
@@ -44,14 +43,10 @@ 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"`
Routes []*ExternalPluginRoute `json:"routes"`
Js []*ExternalPluginJs `json:"js"`
Css []*ExternalPluginCss `json:"css"`
MenuItems []*ExternalPluginMenuItem `json:"menuItems"`
StaticRootConfig *StaticRootConfig `json:"staticRoot"`
}
+11 -7
View File
@@ -38,7 +38,7 @@ func checkExternalPluginPaths() error {
if strings.HasPrefix(section.Name(), "plugin.") {
path := section.Key("path").String()
if path != "" {
log.Info("Plugin: scaning specific dir %s", path)
log.Info("Plugin: Scaning dir %s", path)
scan(path)
}
}
@@ -81,6 +81,13 @@ func (scanner *PluginScanner) walker(currentPath string, f os.FileInfo, err erro
return nil
}
func addStaticRoot(staticRootConfig *StaticRootConfig, currentDir string) {
if staticRootConfig != nil {
staticRootConfig.Path = path.Join(currentDir, staticRootConfig.Path)
StaticRoutes = append(StaticRoutes, staticRootConfig)
}
}
func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
currentDir := filepath.Dir(pluginJsonFilePath)
reader, err := os.Open(pluginJsonFilePath)
@@ -114,20 +121,17 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
}
DataSources[p.Type] = p
if p.StaticRootConfig != nil {
p.StaticRootConfig.Path = path.Join(currentDir, p.StaticRootConfig.Path)
StaticRoutes = append(StaticRoutes, p.StaticRootConfig)
}
addStaticRoot(p.StaticRootConfig, currentDir)
}
if pluginType == "externalPlugin" {
if pluginType == "external" {
p := ExternalPlugin{}
reader.Seek(0, 0)
if err := jsonParser.Decode(&p); err != nil {
return err
}
ExternalPlugins = append(ExternalPlugins, p)
addStaticRoot(p.StaticRootConfig, currentDir)
}
return nil