mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
[GCS] Support for gcs path
This commit is contained in:
parent
6595be95eb
commit
767b460ff1
@ -495,3 +495,4 @@ public_url =
|
||||
[external_image_storage.gcs]
|
||||
key_file =
|
||||
bucket =
|
||||
path =
|
@ -438,3 +438,4 @@ log_queries =
|
||||
[external_image_storage.gcs]
|
||||
;key_file =
|
||||
;bucket =
|
||||
;path =
|
@ -778,6 +778,9 @@ Service Account should have "Storage Object Writer" role.
|
||||
### bucket name
|
||||
Bucket Name on Google Cloud Storage.
|
||||
|
||||
### path
|
||||
Optional extra path inside bucket
|
||||
|
||||
## [alerting]
|
||||
|
||||
### enabled
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@ -20,19 +21,22 @@ const (
|
||||
type GCSUploader struct {
|
||||
keyFile string
|
||||
bucket string
|
||||
path string
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func NewGCSUploader(keyFile, bucket string) *GCSUploader {
|
||||
func NewGCSUploader(keyFile, bucket, path string) *GCSUploader {
|
||||
return &GCSUploader{
|
||||
keyFile: keyFile,
|
||||
bucket: bucket,
|
||||
path: path,
|
||||
log: log.New("gcsuploader"),
|
||||
}
|
||||
}
|
||||
|
||||
func (u *GCSUploader) Upload(ctx context.Context, imageDiskPath string) (string, error) {
|
||||
key := util.GetRandomString(20) + ".png"
|
||||
fileName := util.GetRandomString(20) + ".png"
|
||||
key := path.Join(u.path, fileName)
|
||||
|
||||
u.log.Debug("Opening key file ", u.keyFile)
|
||||
data, err := ioutil.ReadFile(u.keyFile)
|
||||
|
@ -73,8 +73,9 @@ func NewImageUploader() (ImageUploader, error) {
|
||||
|
||||
keyFile := gcssec.Key("key_file").MustString("")
|
||||
bucketName := gcssec.Key("bucket").MustString("")
|
||||
path := gcssec.Key("path").MustString("")
|
||||
|
||||
return NewGCSUploader(keyFile, bucketName), nil
|
||||
return NewGCSUploader(keyFile, bucketName, path), nil
|
||||
}
|
||||
|
||||
return NopImageUploader{}, nil
|
||||
|
Loading…
Reference in New Issue
Block a user