mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use URLs in image annotations (#66804)
* use tokens or urls in image annotations * improve tests, fix some comments * fix empty tokens * code review changes, check for url before checking for token (support old token formats)
This commit is contained in:
@@ -20,6 +20,10 @@ type ImageStore interface {
|
||||
// if the image has expired or if an image with the token does not exist.
|
||||
GetImage(ctx context.Context, token string) (*models.Image, error)
|
||||
|
||||
// GetImageByURL looks for a image by its URL. It returns ErrImageNotFound
|
||||
// if the image has expired or if there is no image associated with the URL.
|
||||
GetImageByURL(ctx context.Context, url string) (*models.Image, error)
|
||||
|
||||
// GetImages returns all images that match the tokens. If one or more images
|
||||
// have expired or do not exist then it also returns the unmatched tokens
|
||||
// and an ErrImageNotFound error.
|
||||
@@ -54,6 +58,23 @@ func (st DBstore) GetImage(ctx context.Context, token string) (*models.Image, er
|
||||
return &image, nil
|
||||
}
|
||||
|
||||
func (st DBstore) GetImageByURL(ctx context.Context, url string) (*models.Image, error) {
|
||||
var image models.Image
|
||||
if err := st.SQLStore.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
exists, err := sess.Where("url = ? AND expires_at > ?", url, TimeNow().UTC()).Limit(1).Get(&image)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get image: %w", err)
|
||||
} else if !exists {
|
||||
return models.ErrImageNotFound
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &image, nil
|
||||
}
|
||||
|
||||
func (st DBstore) GetImages(ctx context.Context, tokens []string) ([]models.Image, []string, error) {
|
||||
var images []models.Image
|
||||
if err := st.SQLStore.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
|
||||
Reference in New Issue
Block a user