models.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. if len(pb.Dependencies.Plugins) == 0 {
  29. pb.Dependencies.Plugins = []PluginDependencyItem{}
  30. }
  31. if pb.Dependencies.GrafanaVersion == "" {
  32. pb.Dependencies.GrafanaVersion = "*"
  33. }
  34. pb.PluginDir = pluginDir
  35. Plugins[pb.Id] = pb
  36. return nil
  37. }
  38. type PluginDependencies struct {
  39. GrafanaVersion string `json:"grafanaVersion"`
  40. Plugins []PluginDependencyItem `json:"plugins"`
  41. }
  42. type PluginDependencyItem struct {
  43. Type string `json:"type"`
  44. Id string `json:"id"`
  45. Name string `json:"name"`
  46. Version string `json:"version"`
  47. }
  48. type PluginInfo struct {
  49. Author PluginInfoLink `json:"author"`
  50. Description string `json:"description"`
  51. Links []PluginInfoLink `json:"links"`
  52. Logos PluginLogos `json:"logos"`
  53. Screenshots []PluginScreenshots `json:"screenshots"`
  54. Version string `json:"version"`
  55. Updated string `json:"updated"`
  56. }
  57. type PluginInfoLink struct {
  58. Name string `json:"name"`
  59. Url string `json:"url"`
  60. }
  61. type PluginLogos struct {
  62. Small string `json:"small"`
  63. Large string `json:"large"`
  64. }
  65. type PluginScreenshots struct {
  66. Path string `json:"path"`
  67. Name string `json:"name"`
  68. }
  69. type PluginStaticRoute struct {
  70. Directory string
  71. PluginId string
  72. }
  73. type EnabledPlugins struct {
  74. Panels []*PanelPlugin
  75. DataSources map[string]*DataSourcePlugin
  76. Apps []*AppPlugin
  77. }
  78. func NewEnabledPlugins() EnabledPlugins {
  79. return EnabledPlugins{
  80. Panels: make([]*PanelPlugin, 0),
  81. DataSources: make(map[string]*DataSourcePlugin),
  82. Apps: make([]*AppPlugin, 0),
  83. }
  84. }