2021-03-12 11:26:07 -06:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-07 09:47:02 -06:00
|
|
|
"io/fs"
|
2023-03-29 05:55:55 -05:00
|
|
|
"time"
|
2021-03-12 11:26:07 -06:00
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
2021-03-12 11:26:07 -06:00
|
|
|
)
|
|
|
|
|
2022-10-27 11:44:28 -05:00
|
|
|
// Store is the publicly accessible storage for plugins.
|
2021-11-01 04:53:33 -05:00
|
|
|
type Store interface {
|
|
|
|
// Plugin finds a plugin by its ID.
|
2021-11-17 05:04:22 -06:00
|
|
|
Plugin(ctx context.Context, pluginID string) (PluginDTO, bool)
|
2021-11-01 04:53:33 -05:00
|
|
|
// Plugins returns plugins by their requested type.
|
2021-11-17 05:04:22 -06:00
|
|
|
Plugins(ctx context.Context, pluginTypes ...Type) []PluginDTO
|
2022-06-07 10:51:00 -05:00
|
|
|
}
|
|
|
|
|
2022-09-23 07:27:01 -05:00
|
|
|
type Installer interface {
|
|
|
|
// Add adds a new plugin.
|
2022-08-23 04:50:50 -05:00
|
|
|
Add(ctx context.Context, pluginID, version string, opts CompatOpts) error
|
2022-09-23 07:27:01 -05:00
|
|
|
// Remove removes an existing plugin.
|
2021-11-01 04:53:33 -05:00
|
|
|
Remove(ctx context.Context, pluginID string) error
|
|
|
|
}
|
|
|
|
|
2023-03-20 08:35:49 -05:00
|
|
|
type PluginSource interface {
|
|
|
|
PluginClass(ctx context.Context) Class
|
|
|
|
PluginURIs(ctx context.Context) []string
|
|
|
|
DefaultSignature(ctx context.Context) (Signature, bool)
|
2022-08-30 10:30:43 -05:00
|
|
|
}
|
|
|
|
|
2023-03-29 05:55:55 -05:00
|
|
|
type FileStore interface {
|
|
|
|
// File retrieves a plugin file.
|
|
|
|
File(ctx context.Context, pluginID, filename string) (*File, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type File struct {
|
|
|
|
Content []byte
|
|
|
|
ModTime time.Time
|
|
|
|
}
|
|
|
|
|
2022-08-23 04:50:50 -05:00
|
|
|
type CompatOpts struct {
|
|
|
|
GrafanaVersion string
|
|
|
|
OS string
|
|
|
|
Arch string
|
|
|
|
}
|
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
type UpdateInfo struct {
|
|
|
|
PluginZipURL string
|
|
|
|
}
|
|
|
|
|
2023-03-07 09:47:02 -06:00
|
|
|
type FS interface {
|
|
|
|
fs.FS
|
|
|
|
|
|
|
|
Base() string
|
|
|
|
Files() []string
|
|
|
|
}
|
|
|
|
|
2023-04-20 04:52:59 -05:00
|
|
|
type FSRemover interface {
|
|
|
|
Remove() error
|
|
|
|
}
|
|
|
|
|
2023-03-07 09:47:02 -06:00
|
|
|
type FoundBundle struct {
|
|
|
|
Primary FoundPlugin
|
|
|
|
Children []*FoundPlugin
|
|
|
|
}
|
|
|
|
|
|
|
|
type FoundPlugin struct {
|
|
|
|
JSONData JSONData
|
|
|
|
FS FS
|
|
|
|
}
|
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
// Client is used to communicate with backend plugin implementations.
|
|
|
|
type Client interface {
|
|
|
|
backend.QueryDataHandler
|
|
|
|
backend.CheckHealthHandler
|
2021-11-15 07:25:13 -06:00
|
|
|
backend.StreamHandler
|
2021-12-14 04:15:49 -06:00
|
|
|
backend.CallResourceHandler
|
2022-02-09 10:36:53 -06:00
|
|
|
backend.CollectMetricsHandler
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
|
2022-01-14 06:30:39 -06:00
|
|
|
// BackendFactoryProvider provides a backend factory for a provided plugin.
|
|
|
|
type BackendFactoryProvider interface {
|
|
|
|
BackendFactory(ctx context.Context, p *Plugin) backendplugin.PluginFactoryFunc
|
|
|
|
}
|
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
type RendererManager interface {
|
|
|
|
// Renderer returns a renderer plugin.
|
2022-09-02 07:20:10 -05:00
|
|
|
Renderer(ctx context.Context) *Plugin
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
|
2022-06-09 12:19:27 -05:00
|
|
|
type SecretsPluginManager interface {
|
|
|
|
// SecretsManager returns a secretsmanager plugin
|
2022-09-02 07:20:10 -05:00
|
|
|
SecretsManager(ctx context.Context) *Plugin
|
2022-06-09 12:19:27 -05:00
|
|
|
}
|
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
type StaticRouteResolver interface {
|
|
|
|
Routes() []*StaticRoute
|
|
|
|
}
|
|
|
|
|
|
|
|
type ErrorResolver interface {
|
|
|
|
PluginErrors() []*Error
|
|
|
|
}
|
|
|
|
|
|
|
|
type PluginLoaderAuthorizer interface {
|
|
|
|
// CanLoadPlugin confirms if a plugin is authorized to load
|
|
|
|
CanLoadPlugin(plugin *Plugin) bool
|
|
|
|
}
|
2022-11-07 04:30:45 -06:00
|
|
|
|
2023-01-18 11:02:54 -06:00
|
|
|
type Licensing interface {
|
|
|
|
Environment() []string
|
|
|
|
|
|
|
|
Edition() string
|
|
|
|
|
|
|
|
Path() string
|
2023-03-08 11:44:04 -06:00
|
|
|
|
|
|
|
AppURL() string
|
2023-01-18 11:02:54 -06:00
|
|
|
}
|
|
|
|
|
2022-11-07 04:30:45 -06:00
|
|
|
// RoleRegistry handles the plugin RBAC roles and their assignments
|
|
|
|
type RoleRegistry interface {
|
|
|
|
DeclarePluginRoles(ctx context.Context, ID, name string, registrations []RoleRegistration) error
|
|
|
|
}
|
2022-12-01 12:08:36 -06: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 09:12:05 -05:00
|
|
|
|
|
|
|
type FeatureToggles interface {
|
|
|
|
IsEnabled(flag string) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type SignatureCalculator interface {
|
|
|
|
Calculate(ctx context.Context, src PluginSource, plugin FoundPlugin) (Signature, error)
|
|
|
|
}
|
2023-04-25 06:01:49 -05:00
|
|
|
|
|
|
|
type KeyStore interface {
|
|
|
|
Get(ctx context.Context, key string) (string, bool, error)
|
|
|
|
Set(ctx context.Context, key string, value string) error
|
|
|
|
Del(ctx context.Context, key string) error
|
|
|
|
ListKeys(ctx context.Context) ([]string, error)
|
|
|
|
GetLastUpdated(ctx context.Context) (*time.Time, error)
|
|
|
|
SetLastUpdated(ctx context.Context) error
|
|
|
|
}
|