plugins

package
v0.0.0-testrgm4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2023 License: AGPL-3.0 Imports: 19 Imported by: 1,232

Documentation

Index

Constants

View Source
const (
	TypeDashboard = "dashboard"
)

Variables

View Source
var (
	// ErrPluginNotRegistered error returned when a plugin is not registered.
	ErrPluginNotRegistered = errutil.NewBase(errutil.StatusNotFound, "plugin.notRegistered")
	// ErrHealthCheckFailed error returned when a plugin health check failed.
	ErrHealthCheckFailed = errutil.NewBase(errutil.StatusInternal, "plugin.failedHealthCheck")
	// ErrPluginUnavailable error returned when a plugin is unavailable.
	ErrPluginUnavailable = errutil.NewBase(errutil.StatusInternal, "plugin.unavailable")
	// ErrMethodNotImplemented error returned when a plugin method is not implemented.
	ErrMethodNotImplemented = errutil.NewBase(errutil.StatusNotImplemented, "plugin.notImplemented")
	// ErrPluginDownstreamError error returned when a plugin method is not implemented.
	ErrPluginDownstreamError = errutil.NewBase(errutil.StatusInternal, "plugin.downstreamError", errutil.WithPublicMessage("An error occurred within the plugin"))
)
View Source
var (
	ErrInstallCorePlugin   = errors.New("cannot install a Core plugin")
	ErrUninstallCorePlugin = errors.New("cannot uninstall a Core plugin")
	ErrPluginNotInstalled  = errors.New("plugin is not installed")
)
View Source
var (
	ErrFileNotExist   = errors.New("file does not exist")
	ErrPluginFileRead = errors.New("file could not be read")
)

Functions

This section is empty.

Types

type AppDTO

type AppDTO struct {
	ID      string `json:"id"`
	Path    string `json:"path"`
	Version string `json:"version"`
	Preload bool   `json:"preload"`
}

type BackendFactoryProvider

type BackendFactoryProvider interface {
	BackendFactory(ctx context.Context, p *Plugin) backendplugin.PluginFactoryFunc
}

BackendFactoryProvider provides a backend factory for a provided plugin.

type BuildInfo

type BuildInfo struct {
	Time   int64  `json:"time,omitempty"`
	Repo   string `json:"repo,omitempty"`
	Branch string `json:"branch,omitempty"`
	Hash   string `json:"hash,omitempty"`
}

type Class

type Class string
const (
	Core     Class = "core"
	Bundled  Class = "bundled"
	External Class = "external"
)

func (Class) String

func (c Class) String() string

type Client

Client is used to communicate with backend plugin implementations.

type ClientMiddleware

type ClientMiddleware interface {
	// CreateClientMiddleware creates a new client middleware.
	CreateClientMiddleware(next Client) Client
}

ClientMiddleware is an interface representing the ability to create a middleware that implements the Client interface.

type ClientMiddlewareFunc

type ClientMiddlewareFunc func(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.

func (ClientMiddlewareFunc) CreateClientMiddleware

func (fn ClientMiddlewareFunc) CreateClientMiddleware(next Client) Client

CreateClientMiddleware implements the ClientMiddleware interface.

type CompatOpts

type CompatOpts struct {
	GrafanaVersion string
	OS             string
	Arch           string
}

type DataSourceDTO

type DataSourceDTO struct {
	ID         int64                  `json:"id,omitempty"`
	UID        string                 `json:"uid,omitempty"`
	Type       string                 `json:"type"`
	Name       string                 `json:"name"`
	PluginMeta *PluginMetaDTO         `json:"meta"`
	URL        string                 `json:"url,omitempty"`
	IsDefault  bool                   `json:"isDefault"`
	Access     string                 `json:"access,omitempty"`
	Preload    bool                   `json:"preload"`
	Module     string                 `json:"module,omitempty"`
	JSONData   map[string]interface{} `json:"jsonData"`
	ReadOnly   bool                   `json:"readOnly"`

	BasicAuth       string `json:"basicAuth,omitempty"`
	WithCredentials bool   `json:"withCredentials,omitempty"`

	// This is populated by an Enterprise hook
	CachingConfig QueryCachingConfig `json:"cachingConfig,omitempty"`

	// InfluxDB
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`

	// InfluxDB + Elasticsearch
	Database string `json:"database,omitempty"`

	// Prometheus
	DirectURL string `json:"directUrl,omitempty"`
}

type Dependencies

type Dependencies struct {
	GrafanaDependency string       `json:"grafanaDependency"`
	GrafanaVersion    string       `json:"grafanaVersion"`
	Plugins           []Dependency `json:"plugins"`
}

type Dependency

type Dependency struct {
	ID      string `json:"id"`
	Type    string `json:"type"`
	Name    string `json:"name"`
	Version string `json:"version"`
}

type DuplicateError

type DuplicateError struct {
	PluginID string
}

func (DuplicateError) Error

func (e DuplicateError) Error() string

func (DuplicateError) Is

func (e DuplicateError) Is(err error) bool

type Error

type Error struct {
	ErrorCode `json:"errorCode"`
	PluginID  string `json:"pluginId,omitempty"`
}

type ErrorCode

type ErrorCode string

type ErrorResolver

type ErrorResolver interface {
	PluginErrors() []*Error
}

type FS

type FS interface {
	fs.FS

	Base() string
	Files() []string
}

type FakePluginStore

type FakePluginStore struct {
	Store

	PluginList []PluginDTO
}

func (FakePluginStore) Plugin

func (pr FakePluginStore) Plugin(_ context.Context, pluginID string) (PluginDTO, bool)

func (FakePluginStore) Plugins

func (pr FakePluginStore) Plugins(_ context.Context, pluginTypes ...Type) []PluginDTO

type File

type File struct {
	Content []byte
	ModTime time.Time
}

type FileStore

type FileStore interface {
	// File retrieves a plugin file.
	File(ctx context.Context, pluginID, filename string) (*File, error)
}

type FoundBundle

type FoundBundle struct {
	Primary  FoundPlugin
	Children []*FoundPlugin
}

type FoundPlugin

type FoundPlugin struct {
	JSONData JSONData
	FS       FS
}
type Header struct {
	Name    string `json:"name"`
	Content string `json:"content"`
}

Header describes an HTTP header that is forwarded with the proxied request for a plugin route

type Includes

type Includes struct {
	Name       string       `json:"name"`
	Path       string       `json:"path"`
	Type       string       `json:"type"`
	Component  string       `json:"component"`
	Role       org.RoleType `json:"role"`
	Action     string       `json:"action,omitempty"`
	AddToNav   bool         `json:"addToNav"`
	DefaultNav bool         `json:"defaultNav"`
	Slug       string       `json:"slug"`
	Icon       string       `json:"icon"`
	UID        string       `json:"uid"`

	ID string `json:"-"`
}

func (Includes) DashboardURLPath

func (e Includes) DashboardURLPath() string

func (Includes) RequiresRBACAction

func (e Includes) RequiresRBACAction() bool

type Info

type Info struct {
	Author      InfoLink      `json:"author"`
	Description string        `json:"description"`
	Links       []InfoLink    `json:"links"`
	Logos       Logos         `json:"logos"`
	Build       BuildInfo     `json:"build"`
	Screenshots []Screenshots `json:"screenshots"`
	Version     string        `json:"version"`
	Updated     string        `json:"updated"`
}
type InfoLink struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

type Installer

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 JSONData

type JSONData struct {
	// Common settings
	ID           string       `json:"id"`
	Type         Type         `json:"type"`
	Name         string       `json:"name"`
	Info         Info         `json:"info"`
	Dependencies Dependencies `json:"dependencies"`
	Includes     []*Includes  `json:"includes"`
	State        ReleaseState `json:"state,omitempty"`
	Category     string       `json:"category"`
	HideFromList bool         `json:"hideFromList,omitempty"`
	Preload      bool         `json:"preload"`
	Backend      bool         `json:"backend"`
	Routes       []*Route     `json:"routes"`

	// AccessControl settings
	Roles []RoleRegistration `json:"roles,omitempty"`

	// Panel settings
	SkipDataQuery bool `json:"skipDataQuery"`

	// App settings
	AutoEnabled bool `json:"autoEnabled"`

	// Datasource settings
	Annotations  bool            `json:"annotations"`
	Metrics      bool            `json:"metrics"`
	Alerting     bool            `json:"alerting"`
	Explore      bool            `json:"explore"`
	Table        bool            `json:"tables"`
	Logs         bool            `json:"logs"`
	Tracing      bool            `json:"tracing"`
	QueryOptions map[string]bool `json:"queryOptions,omitempty"`
	BuiltIn      bool            `json:"builtIn,omitempty"`
	Mixed        bool            `json:"mixed,omitempty"`
	Streaming    bool            `json:"streaming"`
	SDK          bool            `json:"sdk,omitempty"`

	// Backend (Datasource + Renderer + SecretsManager)
	Executable string `json:"executable,omitempty"`
}

JSONData represents the plugin's plugin.json

func (JSONData) DashboardIncludes

func (d JSONData) DashboardIncludes() []*Includes

type JWTTokenAuth

type JWTTokenAuth struct {
	Url    string            `json:"url"`
	Scopes []string          `json:"scopes"`
	Params map[string]string `json:"params"`
}

JWTTokenAuth struct is both for normal Token Auth and JWT Token Auth with an uploaded JWT file.

type Licensing

type Licensing interface {
	Environment() []string

	Edition() string

	Path() string

	AppURL() string
}

type LocalFS

type LocalFS struct {
	// contains filtered or unexported fields
}

LocalFS is a plugins.FS that allows accessing files on the local file system.

func NewLocalFS

func NewLocalFS(m map[string]struct{}, basePath string) LocalFS

NewLocalFS returns a new LocalFS that can access the specified files in the specified base path. Both the map keys and basePath should use the os-specific path separator for Open() to work properly.

func (LocalFS) Base

func (f LocalFS) Base() string

Base returns the base path for the LocalFS.

func (LocalFS) Files

func (f LocalFS) Files() []string

Files returns a slice of all the file paths in the LocalFS relative to the base path. The returned strings use the same path separator as the

func (LocalFS) Open

func (f LocalFS) Open(name string) (fs.File, error)

Open opens the specified file on the local filesystem, and returns the corresponding fs.File. If a nil error is returned, the caller should take care of closing the returned file.

type LocalFile

type LocalFile struct {
	// contains filtered or unexported fields
}

LocalFile implements a fs.File for accessing the local filesystem.

func (*LocalFile) Close

func (p *LocalFile) Close() error

Close closes the file. If the file was never open, nil is returned. If the file is already closed, an error is returned.

func (*LocalFile) Read

func (p *LocalFile) Read(b []byte) (int, error)

Read reads up to len(b) bytes from the File and stores them in b. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF. If the file is already open, it is opened again, without closing it first. The file is not closed at the end of the read operation. If a non-nil error is returned, it must be manually closed by the caller by calling Close().

func (*LocalFile) Stat

func (p *LocalFile) Stat() (fs.FileInfo, error)

Stat returns a FileInfo describing the named file. It returns ErrFileNotExist if the file does not exist, or ErrPluginFileRead if another error occurs.

type Logos

type Logos struct {
	Small string `json:"small"`
	Large string `json:"large"`
}

type NotFoundError

type NotFoundError struct {
	PluginID string
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type PanelDTO

type PanelDTO struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	Info          Info   `json:"info"`
	HideFromList  bool   `json:"hideFromList"`
	Sort          int    `json:"sort"`
	SkipDataQuery bool   `json:"skipDataQuery"`
	ReleaseState  string `json:"state"`
	BaseURL       string `json:"baseUrl"`
	Signature     string `json:"signature"`
	Module        string `json:"module"`
}

type Permission

type Permission struct {
	Action string `json:"action"`
	Scope  string `json:"scope"`
}

type Plugin

type Plugin struct {
	JSONData

	FS    FS
	Class Class

	// App fields
	IncludedInAppID string
	DefaultNavURL   string
	Pinned          bool

	// Signature fields
	Signature      SignatureStatus
	SignatureType  SignatureType
	SignatureOrg   string
	Parent         *Plugin
	Children       []*Plugin
	SignatureError *SignatureError

	// SystemJS fields
	Module  string
	BaseURL string

	Renderer       pluginextensionv2.RendererPlugin
	SecretsManager secretsmanagerplugin.SecretsManagerPlugin
	// contains filtered or unexported fields
}

func (*Plugin) CallResource

func (*Plugin) CheckHealth

func (*Plugin) Client

func (p *Plugin) Client() (PluginClient, bool)

func (*Plugin) CollectMetrics

func (*Plugin) Decommission

func (p *Plugin) Decommission() error

func (*Plugin) ExecutablePath

func (p *Plugin) ExecutablePath() string

func (*Plugin) Exited

func (p *Plugin) Exited() bool

func (*Plugin) File

func (p *Plugin) File(name string) (fs.File, error)

func (*Plugin) IsApp

func (p *Plugin) IsApp() bool

func (*Plugin) IsBundledPlugin

func (p *Plugin) IsBundledPlugin() bool

func (*Plugin) IsCorePlugin

func (p *Plugin) IsCorePlugin() bool

func (*Plugin) IsDecommissioned

func (p *Plugin) IsDecommissioned() bool

func (*Plugin) IsExternalPlugin

func (p *Plugin) IsExternalPlugin() bool

func (*Plugin) IsManaged

func (p *Plugin) IsManaged() bool

func (*Plugin) IsRenderer

func (p *Plugin) IsRenderer() bool

func (*Plugin) IsSecretsManager

func (p *Plugin) IsSecretsManager() bool

func (*Plugin) Logger

func (p *Plugin) Logger() log.Logger

func (*Plugin) PluginID

func (p *Plugin) PluginID() string

func (*Plugin) PublishStream

func (*Plugin) QueryData

func (*Plugin) RegisterClient

func (p *Plugin) RegisterClient(c backendplugin.Plugin)

func (*Plugin) RunStream

func (p *Plugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, sender *backend.StreamSender) error

func (*Plugin) SetLogger

func (p *Plugin) SetLogger(l log.Logger)

func (*Plugin) Start

func (p *Plugin) Start(ctx context.Context) error

func (*Plugin) StaticRoute

func (p *Plugin) StaticRoute() *StaticRoute

func (*Plugin) Stop

func (p *Plugin) Stop(ctx context.Context) error

func (*Plugin) Target

func (p *Plugin) Target() backendplugin.Target

func (*Plugin) ToDTO

func (p *Plugin) ToDTO() PluginDTO

type PluginDTO

type PluginDTO struct {
	JSONData

	Class Class

	// App fields
	IncludedInAppID string
	DefaultNavURL   string
	Pinned          bool

	// Signature fields
	Signature      SignatureStatus
	SignatureType  SignatureType
	SignatureOrg   string
	SignatureError *SignatureError

	// SystemJS fields
	Module  string
	BaseURL string
	// contains filtered or unexported fields
}

func (PluginDTO) Base

func (p PluginDTO) Base() string

func (PluginDTO) IsApp

func (p PluginDTO) IsApp() bool

func (PluginDTO) IsCorePlugin

func (p PluginDTO) IsCorePlugin() bool

func (PluginDTO) SupportsStreaming

func (p PluginDTO) SupportsStreaming() bool

type PluginLoaderAuthorizer

type PluginLoaderAuthorizer interface {
	// CanLoadPlugin confirms if a plugin is authorized to load
	CanLoadPlugin(plugin *Plugin) bool
}

type PluginMetaDTO

type PluginMetaDTO struct {
	JSONData

	Signature SignatureStatus `json:"signature"`

	Module  string `json:"module"`
	BaseURL string `json:"baseUrl"`
}

type PluginSource

type PluginSource interface {
	PluginClass(ctx context.Context) Class
	PluginURIs(ctx context.Context) []string
	DefaultSignature(ctx context.Context) (Signature, bool)
}

type QueryCachingConfig

type QueryCachingConfig struct {
	Enabled bool  `json:"enabled"`
	TTLMS   int64 `json:"TTLMs"`
}

type ReleaseState

type ReleaseState string
const (
	AlphaRelease ReleaseState = "alpha"
)

type RendererManager

type RendererManager interface {
	// Renderer returns a renderer plugin.
	Renderer(ctx context.Context) *Plugin
}

type Role

type Role struct {
	Name        string       `json:"name"`
	Description string       `json:"description"`
	Permissions []Permission `json:"permissions"`
}

Role is the model for Role in RBAC.

type RoleRegistration

type RoleRegistration struct {
	Role   Role     `json:"role"`
	Grants []string `json:"grants"`
}

RoleRegistration stores a role and its assignments to basic roles (Viewer, Editor, Admin, Grafana Admin)

type RoleRegistry

type RoleRegistry interface {
	DeclarePluginRoles(ctx context.Context, ID, name string, registrations []RoleRegistration) error
}

RoleRegistry handles the plugin RBAC roles and their assignments

type Route

type Route struct {
	Path         string          `json:"path"`
	Method       string          `json:"method"`
	ReqRole      org.RoleType    `json:"reqRole"`
	URL          string          `json:"url"`
	URLParams    []URLParam      `json:"urlParams"`
	Headers      []Header        `json:"headers"`
	AuthType     string          `json:"authType"`
	TokenAuth    *JWTTokenAuth   `json:"tokenAuth"`
	JwtTokenAuth *JWTTokenAuth   `json:"jwtTokenAuth"`
	Body         json.RawMessage `json:"body"`
}

Route describes a plugin route that is defined in the plugin.json file for a plugin.

type Screenshots

type Screenshots struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

type SecretsPluginManager

type SecretsPluginManager interface {
	// SecretsManager returns a secretsmanager plugin
	SecretsManager(ctx context.Context) *Plugin
}

type Signature

type Signature struct {
	Status     SignatureStatus
	Type       SignatureType
	SigningOrg string
}

type SignatureError

type SignatureError struct {
	PluginID        string          `json:"pluginId"`
	SignatureStatus SignatureStatus `json:"status"`
}

func (SignatureError) AsErrorCode

func (e SignatureError) AsErrorCode() ErrorCode

func (SignatureError) Error

func (e SignatureError) Error() string

type SignatureStatus

type SignatureStatus string
const (
	SignatureInternal SignatureStatus = "internal" // core plugin, no signature
	SignatureValid    SignatureStatus = "valid"    // signed and accurate MANIFEST
	SignatureInvalid  SignatureStatus = "invalid"  // invalid signature
	SignatureModified SignatureStatus = "modified" // valid signature, but content mismatch
	SignatureUnsigned SignatureStatus = "unsigned" // no MANIFEST file
)

func (SignatureStatus) IsInternal

func (ss SignatureStatus) IsInternal() bool

func (SignatureStatus) IsValid

func (ss SignatureStatus) IsValid() bool

type SignatureType

type SignatureType string
const (
	GrafanaSignature     SignatureType = "grafana"
	CommercialSignature  SignatureType = "commercial"
	CommunitySignature   SignatureType = "community"
	PrivateSignature     SignatureType = "private"
	PrivateGlobSignature SignatureType = "private-glob"
)

func (SignatureType) IsValid

func (s SignatureType) IsValid() bool

type StaticRoute

type StaticRoute struct {
	PluginID  string
	Directory string
}

type StaticRouteResolver

type StaticRouteResolver interface {
	Routes() []*StaticRoute
}

type Store

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
}

Store is the publicly accessible storage for plugins.

type Type

type Type string
const (
	DataSource     Type = "datasource"
	Panel          Type = "panel"
	App            Type = "app"
	Renderer       Type = "renderer"
	SecretsManager Type = "secretsmanager"
)

func (Type) IsValid

func (pt Type) IsValid() bool

type URLParam

type URLParam struct {
	Name    string `json:"name"`
	Content string `json:"content"`
}

URLParam describes query string parameters for a url in a plugin route

type UpdateInfo

type UpdateInfo struct {
	PluginZipURL string
}

Directories

Path Synopsis
Package backendplugin contains backend plugin related logic.
Package backendplugin contains backend plugin related logic.
instrumentation
Package instrumentation contains backend plugin instrumentation logic.
Package instrumentation contains backend plugin instrumentation logic.
pfs
sdk module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL