feat(plugins): changed plugin schema, pluginType -> type, type -> id

This commit is contained in:
Torkel Ödegaard
2016-01-08 23:15:44 +01:00
parent 7a8b3c419b
commit 3bb20dbf2e
23 changed files with 79 additions and 203 deletions
+12 -9
View File
@@ -4,6 +4,13 @@ import (
"github.com/grafana/grafana/pkg/models"
)
type PluginCommon struct {
Type string `json:"type"`
Name string `json:"name"`
Id string `json:"id"`
Info PluginInfo `json:"info"`
}
type PluginInfo struct {
Author PluginInfoLink `json:"author"`
Description string `json:"description"`
@@ -22,10 +29,9 @@ type PluginLogos struct {
}
type DataSourcePlugin struct {
Type string `json:"type"`
Name string `json:"name"`
ServiceName string `json:"serviceName"`
PluginCommon
Module string `json:"module"`
ServiceName string `json:"serviceName"`
Partials map[string]interface{} `json:"partials"`
DefaultMatchFormat string `json:"defaultMatchFormat"`
Annotations bool `json:"annotations"`
@@ -36,8 +42,7 @@ type DataSourcePlugin struct {
}
type PanelPlugin struct {
Type string `json:"type"`
Name string `json:"name"`
PluginCommon
Module string `json:"module"`
PublicContent *PublicContent `json:"public"`
App string `json:"app"`
@@ -71,21 +76,19 @@ type AppPluginCss struct {
}
type ApiPlugin struct {
Type string `json:"type"`
PluginCommon
Routes []*ApiPluginRoute `json:"routes"`
App string `json:"app"`
}
type AppPlugin struct {
Type string `json:"type"`
Name string `json:"name"`
PluginCommon
Enabled bool `json:"enabled"`
Pinned bool `json:"pinned"`
Module string `json:"module"`
Css *AppPluginCss `json:"css"`
Page *AppPluginPage `json:"page"`
PublicContent *PublicContent `json:"public"`
Info *PluginInfo `json:"info"`
}
type EnabledPlugins struct {
+18 -35
View File
@@ -121,7 +121,7 @@ func addPublicContent(public *PublicContent, currentDir string) {
}
}
func interpolatePluginJson(reader io.Reader) (io.Reader, error) {
func interpolatePluginJson(reader io.Reader, pluginCommon *PluginCommon) (io.Reader, error) {
buf := new(bytes.Buffer)
buf.ReadFrom(reader)
jsonStr := buf.String() //
@@ -132,7 +132,7 @@ func interpolatePluginJson(reader io.Reader) (io.Reader, error) {
}
data := map[string]interface{}{
"PluginPublicRoot": "HAHAHA",
"PluginPublicRoot": "public/plugins/" + pluginCommon.Id,
}
var resultBuffer bytes.Buffer
@@ -153,76 +153,59 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
defer reader.Close()
jsonParser := json.NewDecoder(reader)
pluginJson := make(map[string]interface{})
if err := jsonParser.Decode(&pluginJson); err != nil {
pluginCommon := PluginCommon{}
if err := jsonParser.Decode(&pluginCommon); err != nil {
return err
}
pluginType, exists := pluginJson["pluginType"]
if !exists {
return errors.New("Did not find pluginType property in plugin.json")
if pluginCommon.Id == "" || pluginCommon.Type == "" {
return errors.New("Did not find type and id property in plugin.json")
}
reader.Seek(0, 0)
if newReader, err := interpolatePluginJson(reader); err != nil {
if newReader, err := interpolatePluginJson(reader, &pluginCommon); err != nil {
return err
} else {
jsonParser = json.NewDecoder(newReader)
}
if pluginType == "datasource" {
switch pluginCommon.Type {
case "datasource":
p := DataSourcePlugin{}
if err := jsonParser.Decode(&p); err != nil {
return err
}
if p.Type == "" {
return errors.New("Did not find type property in plugin.json")
}
DataSources[p.Type] = &p
DataSources[p.Id] = &p
addPublicContent(p.PublicContent, currentDir)
}
if pluginType == "panel" {
case "panel":
p := PanelPlugin{}
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")
}
Panels[p.Type] = &p
Panels[p.Id] = &p
addPublicContent(p.PublicContent, currentDir)
}
if pluginType == "api" {
case "api":
p := ApiPlugin{}
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")
}
ApiPlugins[p.Type] = &p
}
if pluginType == "app" {
ApiPlugins[p.Id] = &p
case "app":
p := AppPlugin{}
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")
}
Apps[p.Type] = &p
Apps[p.Id] = &p
addPublicContent(p.PublicContent, currentDir)
default:
return errors.New("Unkown plugin type " + pluginCommon.Type)
}
return nil
+1 -1
View File
@@ -29,7 +29,7 @@ func TestPluginScans(t *testing.T) {
So(err, ShouldBeNil)
So(len(Apps), ShouldBeGreaterThan, 0)
So(Apps["app-test"].Info.Logos.Large, ShouldEqual, "plugins/app-exampl/img/logo_large.png")
So(Apps["app-test"].Info.Logos.Large, ShouldEqual, "public/plugins/app-test/logo_large.png")
})
}