mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
imagestorage: fix templating of public_url option for webdav (#74885)
* spelling in error message
* imguploader: fix template for webdav url
Since a few years ago, when loading the config file, the template gets replaced in the expanding
env var phase (see ##25075) and introduced a bug in the webdav public_url config option. This commit
changes the template syntax to be {{file}}. This doesn't get expanded and removed when the config file
is loaded.
* devenv: add a block for a WebDAV server
* Adding alerting as codeowners for webdav
---------
Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
This commit is contained in:
@@ -37,8 +37,8 @@ var netClient = &http.Client{
|
||||
}
|
||||
|
||||
func (u *WebdavUploader) PublicURL(filename string) string {
|
||||
if strings.Contains(u.public_url, "${file}") {
|
||||
return strings.ReplaceAll(u.public_url, "${file}", filename)
|
||||
if strings.Contains(u.public_url, "{{file}}") {
|
||||
return strings.ReplaceAll(u.public_url, "{{file}}", filename)
|
||||
}
|
||||
|
||||
publicURL, _ := url.Parse(u.public_url)
|
||||
|
||||
@@ -2,10 +2,10 @@ package imguploader
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -35,11 +35,10 @@ func TestUploadToWebdav(t *testing.T) {
|
||||
func TestPublicURL(t *testing.T) {
|
||||
t.Run("Given a public URL with parameters, and no template", func(t *testing.T) {
|
||||
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files=")
|
||||
parsed, _ := url.Parse(webdavUploader.PublicURL("fileyfile.png"))
|
||||
require.True(t, strings.HasSuffix(parsed.Path, "fileyfile.png"))
|
||||
assert.Equal(t, "http://cloudycloud.me/s/DOIFDOMV/download/fileyfile.png?files=", webdavUploader.PublicURL("fileyfile.png"))
|
||||
})
|
||||
t.Run("Given a public URL with parameters, and a template", func(t *testing.T) {
|
||||
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files=${file}")
|
||||
require.True(t, strings.HasSuffix(webdavUploader.PublicURL("fileyfile.png"), "fileyfile.png"))
|
||||
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://cloudycloud.me/s/DOIFDOMV/download?files={{file}}")
|
||||
assert.Equal(t, "http://cloudycloud.me/s/DOIFDOMV/download?files=fileyfile.png", webdavUploader.PublicURL("fileyfile.png"))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user