forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterface.go
135 lines (111 loc) · 3.81 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package rendering
import (
"context"
"errors"
"time"
"github.com/grafana/grafana/pkg/apimachinery/errutil"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/org"
)
var ErrTimeout = errors.New("timeout error - you can set timeout in seconds with &timeout url parameter")
var ErrConcurrentLimitReached = errors.New("rendering concurrent limit reached")
var ErrRenderUnavailable = errors.New("rendering plugin not available")
var ErrServerTimeout = errutil.NewBase(errutil.StatusUnknown, "rendering.serverTimeout", errutil.WithPublicMessage("error trying to connect to image-renderer service"))
type RenderType string
const (
RenderCSV RenderType = "csv"
RenderPNG RenderType = "png"
RenderPDF RenderType = "pdf"
)
type TimeoutOpts struct {
Timeout time.Duration // Timeout param passed to image-renderer service
RequestTimeoutMultiplier time.Duration // RequestTimeoutMultiplier used for plugin/HTTP request context timeout
}
type AuthOpts struct {
OrgID int64
UserID int64
OrgRole org.RoleType
}
func getRequestTimeout(opt TimeoutOpts) time.Duration {
if opt.RequestTimeoutMultiplier == 0 {
return opt.Timeout * 2 // default
}
return opt.Timeout * opt.RequestTimeoutMultiplier
}
type CommonOpts struct {
TimeoutOpts
AuthOpts
Path string
Timezone string
ConcurrentLimit int
Headers map[string][]string
}
type CSVOpts struct {
CommonOpts
}
type Opts struct {
CommonOpts
ErrorOpts
Width int
Height int
DeviceScaleFactor float64
Theme models.Theme
}
type ErrorOpts struct {
// ErrorConcurrentLimitReached returns an ErrConcurrentLimitReached
// error instead of a rendering limit exceeded image.
ErrorConcurrentLimitReached bool
// ErrorRenderUnavailable returns an ErrRunderUnavailable error
// instead of a rendering unavailable image.
ErrorRenderUnavailable bool
}
type SanitizeSVGRequest struct {
Filename string
Content []byte
}
type SanitizeSVGResponse struct {
Sanitized []byte
}
type Result struct {
FilePath string
FileName string
}
type RenderResult struct {
FilePath string
}
type RenderCSVResult struct {
FilePath string
FileName string
}
type renderFunc func(ctx context.Context, renderType RenderType, renderKey string, options Opts) (*RenderResult, error)
type renderCSVFunc func(ctx context.Context, renderKey string, options CSVOpts) (*RenderCSVResult, error)
type sanitizeFunc func(ctx context.Context, req *SanitizeSVGRequest) (*SanitizeSVGResponse, error)
type renderKeyProvider interface {
get(ctx context.Context, opts AuthOpts) (string, error)
afterRequest(ctx context.Context, opts AuthOpts, renderKey string)
}
type SessionOpts struct {
Expiry time.Duration
RefreshExpiryOnEachRequest bool
}
type Session interface {
renderKeyProvider
Dispose(ctx context.Context)
}
type CapabilitySupportRequestResult struct {
IsSupported bool
SemverConstraint string
}
//go:generate mockgen -destination=mock.go -package=rendering github.com/grafana/grafana/pkg/services/rendering Service
type Service interface {
IsAvailable(ctx context.Context) bool
Version() string
Render(ctx context.Context, renderType RenderType, opts Opts, session Session) (*RenderResult, error)
RenderCSV(ctx context.Context, opts CSVOpts, session Session) (*RenderCSVResult, error)
RenderErrorImage(theme models.Theme, error error) (*RenderResult, error)
GetRenderUser(ctx context.Context, key string) (*RenderUser, bool)
HasCapability(ctx context.Context, capability CapabilityName) (CapabilitySupportRequestResult, error)
IsCapabilitySupported(ctx context.Context, capability CapabilityName) error
CreateRenderingSession(ctx context.Context, authOpts AuthOpts, sessionOpts SessionOpts) (Session, error)
SanitizeSVG(ctx context.Context, req *SanitizeSVGRequest) (*SanitizeSVGResponse, error)
}