models.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. Includes []*PluginInclude `json:"includes"`
  19. Module string `json:"module"`
  20. BaseUrl string `json:"baseUrl"`
  21. StaticRoot string `json:"staticRoot"`
  22. StaticRootAbs string `json:"-"`
  23. IncludedInAppId string `json:"-"`
  24. PluginDir string `json:"-"`
  25. }
  26. func (pb *PluginBase) registerPlugin(pluginDir string) error {
  27. if _, exists := Plugins[pb.Id]; exists {
  28. return errors.New("Plugin with same id already exists")
  29. }
  30. if !strings.HasPrefix(pluginDir, setting.StaticRootPath) {
  31. log.Info("Plugins: Registering plugin %v", pb.Name)
  32. }
  33. if len(pb.Dependencies.Plugins) == 0 {
  34. pb.Dependencies.Plugins = []PluginDependencyItem{}
  35. }
  36. if pb.Dependencies.GrafanaVersion == "" {
  37. pb.Dependencies.GrafanaVersion = "*"
  38. }
  39. pb.PluginDir = pluginDir
  40. Plugins[pb.Id] = pb
  41. return nil
  42. }
  43. type PluginDependencies struct {
  44. GrafanaVersion string `json:"grafanaVersion"`
  45. Plugins []PluginDependencyItem `json:"plugins"`
  46. }
  47. type PluginInclude struct {
  48. Name string `json:"name"`
  49. Path string `json:"path"`
  50. Type string `json:"type"`
  51. Id string `json:"id"`
  52. }
  53. type PluginDependencyItem struct {
  54. Type string `json:"type"`
  55. Id string `json:"id"`
  56. Name string `json:"name"`
  57. Version string `json:"version"`
  58. }
  59. type PluginInfo struct {
  60. Author PluginInfoLink `json:"author"`
  61. Description string `json:"description"`
  62. Links []PluginInfoLink `json:"links"`
  63. Logos PluginLogos `json:"logos"`
  64. Screenshots []PluginScreenshots `json:"screenshots"`
  65. Version string `json:"version"`
  66. Updated string `json:"updated"`
  67. }
  68. type PluginInfoLink struct {
  69. Name string `json:"name"`
  70. Url string `json:"url"`
  71. }
  72. type PluginLogos struct {
  73. Small string `json:"small"`
  74. Large string `json:"large"`
  75. }
  76. type PluginScreenshots struct {
  77. Path string `json:"path"`
  78. Name string `json:"name"`
  79. }
  80. type PluginStaticRoute struct {
  81. Directory string
  82. PluginId string
  83. }
  84. type EnabledPlugins struct {
  85. Panels []*PanelPlugin
  86. DataSources map[string]*DataSourcePlugin
  87. Apps []*AppPlugin
  88. }
  89. func NewEnabledPlugins() EnabledPlugins {
  90. return EnabledPlugins{
  91. Panels: make([]*PanelPlugin, 0),
  92. DataSources: make(map[string]*DataSourcePlugin),
  93. Apps: make([]*AppPlugin, 0),
  94. }
  95. }