2021-03-13 01:26:07 +08:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-07 23:47:02 +08:00
|
|
|
"io/fs"
|
2023-03-29 18:55:55 +08:00
|
|
|
"time"
|
2021-03-13 01:26:07 +08:00
|
|
|
|
2021-11-01 17:53:33 +08:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
2021-03-13 01:26:07 +08:00
|
|
|
)
|
|
|
|
|
2022-09-23 20:27:01 +08:00
|
|
|
type Installer interface {
|
|
|
|
// Add adds a new plugin.
|
2022-08-23 17:50:50 +08:00
|
|
|
Add(ctx context.Context, pluginID, version string, opts CompatOpts) error
|
2022-09-23 20:27:01 +08:00
|
|
|
// Remove removes an existing plugin.
|
2024-02-12 19:47:49 +08:00
|
|
|
Remove(ctx context.Context, pluginID, version string) error
|
2021-11-01 17:53:33 +08:00
|
|
|
}
|
|
|
|
|
2023-03-20 21:35:49 +08:00
|
|
|
type PluginSource interface {
|
|
|
|
PluginClass(ctx context.Context) Class
|
|
|
|
PluginURIs(ctx context.Context) []string
|
|
|
|
DefaultSignature(ctx context.Context) (Signature, bool)
|
2022-08-30 23:30:43 +08:00
|
|
|
}
|
|
|
|
|
2023-03-29 18:55:55 +08:00
|
|
|
type FileStore interface {
|
|
|
|
// File retrieves a plugin file.
|
2024-02-12 19:47:49 +08:00
|
|
|
File(ctx context.Context, pluginID, pluginVersion, filename string) (*File, error)
|
2023-03-29 18:55:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type File struct {
|
|
|
|
Content []byte
|
|
|
|
ModTime time.Time
|
|
|
|
}
|
|
|
|
|
2022-08-23 17:50:50 +08:00
|
|
|
type CompatOpts struct {
|
2023-05-30 17:48:52 +08:00
|
|
|
grafanaVersion string
|
|
|
|
|
|
|
|
os string
|
|
|
|
arch string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (co CompatOpts) GrafanaVersion() string {
|
|
|
|
return co.grafanaVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
func (co CompatOpts) OS() string {
|
|
|
|
return co.os
|
|
|
|
}
|
|
|
|
|
|
|
|
func (co CompatOpts) Arch() string {
|
|
|
|
return co.arch
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCompatOpts(grafanaVersion, os, arch string) CompatOpts {
|
|
|
|
return CompatOpts{grafanaVersion: grafanaVersion, arch: arch, os: os}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSystemCompatOpts(os, arch string) CompatOpts {
|
|
|
|
return CompatOpts{arch: arch, os: os}
|
2022-08-23 17:50:50 +08:00
|
|
|
}
|
|
|
|
|
2021-11-01 17:53:33 +08:00
|
|
|
type UpdateInfo struct {
|
|
|
|
PluginZipURL string
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:47:02 +08:00
|
|
|
type FS interface {
|
|
|
|
fs.FS
|
|
|
|
|
|
|
|
Base() string
|
2023-04-27 16:26:15 +08:00
|
|
|
Files() ([]string, error)
|
2023-03-07 23:47:02 +08:00
|
|
|
}
|
|
|
|
|
2023-04-20 17:52:59 +08:00
|
|
|
type FSRemover interface {
|
|
|
|
Remove() error
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:47:02 +08:00
|
|
|
type FoundBundle struct {
|
|
|
|
Primary FoundPlugin
|
|
|
|
Children []*FoundPlugin
|
|
|
|
}
|
|
|
|
|
|
|
|
type FoundPlugin struct {
|
|
|
|
JSONData JSONData
|
|
|
|
FS FS
|
|
|
|
}
|
|
|
|
|
2021-11-01 17:53:33 +08:00
|
|
|
// Client is used to communicate with backend plugin implementations.
|
|
|
|
type Client interface {
|
|
|
|
backend.QueryDataHandler
|
|
|
|
backend.CheckHealthHandler
|
2021-11-15 21:25:13 +08:00
|
|
|
backend.StreamHandler
|
2024-05-24 23:45:16 +08:00
|
|
|
backend.AdmissionHandler
|
2024-08-16 04:02:21 +08:00
|
|
|
backend.ConversionHandler
|
2021-12-14 18:15:49 +08:00
|
|
|
backend.CallResourceHandler
|
2022-02-10 00:36:53 +08:00
|
|
|
backend.CollectMetricsHandler
|
2021-11-01 17:53:33 +08:00
|
|
|
}
|
|
|
|
|
2022-01-14 20:30:39 +08:00
|
|
|
// BackendFactoryProvider provides a backend factory for a provided plugin.
|
|
|
|
type BackendFactoryProvider interface {
|
|
|
|
BackendFactory(ctx context.Context, p *Plugin) backendplugin.PluginFactoryFunc
|
|
|
|
}
|
|
|
|
|
2022-06-10 01:19:27 +08:00
|
|
|
type SecretsPluginManager interface {
|
|
|
|
// SecretsManager returns a secretsmanager plugin
|
2022-09-02 20:20:10 +08:00
|
|
|
SecretsManager(ctx context.Context) *Plugin
|
2022-06-10 01:19:27 +08:00
|
|
|
}
|
|
|
|
|
2021-11-01 17:53:33 +08:00
|
|
|
type StaticRouteResolver interface {
|
2023-08-10 16:32:12 +08:00
|
|
|
Routes(ctx context.Context) []*StaticRoute
|
2021-11-01 17:53:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type ErrorResolver interface {
|
2023-08-10 16:32:12 +08:00
|
|
|
PluginErrors(ctx context.Context) []*Error
|
2024-04-18 20:29:02 +08:00
|
|
|
PluginError(ctx context.Context, pluginID string) *Error
|
2021-11-01 17:53:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type PluginLoaderAuthorizer interface {
|
|
|
|
// CanLoadPlugin confirms if a plugin is authorized to load
|
|
|
|
CanLoadPlugin(plugin *Plugin) bool
|
|
|
|
}
|
2022-11-07 18:30:45 +08:00
|
|
|
|
2023-01-19 01:02:54 +08:00
|
|
|
type Licensing interface {
|
|
|
|
Environment() []string
|
|
|
|
|
|
|
|
Edition() string
|
|
|
|
|
|
|
|
Path() string
|
2023-03-09 01:44:04 +08:00
|
|
|
|
|
|
|
AppURL() string
|
2023-01-19 01:02:54 +08:00
|
|
|
}
|
|
|
|
|
2022-12-02 02:08:36 +08:00
|
|
|
// ClientMiddleware is an interface representing the ability to create a middleware
|
|
|
|
// that implements the Client interface.
|
|
|
|
type ClientMiddleware interface {
|
|
|
|
// CreateClientMiddleware creates a new client middleware.
|
|
|
|
CreateClientMiddleware(next Client) Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// The ClientMiddlewareFunc type is an adapter to allow the use of ordinary
|
|
|
|
// functions as ClientMiddleware's. If f is a function with the appropriate
|
|
|
|
// signature, ClientMiddlewareFunc(f) is a ClientMiddleware that calls f.
|
|
|
|
type ClientMiddlewareFunc func(next Client) Client
|
|
|
|
|
|
|
|
// CreateClientMiddleware implements the ClientMiddleware interface.
|
|
|
|
func (fn ClientMiddlewareFunc) CreateClientMiddleware(next Client) Client {
|
|
|
|
return fn(next)
|
|
|
|
}
|
2023-04-18 22:12:05 +08:00
|
|
|
|
|
|
|
type SignatureCalculator interface {
|
|
|
|
Calculate(ctx context.Context, src PluginSource, plugin FoundPlugin) (Signature, error)
|
|
|
|
}
|
2023-04-25 19:01:49 +08:00
|
|
|
|
|
|
|
type KeyStore interface {
|
|
|
|
Get(ctx context.Context, key string) (string, bool, error)
|
2023-09-05 22:20:42 +08:00
|
|
|
Set(ctx context.Context, key string, value any) error
|
|
|
|
Delete(ctx context.Context, key string) error
|
2023-04-25 19:01:49 +08:00
|
|
|
ListKeys(ctx context.Context) ([]string, error)
|
2023-09-05 22:20:42 +08:00
|
|
|
GetLastUpdated(ctx context.Context) (time.Time, error)
|
2023-04-25 19:01:49 +08:00
|
|
|
SetLastUpdated(ctx context.Context) error
|
|
|
|
}
|
2023-04-27 23:54:28 +08:00
|
|
|
|
|
|
|
type KeyRetriever interface {
|
|
|
|
GetPublicKey(ctx context.Context, keyID string) (string, error)
|
|
|
|
}
|