2015-11-19 05:55:13 -06:00
|
|
|
package plugins
|
|
|
|
|
2015-12-21 10:23:24 -06:00
|
|
|
import (
|
2016-01-09 16:34:20 -06:00
|
|
|
"encoding/json"
|
2021-05-12 13:05:16 -05:00
|
|
|
"errors"
|
2016-03-10 12:57:48 -06:00
|
|
|
"fmt"
|
2016-02-10 04:03:12 -06:00
|
|
|
|
2020-02-28 05:51:21 -06:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2020-01-13 13:18:45 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
2015-12-21 10:23:24 -06:00
|
|
|
)
|
2015-11-19 05:55:13 -06:00
|
|
|
|
2021-03-08 00:02:49 -06:00
|
|
|
const (
|
2020-11-17 04:51:31 -06:00
|
|
|
PluginTypeApp = "app"
|
|
|
|
PluginTypeDashboard = "dashboard"
|
2016-03-10 12:57:48 -06:00
|
|
|
)
|
|
|
|
|
2021-05-12 13:05:16 -05:00
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
2016-03-10 12:57:48 -06:00
|
|
|
type PluginNotFoundError struct {
|
2020-10-21 05:39:41 -05:00
|
|
|
PluginID string
|
2016-03-10 12:57:48 -06:00
|
|
|
}
|
|
|
|
|
2016-03-11 02:57:20 -06:00
|
|
|
func (e PluginNotFoundError) Error() string {
|
2021-05-12 13:05:16 -05:00
|
|
|
return fmt.Sprintf("plugin with ID '%s' not found", e.PluginID)
|
2020-10-21 05:39:41 -05:00
|
|
|
}
|
|
|
|
|
2021-03-08 00:02:49 -06:00
|
|
|
type DuplicatePluginError struct {
|
2021-05-12 13:05:16 -05:00
|
|
|
PluginID string
|
|
|
|
ExistingPluginDir string
|
2020-10-21 05:39:41 -05:00
|
|
|
}
|
|
|
|
|
2021-03-08 00:02:49 -06:00
|
|
|
func (e DuplicatePluginError) Error() string {
|
2021-05-12 13:05:16 -05:00
|
|
|
return fmt.Sprintf("plugin with ID '%s' already exists in '%s'", e.PluginID, e.ExistingPluginDir)
|
2020-10-21 05:39:41 -05:00
|
|
|
}
|
|
|
|
|
2021-03-08 00:02:49 -06:00
|
|
|
func (e DuplicatePluginError) Is(err error) bool {
|
2020-11-19 06:34:28 -06:00
|
|
|
// nolint:errorlint
|
2021-03-08 00:02:49 -06:00
|
|
|
_, ok := err.(DuplicatePluginError)
|
2020-10-21 05:39:41 -05:00
|
|
|
return ok
|
2016-03-10 12:57:48 -06:00
|
|
|
}
|
|
|
|
|
2020-10-05 06:28:18 -05:00
|
|
|
// PluginLoader can load a plugin.
|
2016-01-09 16:34:20 -06:00
|
|
|
type PluginLoader interface {
|
2021-03-08 00:02:49 -06:00
|
|
|
// Load loads a plugin and returns it.
|
|
|
|
Load(decoder *json.Decoder, base *PluginBase, backendPluginManager backendplugin.Manager) (interface{}, error)
|
2016-01-09 16:34:20 -06:00
|
|
|
}
|
|
|
|
|
2020-10-05 06:28:18 -05:00
|
|
|
// PluginBase is the base plugin type.
|
2016-01-09 16:34:20 -06:00
|
|
|
type PluginBase struct {
|
2020-12-11 05:57:57 -06:00
|
|
|
Type string `json:"type"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
Info PluginInfo `json:"info"`
|
|
|
|
Dependencies PluginDependencies `json:"dependencies"`
|
|
|
|
Includes []*PluginInclude `json:"includes"`
|
|
|
|
Module string `json:"module"`
|
|
|
|
BaseUrl string `json:"baseUrl"`
|
|
|
|
Category string `json:"category"`
|
|
|
|
HideFromList bool `json:"hideFromList,omitempty"`
|
|
|
|
Preload bool `json:"preload"`
|
|
|
|
State PluginState `json:"state,omitempty"`
|
|
|
|
Signature PluginSignatureStatus `json:"signature"`
|
|
|
|
Backend bool `json:"backend"`
|
|
|
|
|
|
|
|
IncludedInAppId string `json:"-"`
|
|
|
|
PluginDir string `json:"-"`
|
|
|
|
DefaultNavUrl string `json:"-"`
|
|
|
|
IsCorePlugin bool `json:"-"`
|
|
|
|
Files []string `json:"-"`
|
|
|
|
SignatureType PluginSignatureType `json:"-"`
|
|
|
|
SignatureOrg string `json:"-"`
|
2016-03-13 13:21:44 -05:00
|
|
|
|
2016-04-11 11:21:48 -05:00
|
|
|
GrafanaNetVersion string `json:"-"`
|
|
|
|
GrafanaNetHasUpdate bool `json:"-"`
|
2020-10-05 06:28:18 -05:00
|
|
|
|
|
|
|
Root *PluginBase
|
2016-01-08 16:15:44 -06:00
|
|
|
}
|
|
|
|
|
2016-03-07 07:31:02 -06:00
|
|
|
type PluginDependencies struct {
|
2018-02-16 02:49:29 -06:00
|
|
|
GrafanaVersion string `json:"grafanaVersion"`
|
|
|
|
Plugins []PluginDependencyItem `json:"plugins"`
|
2016-03-07 07:31:02 -06:00
|
|
|
}
|
|
|
|
|
2016-03-08 11:17:47 -06:00
|
|
|
type PluginInclude struct {
|
2020-02-28 05:51:21 -06:00
|
|
|
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"`
|
2020-11-27 03:48:37 -06:00
|
|
|
Icon string `json:"icon"`
|
2016-03-21 13:07:08 -05:00
|
|
|
|
|
|
|
Id string `json:"-"`
|
2016-03-08 11:17:47 -06:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:49:29 -06:00
|
|
|
type PluginDependencyItem struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
}
|
|
|
|
|
2019-07-18 13:52:34 -05:00
|
|
|
type PluginBuildInfo struct {
|
|
|
|
Time int64 `json:"time,omitempty"`
|
|
|
|
Repo string `json:"repo,omitempty"`
|
|
|
|
Branch string `json:"branch,omitempty"`
|
|
|
|
Hash string `json:"hash,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-12-22 09:32:17 -06:00
|
|
|
type PluginInfo struct {
|
2016-02-09 08:36:42 -06:00
|
|
|
Author PluginInfoLink `json:"author"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Links []PluginInfoLink `json:"links"`
|
|
|
|
Logos PluginLogos `json:"logos"`
|
2019-07-19 08:21:39 -05:00
|
|
|
Build PluginBuildInfo `json:"build"`
|
2016-02-09 08:36:42 -06:00
|
|
|
Screenshots []PluginScreenshots `json:"screenshots"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
Updated string `json:"updated"`
|
2015-12-22 09:32:17 -06:00
|
|
|
}
|
|
|
|
|
2016-01-08 13:57:58 -06:00
|
|
|
type PluginInfoLink struct {
|
2015-12-22 09:32:17 -06:00
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PluginLogos struct {
|
|
|
|
Small string `json:"small"`
|
|
|
|
Large string `json:"large"`
|
|
|
|
}
|
|
|
|
|
2016-02-09 08:36:42 -06:00
|
|
|
type PluginScreenshots struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
|
2016-01-09 01:12:27 -06:00
|
|
|
type PluginStaticRoute struct {
|
|
|
|
Directory string
|
|
|
|
PluginId string
|
2015-11-19 09:50:17 -06:00
|
|
|
}
|
|
|
|
|
2015-12-03 01:52:37 -06:00
|
|
|
type EnabledPlugins struct {
|
2015-12-21 16:09:27 -06:00
|
|
|
Panels []*PanelPlugin
|
|
|
|
DataSources map[string]*DataSourcePlugin
|
|
|
|
Apps []*AppPlugin
|
2015-12-03 01:52:37 -06:00
|
|
|
}
|