merge apiPlugins with appPlugins
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
type ApiPluginRoute struct {
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
ReqSignedIn bool `json:"reqSignedIn"`
|
||||
ReqGrafanaAdmin bool `json:"reqGrafanaAdmin"`
|
||||
ReqRole models.RoleType `json:"reqRole"`
|
||||
Url string `json:"url"`
|
||||
Headers []ApiPluginHeader `json:"headers"`
|
||||
}
|
||||
|
||||
type ApiPlugin struct {
|
||||
PluginBase
|
||||
Routes []*ApiPluginRoute `json:"routes"`
|
||||
}
|
||||
|
||||
type ApiPluginHeader struct {
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func (app *ApiPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
||||
if err := decoder.Decode(&app); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
app.PluginDir = pluginDir
|
||||
|
||||
ApiPlugins[app.Id] = app
|
||||
return nil
|
||||
}
|
||||
+19
-15
@@ -26,14 +26,30 @@ type AppIncludeInfo struct {
|
||||
|
||||
type AppPlugin struct {
|
||||
FrontendPluginBase
|
||||
Css *AppPluginCss `json:"css"`
|
||||
Pages []AppPluginPage `json:"pages"`
|
||||
Includes []AppIncludeInfo `json:"-"`
|
||||
Css *AppPluginCss `json:"css"`
|
||||
Pages []AppPluginPage `json:"pages"`
|
||||
Routes []*AppPluginRoute `json:"routes"`
|
||||
Includes []AppIncludeInfo `json:"-"`
|
||||
|
||||
Pinned bool `json:"-"`
|
||||
Enabled bool `json:"-"`
|
||||
}
|
||||
|
||||
type AppPluginRoute struct {
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
ReqSignedIn bool `json:"reqSignedIn"`
|
||||
ReqGrafanaAdmin bool `json:"reqGrafanaAdmin"`
|
||||
ReqRole models.RoleType `json:"reqRole"`
|
||||
Url string `json:"url"`
|
||||
Headers []AppPluginRouteHeader `json:"headers"`
|
||||
}
|
||||
|
||||
type AppPluginRouteHeader struct {
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
||||
if err := decoder.Decode(&app); err != nil {
|
||||
return err
|
||||
@@ -59,18 +75,6 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// check if we have child apiPlugins
|
||||
for _, plugin := range ApiPlugins {
|
||||
if strings.HasPrefix(plugin.PluginDir, app.PluginDir) {
|
||||
plugin.IncludedInAppId = app.Id
|
||||
app.Includes = append(app.Includes, AppIncludeInfo{
|
||||
Name: plugin.Name,
|
||||
Id: plugin.Id,
|
||||
Type: plugin.Type,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Apps[app.Id] = app
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ type PluginStaticRoute struct {
|
||||
type EnabledPlugins struct {
|
||||
Panels []*PanelPlugin
|
||||
DataSources map[string]*DataSourcePlugin
|
||||
ApiList []*ApiPlugin
|
||||
Apps []*AppPlugin
|
||||
}
|
||||
|
||||
@@ -53,7 +52,6 @@ func NewEnabledPlugins() EnabledPlugins {
|
||||
return EnabledPlugins{
|
||||
Panels: make([]*PanelPlugin, 0),
|
||||
DataSources: make(map[string]*DataSourcePlugin),
|
||||
ApiList: make([]*ApiPlugin, 0),
|
||||
Apps: make([]*AppPlugin, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
var (
|
||||
DataSources map[string]*DataSourcePlugin
|
||||
Panels map[string]*PanelPlugin
|
||||
ApiPlugins map[string]*ApiPlugin
|
||||
StaticRoutes []*PluginStaticRoute
|
||||
Apps map[string]*AppPlugin
|
||||
PluginTypes map[string]interface{}
|
||||
@@ -30,14 +29,12 @@ type PluginScanner struct {
|
||||
|
||||
func Init() error {
|
||||
DataSources = make(map[string]*DataSourcePlugin)
|
||||
ApiPlugins = make(map[string]*ApiPlugin)
|
||||
StaticRoutes = make([]*PluginStaticRoute, 0)
|
||||
Panels = make(map[string]*PanelPlugin)
|
||||
Apps = make(map[string]*AppPlugin)
|
||||
PluginTypes = map[string]interface{}{
|
||||
"panel": PanelPlugin{},
|
||||
"datasource": DataSourcePlugin{},
|
||||
"api": ApiPlugin{},
|
||||
"app": AppPlugin{},
|
||||
}
|
||||
|
||||
|
||||
@@ -68,11 +68,5 @@ func GetEnabledPlugins(orgId int64) (*EnabledPlugins, error) {
|
||||
}
|
||||
}
|
||||
|
||||
for _, api := range ApiPlugins {
|
||||
if isPluginEnabled(api.IncludedInAppId) {
|
||||
enabledPlugins.ApiList = append(enabledPlugins.ApiList, api)
|
||||
}
|
||||
}
|
||||
|
||||
return &enabledPlugins, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user