Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
6d9e8bd1
Commit
6d9e8bd1
authored
Mar 23, 2017
by
fir4
Committed by
Daniel Lee
Apr 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webdav: allow specification of a different public_url than upload url
parent
368e847d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
11 deletions
+24
-11
conf/defaults.ini
+1
-0
conf/sample.ini
+1
-0
docs/sources/installation/configuration.md
+3
-0
pkg/components/imguploader/imguploader.go
+2
-1
pkg/components/imguploader/webdavuploader.go
+16
-9
pkg/components/imguploader/webdavuploader_test.go
+1
-1
No files found.
conf/defaults.ini
View file @
6d9e8bd1
...
...
@@ -444,3 +444,4 @@ secret_key =
url
=
username
=
password
=
public_url
=
conf/sample.ini
View file @
6d9e8bd1
...
...
@@ -399,5 +399,6 @@
[external_image_storage.webdav]
;url =
;public_url =
;username =
;password =
docs/sources/installation/configuration.md
View file @
6d9e8bd1
...
...
@@ -644,6 +644,9 @@ Secret key. e.g. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
### url
Url to where Grafana will send PUT request with images
### public_url
Url to send to users in notifications, directly appended with the resulting uploaded file name
### username
basic auth username
...
...
pkg/components/imguploader/imguploader.go
View file @
6d9e8bd1
...
...
@@ -47,10 +47,11 @@ func NewImageUploader() (ImageUploader, error) {
return
nil
,
fmt
.
Errorf
(
"Could not find url key for image.uploader.webdav"
)
}
public_url
:=
webdavSec
.
Key
(
"public_url"
)
.
String
()
username
:=
webdavSec
.
Key
(
"username"
)
.
String
()
password
:=
webdavSec
.
Key
(
"password"
)
.
String
()
return
NewWebdavImageUploader
(
url
,
username
,
password
)
return
NewWebdavImageUploader
(
url
,
username
,
password
,
public_url
)
}
return
NopImageUploader
{},
nil
...
...
pkg/components/imguploader/webdavuploader.go
View file @
6d9e8bd1
...
...
@@ -14,9 +14,10 @@ import (
)
type
WebdavUploader
struct
{
url
string
username
string
password
string
url
string
username
string
password
string
public_url
string
}
var
netTransport
=
&
http
.
Transport
{
...
...
@@ -33,7 +34,8 @@ var netClient = &http.Client{
func
(
u
*
WebdavUploader
)
Upload
(
pa
string
)
(
string
,
error
)
{
url
,
_
:=
url
.
Parse
(
u
.
url
)
url
.
Path
=
path
.
Join
(
url
.
Path
,
util
.
GetRandomString
(
20
)
+
".png"
)
filename
:=
util
.
GetRandomString
(
20
)
+
".png"
url
.
Path
=
path
.
Join
(
url
.
Path
,
filename
)
imgData
,
err
:=
ioutil
.
ReadFile
(
pa
)
req
,
err
:=
http
.
NewRequest
(
"PUT"
,
url
.
String
(),
bytes
.
NewReader
(
imgData
))
...
...
@@ -53,13 +55,18 @@ func (u *WebdavUploader) Upload(pa string) (string, error) {
return
""
,
fmt
.
Errorf
(
"Failed to upload image. Returned statuscode %v body %s"
,
res
.
StatusCode
,
body
)
}
return
url
.
String
(),
nil
if
u
.
public_url
!=
""
{
return
(
u
.
public_url
+
filename
),
nil
}
else
{
return
url
.
String
(),
nil
}
}
func
NewWebdavImageUploader
(
url
,
username
,
passw
rod
string
)
(
*
WebdavUploader
,
error
)
{
func
NewWebdavImageUploader
(
url
,
username
,
passw
ord
,
public_url
string
)
(
*
WebdavUploader
,
error
)
{
return
&
WebdavUploader
{
url
:
url
,
username
:
username
,
password
:
passwrod
,
url
:
url
,
username
:
username
,
password
:
password
,
public_url
:
public_url
,
},
nil
}
pkg/components/imguploader/webdavuploader_test.go
View file @
6d9e8bd1
...
...
@@ -7,7 +7,7 @@ import (
)
func
TestUploadToWebdav
(
t
*
testing
.
T
)
{
webdavUploader
,
_
:=
NewWebdavImageUploader
(
"http://localhost:9998/dav/"
,
"username"
,
"password"
)
webdavUploader
,
_
:=
NewWebdavImageUploader
(
"http://localhost:9998/dav/"
,
"username"
,
"password"
,
""
)
SkipConvey
(
"[Integration test] for external_image_store.webdav"
,
t
,
func
()
{
path
,
err
:=
webdavUploader
.
Upload
(
"../../../public/img/logo_transparent_400x.png"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment