2015-11-19 05:55:13 -06:00
|
|
|
package plugins
|
|
|
|
|
2015-12-21 10:23:24 -06:00
|
|
|
import (
|
2016-01-09 16:34:20 -06:00
|
|
|
"encoding/json"
|
2016-02-10 04:03:12 -06:00
|
|
|
"errors"
|
2016-03-10 12:57:48 -06:00
|
|
|
"fmt"
|
2016-02-10 04:03:12 -06:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/log"
|
2016-03-21 13:07:08 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2016-02-10 04:03:12 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2015-12-21 10:23:24 -06:00
|
|
|
)
|
2015-11-19 05:55:13 -06:00
|
|
|
|
2016-03-10 12:57:48 -06:00
|
|
|
var (
|
|
|
|
PluginTypeApp = "app"
|
|
|
|
PluginTypeDatasource = "datasource"
|
|
|
|
PluginTypePanel = "panel"
|
|
|
|
PluginTypeDashboard = "dashboard"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PluginNotFoundError struct {
|
|
|
|
PluginId string
|
|
|
|
}
|
|
|
|
|
2016-03-11 02:57:20 -06:00
|
|
|
func (e PluginNotFoundError) Error() string {
|
2016-03-10 12:57:48 -06:00
|
|
|
return fmt.Sprintf("Plugin with id %s not found", e.PluginId)
|
|
|
|
}
|
|
|
|
|
2016-01-09 16:34:20 -06:00
|
|
|
type PluginLoader interface {
|
|
|
|
Load(decoder *json.Decoder, pluginDir string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type PluginBase struct {
|
2016-03-14 11:16:10 -05:00
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
Info PluginInfo `json:"info"`
|
|
|
|
Dependencies PluginDependencies `json:"dependencies"`
|
|
|
|
Includes []*PluginInclude `json:"includes"`
|
|
|
|
Module string `json:"module"`
|
|
|
|
BaseUrl string `json:"baseUrl"`
|
2016-01-19 11:18:53 -06:00
|
|
|
|
|
|
|
IncludedInAppId string `json:"-"`
|
|
|
|
PluginDir string `json:"-"`
|
2016-03-22 04:15:47 -05:00
|
|
|
DefaultNavUrl string `json:"-"`
|
2016-03-13 13:21:44 -05:00
|
|
|
|
|
|
|
// cache for readme file contents
|
|
|
|
Readme []byte `json:"-"`
|
2016-01-08 16:15:44 -06:00
|
|
|
}
|
|
|
|
|
2016-02-10 04:03:12 -06:00
|
|
|
func (pb *PluginBase) registerPlugin(pluginDir string) error {
|
|
|
|
if _, exists := Plugins[pb.Id]; exists {
|
|
|
|
return errors.New("Plugin with same id already exists")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasPrefix(pluginDir, setting.StaticRootPath) {
|
|
|
|
log.Info("Plugins: Registering plugin %v", pb.Name)
|
|
|
|
}
|
|
|
|
|
2016-03-07 11:03:45 -06:00
|
|
|
if len(pb.Dependencies.Plugins) == 0 {
|
|
|
|
pb.Dependencies.Plugins = []PluginDependencyItem{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if pb.Dependencies.GrafanaVersion == "" {
|
|
|
|
pb.Dependencies.GrafanaVersion = "*"
|
|
|
|
}
|
|
|
|
|
2016-02-10 04:03:12 -06:00
|
|
|
pb.PluginDir = pluginDir
|
|
|
|
Plugins[pb.Id] = pb
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-07 07:31:02 -06:00
|
|
|
type PluginDependencies struct {
|
|
|
|
GrafanaVersion string `json:"grafanaVersion"`
|
|
|
|
Plugins []PluginDependencyItem `json:"plugins"`
|
|
|
|
}
|
|
|
|
|
2016-03-08 11:17:47 -06:00
|
|
|
type PluginInclude struct {
|
2016-03-21 13:07:08 -05:00
|
|
|
Name string `json:"name"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Component string `json:"component"`
|
|
|
|
Role models.RoleType `json:"role"`
|
2016-03-22 04:15:47 -05:00
|
|
|
AddToNav bool `json:"addToNav"`
|
2016-03-21 13:07:08 -05:00
|
|
|
DefaultNav bool `json:"defaultNav"`
|
|
|
|
Slug string `json:"slug"`
|
|
|
|
|
|
|
|
Id string `json:"-"`
|
2016-03-08 11:17:47 -06:00
|
|
|
}
|
|
|
|
|
2016-03-07 07:31:02 -06:00
|
|
|
type PluginDependencyItem struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
}
|
|
|
|
|
2015-12-22 09:32:17 -06:00
|
|
|
type PluginInfo struct {
|
2016-02-09 08:36:42 -06:00
|
|
|
Author PluginInfoLink `json:"author"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Links []PluginInfoLink `json:"links"`
|
|
|
|
Logos PluginLogos `json:"logos"`
|
|
|
|
Screenshots []PluginScreenshots `json:"screenshots"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
Updated string `json:"updated"`
|
2015-12-22 09:32:17 -06:00
|
|
|
}
|
|
|
|
|
2016-01-08 13:57:58 -06:00
|
|
|
type PluginInfoLink struct {
|
2015-12-22 09:32:17 -06:00
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PluginLogos struct {
|
|
|
|
Small string `json:"small"`
|
|
|
|
Large string `json:"large"`
|
|
|
|
}
|
|
|
|
|
2016-02-09 08:36:42 -06:00
|
|
|
type PluginScreenshots struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
2016-01-09 01:12:27 -06:00
|
|
|
type PluginStaticRoute struct {
|
|
|
|
Directory string
|
|
|
|
PluginId string
|
2015-11-19 09:50:17 -06:00
|
|
|
}
|
|
|
|
|
2015-12-03 01:52:37 -06:00
|
|
|
type EnabledPlugins struct {
|
2015-12-21 16:09:27 -06:00
|
|
|
Panels []*PanelPlugin
|
|
|
|
DataSources map[string]*DataSourcePlugin
|
|
|
|
Apps []*AppPlugin
|
2015-12-03 01:52:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEnabledPlugins() EnabledPlugins {
|
|
|
|
return EnabledPlugins{
|
2015-12-21 16:09:27 -06:00
|
|
|
Panels: make([]*PanelPlugin, 0),
|
|
|
|
DataSources: make(map[string]*DataSourcePlugin),
|
|
|
|
Apps: make([]*AppPlugin, 0),
|
2015-12-03 01:52:37 -06:00
|
|
|
}
|
|
|
|
}
|