2021-03-12 11:26:07 -06:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:30:43 -05:00
|
|
|
type PluginSource struct {
|
|
|
|
Class Class
|
|
|
|
Paths []string
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|