forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsources.go
68 lines (56 loc) · 1.74 KB
/
sources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package sources
import (
"context"
"path/filepath"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/setting"
)
type Service struct {
cfg *setting.Cfg
log log.Logger
}
func ProvideService(cfg *setting.Cfg) *Service {
return &Service{
cfg: cfg,
log: log.New("plugin.sources"),
}
}
func (s *Service) List(_ context.Context) []plugins.PluginSource {
r := []plugins.PluginSource{
NewLocalSource(plugins.ClassCore, corePluginPaths(s.cfg.StaticRootPath)),
NewLocalSource(plugins.ClassBundled, []string{s.cfg.BundledPluginsPath}),
}
r = append(r, s.externalPluginSources()...)
r = append(r, s.pluginSettingSources()...)
return r
}
func (s *Service) externalPluginSources() []plugins.PluginSource {
localSrcs, err := DirAsLocalSources(s.cfg.PluginsPath, plugins.ClassExternal)
if err != nil {
s.log.Error("Failed to load external plugins", "error", err)
return []plugins.PluginSource{}
}
srcs := make([]plugins.PluginSource, len(localSrcs))
for i, src := range localSrcs {
srcs[i] = src
}
return srcs
}
func (s *Service) pluginSettingSources() []plugins.PluginSource {
sources := make([]plugins.PluginSource, 0, len(s.cfg.PluginSettings))
for _, ps := range s.cfg.PluginSettings {
path, exists := ps["path"]
if !exists || path == "" {
continue
}
sources = append(sources, NewLocalSource(plugins.ClassExternal, []string{path}))
}
return sources
}
// corePluginPaths provides a list of the Core plugin file system paths
func corePluginPaths(staticRootPath string) []string {
datasourcePaths := filepath.Join(staticRootPath, "app/plugins/datasource")
panelsPath := filepath.Join(staticRootPath, "app/plugins/panel")
return []string{datasourcePaths, panelsPath}
}