Documentation
¶
Index ¶
- Constants
- Variables
- func GetImageToken(alert types.Alert) string
- func GetImageURL(alert types.Alert) string
- func WithStoredImages(ctx context.Context, l logging.Logger, imageProvider Provider, ...) error
- type FakeTokenStore
- type Image
- type ImageContent
- type Provider
- type TokenProvider
- type TokenStore
- type URLProvider
- type UnavailableProvider
Constants ¶
const ( // ProviderTimeout should be used by all callers for calles to `Images` ProviderTimeout = 500 * time.Millisecond )
Variables ¶
var ( ErrImageNotFound = errors.New("image not found") // ErrImagesDone is used to stop iteration of subsequent images. It should be // returned from forEachFunc when either the intended image has been found or // the maximum number of images has been iterated. ErrImagesDone = errors.New("images done") )
var ErrImageUploadNotSupported = errors.New("image upload is not supported")
ErrImageUploadNotSupported is returned when image uploading is not supported.
Functions ¶
func GetImageToken ¶
GetImageToken is a helper function to retrieve the image token from the alert annotations.
func GetImageURL ¶
GetImageURL is a helper function to retrieve the image url from the alert annotations.
func WithStoredImages ¶
func WithStoredImages(ctx context.Context, l logging.Logger, imageProvider Provider, forEachFunc forEachImageFunc, alerts ...*types.Alert) error
WithStoredImages retrieves the image for each alert and then calls forEachFunc with the index of the alert and the retrieved image struct. If the alert does not have an image then forEachFunc will not be called for that alert. If forEachFunc returns an error, WithStoredImages will return the error and not iterate the remaining alerts. A forEachFunc can return ErrImagesDone to stop the iteration of remaining alerts if the intended image or maximum number of images have been found.
Types ¶
type FakeTokenStore ¶
func NewFakeTokenStore ¶
func NewFakeTokenStore(n int) *FakeTokenStore
NewFakeTokenStore returns an token store with N test images. Each image has a URL, but does not have a file on disk. They are mapped to the token test-image-%d
func NewFakeTokenStoreFromImages ¶
func NewFakeTokenStoreFromImages(images map[string]*Image) *FakeTokenStore
func NewFakeTokenStoreWithFile ¶
func NewFakeTokenStoreWithFile(t *testing.T, n int) *FakeTokenStore
NewFakeTokenStoreWithFile returns an image provider with N test images. Each image has a URL and raw data. They are mapped to the token test-image-%d
type Image ¶
type Image struct { // URL is the public URL of the image. This URL should not be treated as a trusted source and should not be // downloaded directly. RawData should be used to retrieve the image data. URL string // RawData returns the raw image data. Depending on the provider, this may be a file read, a network request, or // unsupported. It's the responsibility of the Provider to ensure that the data is safe to read. RawData func(ctx context.Context) (ImageContent, error) }
type ImageContent ¶
type Provider ¶
type Provider interface { // GetImage takes an alert and returns its associated image. GetImage(ctx context.Context, alert types.Alert) (*Image, error) }
func NewFakeProvider ¶
func NewTokenProvider ¶
func NewTokenProvider(store TokenStore, logger logging.Logger) Provider
type TokenProvider ¶
type TokenProvider struct {
// contains filtered or unexported fields
}
TokenProvider implements the ImageProvider interface, retrieving images from a store using tokens. Image data should be considered trusted as the stored image URL and content are not user-modifiable.
type TokenStore ¶
type URLProvider ¶
type URLProvider struct{}
URLProvider is a provider that stores a direct reference to an image's public URL in an alert's annotations. The URL is not validated against a database record, so retrieving raw image data is blocked in an attempt to prevent malicious access to untrusted URLs.