mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 22:57:16 +08:00

* Send new annotation containing image url * Use new image TokenProvider with TokenStore New abstraction GetImage no longer needs to support parsing both token and url from annotations, as remote AM will use the new URLProvider. Instead, we use the new generic TokenProvider and give it a TokenStore backed by the grafana database. That means we revert back to always using token simplifying code and security considerations. * Upgrade grafana/alerting to merged commit SHA
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
// ErrImageNotFound is returned when the image does not exist or is expired.
|
|
ErrImageNotFound = errors.New("image not found")
|
|
|
|
// ErrImageDataUnavailable is returned when image data is unavailable. Usually because the image is missing a path.
|
|
ErrImageDataUnavailable = errors.New("image data is unavailable")
|
|
)
|
|
|
|
type Image struct {
|
|
ID int64 `xorm:"pk autoincr 'id'"`
|
|
Token string `xorm:"token"`
|
|
Path string `xorm:"path"`
|
|
URL string `xorm:"url"`
|
|
CreatedAt time.Time `xorm:"created_at"`
|
|
ExpiresAt time.Time `xorm:"expires_at"`
|
|
}
|
|
|
|
// ExtendDuration extends the expiration time of the image. It can shorten
|
|
// the duration of the image if d is negative.
|
|
func (i *Image) ExtendDuration(d time.Duration) {
|
|
i.ExpiresAt = i.ExpiresAt.Add(d)
|
|
}
|
|
|
|
// HasExpired returns true if the image has expired.
|
|
func (i *Image) HasExpired() bool {
|
|
return timeNow().After(i.ExpiresAt)
|
|
}
|
|
|
|
// HasPath returns true if the image has a path on disk.
|
|
func (i *Image) HasPath() bool {
|
|
return i.Path != ""
|
|
}
|
|
|
|
// HasURL returns true if the image has a URL.
|
|
func (i *Image) HasURL() bool {
|
|
return i.URL != ""
|
|
}
|
|
|
|
// A XORM interface that defines the used table for this struct.
|
|
func (i *Image) TableName() string {
|
|
return "alert_image"
|
|
}
|