models.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package plugins
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "strings"
  6. "github.com/grafana/grafana/pkg/log"
  7. "github.com/grafana/grafana/pkg/setting"
  8. )
  9. type PluginLoader interface {
  10. Load(decoder *json.Decoder, pluginDir string) error
  11. }
  12. type PluginBase struct {
  13. Type string `json:"type"`
  14. Name string `json:"name"`
  15. Id string `json:"id"`
  16. Info PluginInfo `json:"info"`
  17. Dependencies PluginDependencies `json:"dependencies"`
  18. IncludedInAppId string `json:"-"`
  19. PluginDir string `json:"-"`
  20. }
  21. func (pb *PluginBase) registerPlugin(pluginDir string) error {
  22. if _, exists := Plugins[pb.Id]; exists {
  23. return errors.New("Plugin with same id already exists")
  24. }
  25. if !strings.HasPrefix(pluginDir, setting.StaticRootPath) {
  26. log.Info("Plugins: Registering plugin %v", pb.Name)
  27. }
  28. pb.PluginDir = pluginDir
  29. Plugins[pb.Id] = pb
  30. return nil
  31. }
  32. type PluginDependencies struct {
  33. GrafanaVersion string `json:"grafanaVersion"`
  34. Plugins []PluginDependencyItem `json:"plugins"`
  35. }
  36. type PluginDependencyItem struct {
  37. Type string `json:"type"`
  38. Id string `json:"id"`
  39. Name string `json:"name"`
  40. Version string `json:"version"`
  41. }
  42. type PluginInfo struct {
  43. Author PluginInfoLink `json:"author"`
  44. Description string `json:"description"`
  45. Links []PluginInfoLink `json:"links"`
  46. Logos PluginLogos `json:"logos"`
  47. Screenshots []PluginScreenshots `json:"screenshots"`
  48. Version string `json:"version"`
  49. Updated string `json:"updated"`
  50. }
  51. type PluginInfoLink struct {
  52. Name string `json:"name"`
  53. Url string `json:"url"`
  54. }
  55. type PluginLogos struct {
  56. Small string `json:"small"`
  57. Large string `json:"large"`
  58. }
  59. type PluginScreenshots struct {
  60. Path string `json:"path"`
  61. Name string `json:"name"`
  62. }
  63. type PluginStaticRoute struct {
  64. Directory string
  65. PluginId string
  66. }
  67. type EnabledPlugins struct {
  68. Panels []*PanelPlugin
  69. DataSources map[string]*DataSourcePlugin
  70. Apps []*AppPlugin
  71. }
  72. func NewEnabledPlugins() EnabledPlugins {
  73. return EnabledPlugins{
  74. Panels: make([]*PanelPlugin, 0),
  75. DataSources: make(map[string]*DataSourcePlugin),
  76. Apps: make([]*AppPlugin, 0),
  77. }
  78. }