mirror of
https://github.com/grafana/grafana.git
synced 2024-12-28 01:41:24 -06:00
6dbe3b555f
Adding support for backend plugin client middlewares. This allows headers in outgoing backend plugin and HTTP requests to be modified using client middlewares. The following client middlewares added: Forward cookies: Will forward incoming HTTP request Cookies to outgoing plugins.Client and HTTP requests if the datasource has enabled forwarding of cookies (keepCookies). Forward OAuth token: Will set OAuth token headers on outgoing plugins.Client and HTTP requests if the datasource has enabled Forward OAuth Identity (oauthPassThru). Clear auth headers: Will clear any outgoing HTTP headers that was part of the incoming HTTP request and used when authenticating to Grafana. The current suggested way to register client middlewares is to have a separate package, pluginsintegration, responsible for bootstrap/instantiate the backend plugin client with middlewares and/or longer term bootstrap/instantiate plugin management. Fixes #54135 Related to #47734 Related to #57870 Related to #41623 Related to #57065
99 lines
2.7 KiB
Go
99 lines
2.7 KiB
Go
package plugins
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
)
|
|
|
|
// Store is the publicly accessible storage for plugins.
|
|
type Store interface {
|
|
// Plugin finds a plugin by its ID.
|
|
Plugin(ctx context.Context, pluginID string) (PluginDTO, bool)
|
|
// Plugins returns plugins by their requested type.
|
|
Plugins(ctx context.Context, pluginTypes ...Type) []PluginDTO
|
|
}
|
|
|
|
type Installer interface {
|
|
// Add adds a new plugin.
|
|
Add(ctx context.Context, pluginID, version string, opts CompatOpts) error
|
|
// Remove removes an existing plugin.
|
|
Remove(ctx context.Context, pluginID string) error
|
|
}
|
|
|
|
type PluginSource struct {
|
|
Class Class
|
|
Paths []string
|
|
}
|
|
|
|
type CompatOpts struct {
|
|
GrafanaVersion string
|
|
OS string
|
|
Arch string
|
|
}
|
|
|
|
type UpdateInfo struct {
|
|
PluginZipURL string
|
|
}
|
|
|
|
// Client is used to communicate with backend plugin implementations.
|
|
type Client interface {
|
|
backend.QueryDataHandler
|
|
backend.CheckHealthHandler
|
|
backend.StreamHandler
|
|
backend.CallResourceHandler
|
|
backend.CollectMetricsHandler
|
|
}
|
|
|
|
// BackendFactoryProvider provides a backend factory for a provided plugin.
|
|
type BackendFactoryProvider interface {
|
|
BackendFactory(ctx context.Context, p *Plugin) backendplugin.PluginFactoryFunc
|
|
}
|
|
|
|
type RendererManager interface {
|
|
// Renderer returns a renderer plugin.
|
|
Renderer(ctx context.Context) *Plugin
|
|
}
|
|
|
|
type SecretsPluginManager interface {
|
|
// SecretsManager returns a secretsmanager plugin
|
|
SecretsManager(ctx context.Context) *Plugin
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// RoleRegistry handles the plugin RBAC roles and their assignments
|
|
type RoleRegistry interface {
|
|
DeclarePluginRoles(ctx context.Context, ID, name string, registrations []RoleRegistration) error
|
|
}
|
|
|
|
// 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)
|
|
}
|