mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #12007 from bergquist/provisioning_symlinked_folders
Add support for symlinked folders in dashboard provisioning
This commit is contained in:
commit
7214ee9024
@ -47,15 +47,25 @@ func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
|
|||||||
log.Error("Cannot read directory", "error", err)
|
log.Error("Cannot read directory", "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
absPath, err := filepath.Abs(path)
|
copy := path
|
||||||
|
path, err := filepath.Abs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not create absolute path ", "path", path)
|
log.Error("Could not create absolute path ", "path", path)
|
||||||
absPath = path //if .Abs return an error we fallback to path
|
}
|
||||||
|
|
||||||
|
path, err = filepath.EvalSymlinks(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to read content of symlinked path: %s", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if path == "" {
|
||||||
|
path = copy
|
||||||
|
log.Info("falling back to original path due to EvalSymlink/Abs failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &fileReader{
|
return &fileReader{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Path: absPath,
|
Path: path,
|
||||||
log: log,
|
log: log,
|
||||||
dashboardService: dashboards.NewProvisioningService(),
|
dashboardService: dashboards.NewProvisioningService(),
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
// +build linux
|
||||||
|
|
||||||
|
package dashboards
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
symlinkedFolder = "testdata/test-dashboards/symlink"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvsionedSymlinkedFolder(t *testing.T) {
|
||||||
|
cfg := &DashboardsAsConfig{
|
||||||
|
Name: "Default",
|
||||||
|
Type: "file",
|
||||||
|
OrgId: 1,
|
||||||
|
Folder: "",
|
||||||
|
Options: map[string]interface{}{"path": symlinkedFolder},
|
||||||
|
}
|
||||||
|
|
||||||
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected err to be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
want, err := filepath.Abs(containingId)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected err to be nill")
|
||||||
|
}
|
||||||
|
|
||||||
|
if reader.Path != want {
|
||||||
|
t.Errorf("got %s want %s", reader.Path, want)
|
||||||
|
}
|
||||||
|
}
|
@ -49,13 +49,16 @@ func TestCreatingNewDashboardFileReader(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("using full path", func() {
|
Convey("using full path", func() {
|
||||||
cfg.Options["folder"] = "/var/lib/grafana/dashboards"
|
fullPath := "/var/lib/grafana/dashboards"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
fullPath = `c:\var\lib\grafana`
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Options["folder"] = fullPath
|
||||||
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
if runtime.GOOS != "windows" {
|
So(reader.Path, ShouldEqual, fullPath)
|
||||||
So(reader.Path, ShouldEqual, "/var/lib/grafana/dashboards")
|
|
||||||
}
|
|
||||||
So(filepath.IsAbs(reader.Path), ShouldBeTrue)
|
So(filepath.IsAbs(reader.Path), ShouldBeTrue)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
1
pkg/services/provisioning/dashboards/testdata/test-dashboards/symlink
vendored
Symbolic link
1
pkg/services/provisioning/dashboards/testdata/test-dashboards/symlink
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
containing-id/
|
Loading…
Reference in New Issue
Block a user