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.
|
2024-11-29 23:02:33 +08:00
|
|
|
Add(ctx context.Context, pluginID, version string, opts AddOpts) 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
|
2025-02-19 19:19:45 +08:00
|
|
|
DefaultSignature(ctx context.Context, pluginID string) (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
|
|
|
|
}
|
|
|
|
|
2024-11-29 23:02:33 +08:00
|
|
|
type AddOpts struct {
|
2023-05-30 17:48:52 +08:00
|
|
|
grafanaVersion string
|
|
|
|
|
|
|
|
os string
|
|
|
|
arch string
|
2024-11-29 23:02:33 +08:00
|
|
|
|
|
|
|
url string
|
2023-05-30 17:48:52 +08:00
|
|
|
}
|
|
|
|
|
2024-11-29 23:02:33 +08:00
|
|
|
func (co AddOpts) GrafanaVersion() string {
|
2023-05-30 17:48:52 +08:00
|
|
|
return co.grafanaVersion
|
|
|
|
}
|
|
|
|
|
2024-11-29 23:02:33 +08:00
|
|
|
func (co AddOpts) OS() string {
|
2023-05-30 17:48:52 +08:00
|
|
|
return co.os
|
|
|
|
}
|
|
|
|
|
2024-11-29 23:02:33 +08:00
|
|
|
func (co AddOpts) Arch() string {
|
2023-05-30 17:48:52 +08:00
|
|
|
return co.arch
|
|
|
|
}
|
|
|
|
|
2024-11-29 23:02:33 +08:00
|
|
|
func (co AddOpts) URL() string {
|
|
|
|
return co.url
|
2023-05-30 17:48:52 +08:00
|
|
|
}
|
|
|
|
|
2024-11-29 23:02:33 +08:00
|
|
|
func NewAddOpts(grafanaVersion, os, arch, url string) AddOpts {
|
|
|
|
return AddOpts{grafanaVersion: grafanaVersion, arch: arch, os: os, url: url}
|
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)
|
2024-08-21 16:46:41 +08:00
|
|
|
Rel(string) (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 {
|
2024-09-30 22:33:15 +08:00
|
|
|
backend.Handler
|
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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|