diff --git a/pkg/components/imguploader/gcsuploader.go b/pkg/components/imguploader/gcsuploader.go index 7194c0828bf..08ac64ec3de 100644 --- a/pkg/components/imguploader/gcsuploader.go +++ b/pkg/components/imguploader/gcsuploader.go @@ -4,12 +4,13 @@ import ( "context" "errors" "fmt" - "github.com/grafana/grafana/pkg/log" - "github.com/grafana/grafana/pkg/util" - "golang.org/x/oauth2/google" "io/ioutil" "net/http" "os" + + "github.com/grafana/grafana/pkg/log" + "github.com/grafana/grafana/pkg/util" + "golang.org/x/oauth2/google" ) type GCSUploader struct { @@ -26,12 +27,11 @@ func NewGCSUploader(keyFile, bucket string) *GCSUploader { } } -func (u *GCSUploader) Upload(imageDiskPath string) (string, error) { +func (u *GCSUploader) Upload(ctx context.Context, imageDiskPath string) (string, error) { key := util.GetRandomString(20) + ".png" log.Debug("Opening key file ", u.keyFile) - ctx := context.Background() data, err := ioutil.ReadFile(u.keyFile) if err != nil { return "", err diff --git a/pkg/components/imguploader/imguploader.go b/pkg/components/imguploader/imguploader.go index c7076afab02..32058e6cc2d 100644 --- a/pkg/components/imguploader/imguploader.go +++ b/pkg/components/imguploader/imguploader.go @@ -1,6 +1,7 @@ package imguploader import ( + "context" "fmt" "regexp" @@ -8,13 +9,13 @@ import ( ) type ImageUploader interface { - Upload(path string) (string, error) + Upload(ctx context.Context, path string) (string, error) } type NopImageUploader struct { } -func (NopImageUploader) Upload(path string) (string, error) { +func (NopImageUploader) Upload(ctx context.Context, path string) (string, error) { return "", nil } diff --git a/pkg/components/imguploader/s3uploader.go b/pkg/components/imguploader/s3uploader.go index 302420a27f4..a8694c0389c 100644 --- a/pkg/components/imguploader/s3uploader.go +++ b/pkg/components/imguploader/s3uploader.go @@ -1,6 +1,7 @@ package imguploader import ( + "context" "os" "time" @@ -34,7 +35,7 @@ func NewS3Uploader(region, bucket, acl, accessKey, secretKey string) *S3Uploader } } -func (u *S3Uploader) Upload(imageDiskPath string) (string, error) { +func (u *S3Uploader) Upload(ctx context.Context, imageDiskPath string) (string, error) { sess, err := session.NewSession() if err != nil { return "", err diff --git a/pkg/components/imguploader/webdavuploader.go b/pkg/components/imguploader/webdavuploader.go index 4a056e3a48a..01de7119756 100644 --- a/pkg/components/imguploader/webdavuploader.go +++ b/pkg/components/imguploader/webdavuploader.go @@ -2,6 +2,7 @@ package imguploader import ( "bytes" + "context" "fmt" "io/ioutil" "net" @@ -33,7 +34,7 @@ var netClient = &http.Client{ Transport: netTransport, } -func (u *WebdavUploader) Upload(pa string) (string, error) { +func (u *WebdavUploader) Upload(ctx context.Context, pa string) (string, error) { url, _ := url.Parse(u.url) filename := util.GetRandomString(20) + ".png" url.Path = path.Join(url.Path, filename) diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index cb612968b01..be74d41cc6c 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -100,7 +100,7 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) { context.ImageOnDiskPath = imagePath } - context.ImagePublicUrl, err = uploader.Upload(context.ImageOnDiskPath) + context.ImagePublicUrl, err = uploader.Upload(context.Ctx, context.ImageOnDiskPath) if err != nil { return err }