plugins

package
v0.0.0-test Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: AGPL-3.0 Imports: 12 Imported by: 1,183

Documentation

Index

Constants

View Source
const (
	TypeDashboard = "dashboard"
)

Variables

View Source
var (
	ErrInstallCorePlugin           = errors.New("cannot install a Core plugin")
	ErrUninstallCorePlugin         = errors.New("cannot uninstall a Core plugin")
	ErrUninstallOutsideOfPluginDir = errors.New("cannot uninstall a plugin outside")
	ErrPluginNotInstalled          = errors.New("plugin is not installed")
)
View Source
var PluginTypes = []Type{
	DataSource,
	Panel,
	App,
	Renderer,
}

Functions

func ComposePluginStartCommand

func ComposePluginStartCommand(executable string) string

func ComposeRendererStartCommand

func ComposeRendererStartCommand() string

Types

type AddOpts

type AddOpts struct {
	PluginInstallDir, PluginZipURL, PluginRepoURL string
}

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"
)

type Client

type Client interface {
	backend.QueryDataHandler
	backend.CheckHealthHandler
	backend.StreamHandler

	// CallResource calls a plugin resource.
	CallResource(pCtx backend.PluginContext, ctx *models.ReqContext, path string)
	// CollectMetrics collects metrics from a plugin.
	CollectMetrics(ctx context.Context, pluginID string) (*backend.CollectMetricsResult, error)
}

Client is used to communicate with backend plugin implementations.

type CoreBackendRegistrar

type CoreBackendRegistrar interface {
	// LoadAndRegister loads and registers a Core backend plugin
	LoadAndRegister(pluginID string, factory backendplugin.PluginFactoryFunc) error
}

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
	ExistingPluginDir 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 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 ImportDashboardInput

type ImportDashboardInput struct {
	Type     string `json:"type"`
	PluginId string `json:"pluginId"`
	Name     string `json:"name"`
	Value    string `json:"value"`
}

type Includes

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

	ID string `json:"-"`
}
func (e Includes) GetSlugOrUIDLink() string

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 {
	// Install downloads the requested plugin in the provided file system location.
	Install(ctx context.Context, pluginID, version, pluginsDir, pluginZipURL, pluginRepoURL string) error
	// Uninstall removes the requested plugin from the provided file system location.
	Uninstall(ctx context.Context, pluginDir string) error
	// GetUpdateInfo provides update information for the requested plugin.
	GetUpdateInfo(ctx context.Context, pluginID, version, pluginRepoURL string) (UpdateInfo, error)
}

Installer is responsible for managing plugins (add / remove) on the file system.

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"`

	// 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)
	Executable string `json:"executable,omitempty"`
}

JSONData represents the plugin's plugin.json

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 Loader

type Loader interface {
	// Load will return a list of plugins found in the provided file system paths.
	Load(paths []string, ignore map[string]struct{}) ([]*Plugin, error)
	// LoadWithFactory will return a plugin found in the provided file system path and use the provided factory to
	// construct the plugin backend client.
	LoadWithFactory(path string, factory backendplugin.PluginFactoryFunc) (*Plugin, error)
}

Loader is responsible for loading plugins from the file system.

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 Plugin

type Plugin struct {
	JSONData

	PluginDir string
	Class     Class

	// App fields
	IncludedInAppID string
	DefaultNavURL   string
	Pinned          bool

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

	// GCOM update checker fields
	GrafanaComVersion   string
	GrafanaComHasUpdate bool

	// SystemJS fields
	Module  string
	BaseURL string

	Renderer pluginextensionv2.RendererPlugin
	// contains filtered or unexported fields
}

func (*Plugin) CallResource

func (*Plugin) CheckHealth

func (*Plugin) Client

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

func (*Plugin) CollectMetrics

func (p *Plugin) CollectMetrics(ctx context.Context) (*backend.CollectMetricsResult, error)

func (*Plugin) Decommission

func (p *Plugin) Decommission() error

func (*Plugin) Exited

func (p *Plugin) Exited() bool

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) IsDataSource

func (p *Plugin) IsDataSource() 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) IsPanel

func (p *Plugin) IsPanel() bool

func (*Plugin) IsRenderer

func (p *Plugin) IsRenderer() 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) ToDTO

func (p *Plugin) ToDTO() PluginDTO

type PluginDTO

type PluginDTO struct {
	JSONData

	PluginDir string
	Class     Class

	// App fields
	IncludedInAppID string
	DefaultNavURL   string
	Pinned          bool

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

	// GCOM update checker fields
	GrafanaComVersion   string
	GrafanaComHasUpdate bool

	// SystemJS fields
	Module  string
	BaseURL string

	// temporary
	backend.StreamHandler
}

func (PluginDTO) IncludedInSignature

func (p PluginDTO) IncludedInSignature(file string) bool

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 PluginDashboardInfoDTO

type PluginDashboardInfoDTO struct {
	PluginId         string `json:"pluginId"`
	Title            string `json:"title"`
	Imported         bool   `json:"imported"`
	ImportedUri      string `json:"importedUri"`
	ImportedUrl      string `json:"importedUrl"`
	Slug             string `json:"slug"`
	DashboardId      int64  `json:"dashboardId"`
	FolderId         int64  `json:"folderId"`
	ImportedRevision int64  `json:"importedRevision"`
	Revision         int64  `json:"revision"`
	Description      string `json:"description"`
	Path             string `json:"path"`
	Removed          bool   `json:"removed"`
}

type PluginDashboardManager

type PluginDashboardManager interface {
	// GetPluginDashboards gets dashboards for a certain org/plugin.
	GetPluginDashboards(orgID int64, pluginID string) ([]*PluginDashboardInfoDTO, error)
	// LoadPluginDashboard loads a plugin dashboard.
	LoadPluginDashboard(pluginID, path string) (*models.Dashboard, error)
	// ImportDashboard imports a dashboard.
	ImportDashboard(ctx context.Context, pluginID, path string, orgID, folderID int64, dashboardModel *simplejson.Json,
		overwrite bool, inputs []ImportDashboardInput, user *models.SignedInUser) (PluginDashboardInfoDTO,
		*models.Dashboard, error)
}

type PluginFiles

type PluginFiles map[string]struct{}

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 ReleaseState

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

type RendererManager

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

type Route

type Route struct {
	Path         string          `json:"path"`
	Method       string          `json:"method"`
	ReqRole      models.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 Signature

type Signature struct {
	Status     SignatureStatus
	Type       SignatureType
	SigningOrg string
	Files      PluginFiles
}

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"
	PrivateSignature SignatureType = "private"
)

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

	// Add adds a plugin to the store.
	Add(ctx context.Context, pluginID, version string, opts AddOpts) error
	// Remove removes a plugin from the store.
	Remove(ctx context.Context, pluginID string) error
}

Store is the storage for plugins.

type Type

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

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 adapters contains plugin SDK adapters.
Package adapters contains plugin SDK adapters.
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.
codegen module
sdk module

Jump to

Keyboard shortcuts

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