Commit 89d10c70 by Arve Knudsen Committed by GitHub

Plugins: Compose filesystem paths with filepath.Join (#28375)

* plugins: Fix filesystem path composition

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* plugins: Use filepath.Join to join filesystem paths

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
parent 762a7195
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
...@@ -338,7 +337,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) Response { ...@@ -338,7 +337,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) Response {
filePath := hs.Cfg.DefaultHomeDashboardPath filePath := hs.Cfg.DefaultHomeDashboardPath
if filePath == "" { if filePath == "" {
filePath = path.Join(hs.Cfg.StaticRootPath, "dashboards/home.json") filePath = filepath.Join(hs.Cfg.StaticRootPath, "dashboards/home.json")
} }
file, err := os.Open(filePath) file, err := os.Open(filePath)
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"path" "path/filepath"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
...@@ -55,7 +55,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg) (*macaron.Macaron, *HT ...@@ -55,7 +55,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg) (*macaron.Macaron, *HT
m := macaron.New() m := macaron.New()
m.Use(middleware.GetContextHandler(nil, nil, nil)) m.Use(middleware.GetContextHandler(nil, nil, nil))
m.Use(macaron.Renderer(macaron.RenderOptions{ m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"), Directory: filepath.Join(setting.StaticRootPath, "views"),
IndentJSON: true, IndentJSON: true,
Delims: macaron.Delims{Left: "[[", Right: "]]"}, Delims: macaron.Delims{Left: "[[", Right: "]]"},
})) }))
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"path/filepath"
"sync" "sync"
"github.com/grafana/grafana/pkg/services/live" "github.com/grafana/grafana/pkg/services/live"
...@@ -331,7 +332,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() { ...@@ -331,7 +332,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
} }
m.Use(macaron.Renderer(macaron.RenderOptions{ m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"), Directory: filepath.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD, IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"}, Delims: macaron.Delims{Left: "[[", Right: "]]"},
})) }))
......
...@@ -2,7 +2,7 @@ package plugins ...@@ -2,7 +2,7 @@ package plugins
import ( import (
"encoding/json" "encoding/json"
"path" "path/filepath"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
...@@ -45,7 +45,7 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, base *PluginBase, backend ...@@ -45,7 +45,7 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, base *PluginBase, backend
if p.Backend { if p.Backend {
cmd := ComposePluginStartCommand(p.Executable) cmd := ComposePluginStartCommand(p.Executable)
fullpath := path.Join(p.PluginDir, cmd) fullpath := filepath.Join(p.PluginDir, cmd)
factory := grpcplugin.NewBackendPlugin(p.Id, fullpath, grpcplugin.PluginStartFuncs{ factory := grpcplugin.NewBackendPlugin(p.Id, fullpath, grpcplugin.PluginStartFuncs{
OnLegacyStart: p.onLegacyPluginStart, OnLegacyStart: p.onLegacyPluginStart,
OnStart: p.onPluginStart, OnStart: p.onPluginStart,
......
...@@ -54,8 +54,8 @@ func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) { ...@@ -54,8 +54,8 @@ func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) {
func (fp *FrontendPluginBase) handleModuleDefaults() { func (fp *FrontendPluginBase) handleModuleDefaults() {
if isExternalPlugin(fp.PluginDir) { if isExternalPlugin(fp.PluginDir) {
fp.Module = path.Join("plugins", fp.Id, "module") fp.Module = filepath.Join("plugins", fp.Id, "module")
fp.BaseUrl = path.Join("public/plugins", fp.Id) fp.BaseUrl = filepath.Join("public/plugins", fp.Id)
return return
} }
...@@ -66,8 +66,8 @@ func (fp *FrontendPluginBase) handleModuleDefaults() { ...@@ -66,8 +66,8 @@ func (fp *FrontendPluginBase) handleModuleDefaults() {
currentDir := filepath.Base(fp.PluginDir) currentDir := filepath.Base(fp.PluginDir)
// use path package for the following statements // use path package for the following statements
// because these are not file paths // because these are not file paths
fp.Module = path.Join("app/plugins", fp.Type, currentDir, "module") fp.Module = filepath.Join("app/plugins", fp.Type, currentDir, "module")
fp.BaseUrl = path.Join("public/app/plugins", fp.Type, currentDir) fp.BaseUrl = filepath.Join("public/app/plugins", fp.Type, currentDir)
} }
func isExternalPlugin(pluginDir string) bool { func isExternalPlugin(pluginDir string) bool {
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
...@@ -79,7 +78,7 @@ func (pm *PluginManager) Init() error { ...@@ -79,7 +78,7 @@ func (pm *PluginManager) Init() error {
pm.log.Info("Starting plugin search") pm.log.Info("Starting plugin search")
plugDir := path.Join(setting.StaticRootPath, "app/plugins") plugDir := filepath.Join(setting.StaticRootPath, "app/plugins")
pm.log.Debug("Scanning core plugin directory", "dir", plugDir) pm.log.Debug("Scanning core plugin directory", "dir", plugDir)
if err := pm.scan(plugDir, false); err != nil { if err := pm.scan(plugDir, false); err != nil {
return errutil.Wrapf(err, "failed to scan core plugin directory '%s'", plugDir) return errutil.Wrapf(err, "failed to scan core plugin directory '%s'", plugDir)
......
...@@ -3,7 +3,7 @@ package plugins ...@@ -3,7 +3,7 @@ package plugins
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"path" "path/filepath"
pluginModel "github.com/grafana/grafana-plugin-model/go/renderer" pluginModel "github.com/grafana/grafana-plugin-model/go/renderer"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
...@@ -34,7 +34,7 @@ func (r *RendererPlugin) Load(decoder *json.Decoder, base *PluginBase, backendPl ...@@ -34,7 +34,7 @@ func (r *RendererPlugin) Load(decoder *json.Decoder, base *PluginBase, backendPl
r.backendPluginManager = backendPluginManager r.backendPluginManager = backendPluginManager
cmd := ComposePluginStartCommand("plugin_start") cmd := ComposePluginStartCommand("plugin_start")
fullpath := path.Join(r.PluginDir, cmd) fullpath := filepath.Join(r.PluginDir, cmd)
factory := grpcplugin.NewRendererPlugin(r.Id, fullpath, grpcplugin.PluginStartFuncs{ factory := grpcplugin.NewRendererPlugin(r.Id, fullpath, grpcplugin.PluginStartFuncs{
OnLegacyStart: r.onLegacyPluginStart, OnLegacyStart: r.onLegacyPluginStart,
OnStart: r.onPluginStart, OnStart: r.onPluginStart,
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"path" "path/filepath"
"strconv" "strconv"
sdkgrpcplugin "github.com/grafana/grafana-plugin-sdk-go/backend/grpcplugin" sdkgrpcplugin "github.com/grafana/grafana-plugin-sdk-go/backend/grpcplugin"
...@@ -38,7 +38,7 @@ func (p *TransformPlugin) Load(decoder *json.Decoder, base *PluginBase, backendP ...@@ -38,7 +38,7 @@ func (p *TransformPlugin) Load(decoder *json.Decoder, base *PluginBase, backendP
} }
cmd := ComposePluginStartCommand(p.Executable) cmd := ComposePluginStartCommand(p.Executable)
fullpath := path.Join(p.PluginDir, cmd) fullpath := filepath.Join(p.PluginDir, cmd)
factory := grpcplugin.NewBackendPlugin(p.Id, fullpath, grpcplugin.PluginStartFuncs{ factory := grpcplugin.NewBackendPlugin(p.Id, fullpath, grpcplugin.PluginStartFuncs{
OnStart: p.onPluginStart, OnStart: p.onPluginStart,
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment