mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
c39d6ad97d
* add uninstall flow * add install flow * small cleanup * smaller-footprint solution * cleanup + make bp start auto * fix interface contract * improve naming * accept version arg * ensure use of shared logger * make installer a field * add plugin decommissioning * add basic error checking * fix api docs * making initialization idempotent * add mutex * fix comment * fix test * add test for decommission * improve existing test * add more test coverage * more tests * change test func to use read lock * refactoring + adding test asserts * improve purging old install flow * improve dupe checking * change log name * skip over dupe scanned * make test assertion more flexible * remove trailing line * fix pointer receiver name * update comment * add context to API * add config flag * add base http api test + fix update functionality * simplify existing check * clean up test * refactor tests based on feedback * add single quotes to errs * use gcmp in tests + fix logo issue * make plugin list testing more flexible * address feedback * fix API test * fix linter * undo preallocate * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * fix linting issue in test * add docs placeholder * update install notes * Update docs/sources/plugins/marketplace.md Co-authored-by: Marcus Olsson <marcus.olsson@hey.com> * update access wording * add more placeholder docs * add link to more info * PR feedback - improved errors, refactor, lock fix * improve err details * propagate plugin version errors * don't autostart renderer * add H1 * fix imports Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Marcus Olsson <marcus.olsson@hey.com>
153 lines
4.3 KiB
Go
153 lines
4.3 KiB
Go
package plugins
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
)
|
|
|
|
const (
|
|
PluginTypeApp = "app"
|
|
PluginTypeDashboard = "dashboard"
|
|
)
|
|
|
|
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")
|
|
)
|
|
|
|
type PluginNotFoundError struct {
|
|
PluginID string
|
|
}
|
|
|
|
func (e PluginNotFoundError) Error() string {
|
|
return fmt.Sprintf("plugin with ID '%s' not found", e.PluginID)
|
|
}
|
|
|
|
type DuplicatePluginError struct {
|
|
PluginID string
|
|
ExistingPluginDir string
|
|
}
|
|
|
|
func (e DuplicatePluginError) Error() string {
|
|
return fmt.Sprintf("plugin with ID '%s' already exists in '%s'", e.PluginID, e.ExistingPluginDir)
|
|
}
|
|
|
|
func (e DuplicatePluginError) Is(err error) bool {
|
|
// nolint:errorlint
|
|
_, ok := err.(DuplicatePluginError)
|
|
return ok
|
|
}
|
|
|
|
// PluginLoader can load a plugin.
|
|
type PluginLoader interface {
|
|
// Load loads a plugin and returns it.
|
|
Load(decoder *json.Decoder, base *PluginBase, backendPluginManager backendplugin.Manager) (interface{}, error)
|
|
}
|
|
|
|
// PluginBase is the base plugin type.
|
|
type PluginBase struct {
|
|
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:"-"`
|
|
|
|
GrafanaNetVersion string `json:"-"`
|
|
GrafanaNetHasUpdate bool `json:"-"`
|
|
|
|
Root *PluginBase
|
|
}
|
|
|
|
type PluginDependencies struct {
|
|
GrafanaVersion string `json:"grafanaVersion"`
|
|
Plugins []PluginDependencyItem `json:"plugins"`
|
|
}
|
|
|
|
type PluginInclude 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"`
|
|
|
|
Id string `json:"-"`
|
|
}
|
|
|
|
type PluginDependencyItem struct {
|
|
Type string `json:"type"`
|
|
Id string `json:"id"`
|
|
Name string `json:"name"`
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
type PluginBuildInfo struct {
|
|
Time int64 `json:"time,omitempty"`
|
|
Repo string `json:"repo,omitempty"`
|
|
Branch string `json:"branch,omitempty"`
|
|
Hash string `json:"hash,omitempty"`
|
|
}
|
|
|
|
type PluginInfo struct {
|
|
Author PluginInfoLink `json:"author"`
|
|
Description string `json:"description"`
|
|
Links []PluginInfoLink `json:"links"`
|
|
Logos PluginLogos `json:"logos"`
|
|
Build PluginBuildInfo `json:"build"`
|
|
Screenshots []PluginScreenshots `json:"screenshots"`
|
|
Version string `json:"version"`
|
|
Updated string `json:"updated"`
|
|
}
|
|
|
|
type PluginInfoLink struct {
|
|
Name string `json:"name"`
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
type PluginLogos struct {
|
|
Small string `json:"small"`
|
|
Large string `json:"large"`
|
|
}
|
|
|
|
type PluginScreenshots struct {
|
|
Path string `json:"path"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type PluginStaticRoute struct {
|
|
Directory string
|
|
PluginId string
|
|
}
|
|
|
|
type EnabledPlugins struct {
|
|
Panels []*PanelPlugin
|
|
DataSources map[string]*DataSourcePlugin
|
|
Apps []*AppPlugin
|
|
}
|