2015-11-19 12:55:13 +01:00
|
|
|
package plugins
|
|
|
|
|
|
2015-12-22 00:23:24 +08:00
|
|
|
import (
|
2021-05-12 20:05:16 +02:00
|
|
|
"errors"
|
2016-03-10 19:57:48 +01:00
|
|
|
"fmt"
|
2016-02-10 11:03:12 +01:00
|
|
|
|
2022-08-10 11:56:48 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
2015-12-22 00:23:24 +08:00
|
|
|
)
|
2015-11-19 12:55:13 +01:00
|
|
|
|
2021-03-08 07:02:49 +01:00
|
|
|
const (
|
2021-11-01 09:53:33 +00:00
|
|
|
TypeDashboard = "dashboard"
|
2016-03-10 19:57:48 +01:00
|
|
|
)
|
|
|
|
|
|
2021-05-12 20:05:16 +02:00
|
|
|
var (
|
2022-08-23 11:50:50 +02:00
|
|
|
ErrInstallCorePlugin = errors.New("cannot install a Core plugin")
|
|
|
|
|
ErrUninstallCorePlugin = errors.New("cannot uninstall a Core plugin")
|
|
|
|
|
ErrPluginNotInstalled = errors.New("plugin is not installed")
|
2021-05-12 20:05:16 +02:00
|
|
|
)
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type NotFoundError struct {
|
2020-10-21 12:39:41 +02:00
|
|
|
PluginID string
|
2016-03-10 19:57:48 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
func (e NotFoundError) Error() string {
|
2021-05-12 20:05:16 +02:00
|
|
|
return fmt.Sprintf("plugin with ID '%s' not found", e.PluginID)
|
2020-10-21 12:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type DuplicateError struct {
|
2022-12-02 12:46:55 +00:00
|
|
|
PluginID string
|
2020-10-21 12:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
func (e DuplicateError) Error() string {
|
2022-12-02 12:46:55 +00:00
|
|
|
return fmt.Sprintf("plugin with ID '%s' already exists", e.PluginID)
|
2020-10-21 12:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
func (e DuplicateError) Is(err error) bool {
|
2020-11-19 13:34:28 +01:00
|
|
|
// nolint:errorlint
|
2021-11-01 09:53:33 +00:00
|
|
|
_, ok := err.(DuplicateError)
|
2020-10-21 12:39:41 +02:00
|
|
|
return ok
|
2016-03-10 19:57:48 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type SignatureError struct {
|
|
|
|
|
PluginID string `json:"pluginId"`
|
|
|
|
|
SignatureStatus SignatureStatus `json:"status"`
|
|
|
|
|
}
|
2021-09-08 08:49:05 +02:00
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
func (e SignatureError) Error() string {
|
|
|
|
|
switch e.SignatureStatus {
|
2023-06-08 12:21:19 +02:00
|
|
|
case SignatureStatusInvalid:
|
2021-11-01 09:53:33 +00:00
|
|
|
return fmt.Sprintf("plugin '%s' has an invalid signature", e.PluginID)
|
2023-06-08 12:21:19 +02:00
|
|
|
case SignatureStatusModified:
|
2021-11-01 09:53:33 +00:00
|
|
|
return fmt.Sprintf("plugin '%s' has an modified signature", e.PluginID)
|
2023-06-08 12:21:19 +02:00
|
|
|
case SignatureStatusUnsigned:
|
2021-11-01 09:53:33 +00:00
|
|
|
return fmt.Sprintf("plugin '%s' has no signature", e.PluginID)
|
2023-06-08 12:21:19 +02:00
|
|
|
case SignatureStatusInternal, SignatureStatusValid:
|
2021-11-01 09:53:33 +00:00
|
|
|
return ""
|
2021-09-08 08:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
return fmt.Sprintf("plugin '%s' has an unknown signature state", e.PluginID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e SignatureError) AsErrorCode() ErrorCode {
|
|
|
|
|
switch e.SignatureStatus {
|
2023-06-08 12:21:19 +02:00
|
|
|
case SignatureStatusInvalid:
|
|
|
|
|
return errorCodeSignatureInvalid
|
|
|
|
|
case SignatureStatusModified:
|
|
|
|
|
return errorCodeSignatureModified
|
|
|
|
|
case SignatureStatusUnsigned:
|
|
|
|
|
return errorCodeSignatureMissing
|
|
|
|
|
case SignatureStatusInternal, SignatureStatusValid:
|
2021-11-01 09:53:33 +00:00
|
|
|
return ""
|
2021-09-08 08:49:05 +02:00
|
|
|
}
|
2021-11-01 09:53:33 +00:00
|
|
|
|
|
|
|
|
return ""
|
2021-09-08 08:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type Dependencies struct {
|
2021-11-12 11:07:12 +01:00
|
|
|
GrafanaDependency string `json:"grafanaDependency"`
|
|
|
|
|
GrafanaVersion string `json:"grafanaVersion"`
|
|
|
|
|
Plugins []Dependency `json:"plugins"`
|
2016-03-07 14:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type Includes struct {
|
2022-08-10 11:56:48 +02:00
|
|
|
Name string `json:"name"`
|
|
|
|
|
Path string `json:"path"`
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
Component string `json:"component"`
|
|
|
|
|
Role org.RoleType `json:"role"`
|
2022-11-16 15:54:04 +01:00
|
|
|
Action string `json:"action,omitempty"`
|
2022-08-10 11:56:48 +02:00
|
|
|
AddToNav bool `json:"addToNav"`
|
|
|
|
|
DefaultNav bool `json:"defaultNav"`
|
|
|
|
|
Slug string `json:"slug"`
|
|
|
|
|
Icon string `json:"icon"`
|
|
|
|
|
UID string `json:"uid"`
|
2016-03-21 19:07:08 +01:00
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
ID string `json:"-"`
|
2016-03-08 18:17:47 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-06 10:50:39 +02:00
|
|
|
func (e Includes) DashboardURLPath() string {
|
|
|
|
|
if e.Type != "dashboard" || len(e.UID) == 0 {
|
|
|
|
|
return ""
|
2021-07-22 09:11:33 +02:00
|
|
|
}
|
2022-04-06 10:50:39 +02:00
|
|
|
return "/d/" + e.UID
|
2021-07-22 09:11:33 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:54:04 +01:00
|
|
|
func (e Includes) RequiresRBACAction() bool {
|
|
|
|
|
return e.Action != ""
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type Dependency struct {
|
|
|
|
|
ID string `json:"id"`
|
2018-02-16 09:49:29 +01:00
|
|
|
Type string `json:"type"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type BuildInfo struct {
|
2019-07-18 11:52:34 -07:00
|
|
|
Time int64 `json:"time,omitempty"`
|
|
|
|
|
Repo string `json:"repo,omitempty"`
|
|
|
|
|
Branch string `json:"branch,omitempty"`
|
|
|
|
|
Hash string `json:"hash,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
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"`
|
2015-12-22 16:32:17 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type InfoLink struct {
|
2015-12-22 16:32:17 +01:00
|
|
|
Name string `json:"name"`
|
2021-11-01 09:53:33 +00:00
|
|
|
URL string `json:"url"`
|
2015-12-22 16:32:17 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type Logos struct {
|
2015-12-22 16:32:17 +01:00
|
|
|
Small string `json:"small"`
|
|
|
|
|
Large string `json:"large"`
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type Screenshots struct {
|
2016-02-09 22:36:42 +08:00
|
|
|
Name string `json:"name"`
|
2021-11-01 09:53:33 +00:00
|
|
|
Path string `json:"path"`
|
2016-02-09 22:36:42 +08:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type StaticRoute struct {
|
|
|
|
|
PluginID string
|
2016-01-09 08:12:27 +01:00
|
|
|
Directory string
|
2015-11-19 16:50:17 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type SignatureStatus string
|
|
|
|
|
|
|
|
|
|
func (ss SignatureStatus) IsValid() bool {
|
2023-06-08 12:21:19 +02:00
|
|
|
return ss == SignatureStatusValid
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ss SignatureStatus) IsInternal() bool {
|
2023-06-08 12:21:19 +02:00
|
|
|
return ss == SignatureStatusInternal
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
2023-06-08 12:21:19 +02:00
|
|
|
SignatureStatusInternal SignatureStatus = "internal" // core plugin, no signature
|
|
|
|
|
SignatureStatusValid SignatureStatus = "valid" // signed and accurate MANIFEST
|
|
|
|
|
SignatureStatusInvalid SignatureStatus = "invalid" // invalid signature
|
|
|
|
|
SignatureStatusModified SignatureStatus = "modified" // valid signature, but content mismatch
|
|
|
|
|
SignatureStatusUnsigned SignatureStatus = "unsigned" // no MANIFEST file
|
2021-11-01 09:53:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ReleaseState string
|
|
|
|
|
|
|
|
|
|
const (
|
2023-06-08 12:21:19 +02:00
|
|
|
ReleaseStateAlpha ReleaseState = "alpha"
|
2021-11-01 09:53:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type SignatureType string
|
|
|
|
|
|
|
|
|
|
const (
|
2023-06-08 12:21:19 +02:00
|
|
|
SignatureTypeGrafana SignatureType = "grafana"
|
|
|
|
|
SignatureTypeCommercial SignatureType = "commercial"
|
|
|
|
|
SignatureTypeCommunity SignatureType = "community"
|
|
|
|
|
SignatureTypePrivate SignatureType = "private"
|
|
|
|
|
SignatureTypePrivateGlob SignatureType = "private-glob"
|
2021-11-01 09:53:33 +00:00
|
|
|
)
|
|
|
|
|
|
2022-07-27 12:56:52 +02:00
|
|
|
func (s SignatureType) IsValid() bool {
|
|
|
|
|
switch s {
|
2023-06-08 12:21:19 +02:00
|
|
|
case SignatureTypeGrafana, SignatureTypeCommercial, SignatureTypeCommunity, SignatureTypePrivate,
|
|
|
|
|
SignatureTypePrivateGlob:
|
2022-07-27 12:56:52 +02:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
type Signature struct {
|
|
|
|
|
Status SignatureStatus
|
|
|
|
|
Type SignatureType
|
|
|
|
|
SigningOrg string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PluginMetaDTO struct {
|
|
|
|
|
JSONData
|
|
|
|
|
|
|
|
|
|
Signature SignatureStatus `json:"signature"`
|
|
|
|
|
|
|
|
|
|
Module string `json:"module"`
|
|
|
|
|
BaseURL string `json:"baseUrl"`
|
2015-12-03 15:52:37 +08:00
|
|
|
}
|
2021-07-29 11:52:23 +02:00
|
|
|
|
2021-12-14 10:16:13 +00:00
|
|
|
type DataSourceDTO struct {
|
2023-08-30 08:46:47 -07:00
|
|
|
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]any `json:"jsonData"`
|
|
|
|
|
ReadOnly bool `json:"readOnly"`
|
|
|
|
|
AngularDetected bool `json:"angularDetected"`
|
2021-12-14 10:16:13 +00:00
|
|
|
|
|
|
|
|
BasicAuth string `json:"basicAuth,omitempty"`
|
|
|
|
|
WithCredentials bool `json:"withCredentials,omitempty"`
|
|
|
|
|
|
2023-02-02 23:39:54 -05:00
|
|
|
// This is populated by an Enterprise hook
|
|
|
|
|
CachingConfig QueryCachingConfig `json:"cachingConfig,omitempty"`
|
|
|
|
|
|
2021-12-14 10:16:13 +00:00
|
|
|
// 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 PanelDTO struct {
|
2023-09-29 08:20:37 -07:00
|
|
|
ID string `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
AliasIDs []string `json:"aliasIds,omitempty"`
|
|
|
|
|
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"`
|
|
|
|
|
AngularDetected bool `json:"angularDetected"`
|
2021-12-14 10:16:13 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-07 17:20:05 +01:00
|
|
|
type AppDTO struct {
|
2023-05-12 12:51:11 +02:00
|
|
|
ID string `json:"id"`
|
|
|
|
|
Path string `json:"path"`
|
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
Preload bool `json:"preload"`
|
|
|
|
|
AngularDetected bool `json:"angularDetected"`
|
2023-02-07 17:20:05 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
const (
|
2023-06-08 12:21:19 +02:00
|
|
|
errorCodeSignatureMissing ErrorCode = "signatureMissing"
|
|
|
|
|
errorCodeSignatureModified ErrorCode = "signatureModified"
|
|
|
|
|
errorCodeSignatureInvalid ErrorCode = "signatureInvalid"
|
2021-11-01 09:53:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ErrorCode string
|
|
|
|
|
|
|
|
|
|
type Error struct {
|
|
|
|
|
ErrorCode `json:"errorCode"`
|
|
|
|
|
PluginID string `json:"pluginId,omitempty"`
|
2021-07-29 11:52:23 +02:00
|
|
|
}
|
2021-12-14 10:16:13 +00:00
|
|
|
|
2022-11-07 11:30:45 +01:00
|
|
|
// Access-Control related definitions
|
|
|
|
|
|
|
|
|
|
// RoleRegistration stores a role and its assignments to basic roles
|
|
|
|
|
// (Viewer, Editor, Admin, Grafana Admin)
|
|
|
|
|
type RoleRegistration struct {
|
|
|
|
|
Role Role `json:"role"`
|
|
|
|
|
Grants []string `json:"grants"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Role is the model for Role in RBAC.
|
|
|
|
|
type Role struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
Permissions []Permission `json:"permissions"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Permission struct {
|
|
|
|
|
Action string `json:"action"`
|
|
|
|
|
Scope string `json:"scope"`
|
|
|
|
|
}
|
2023-02-02 23:39:54 -05:00
|
|
|
|
|
|
|
|
type QueryCachingConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
|
TTLMS int64 `json:"TTLMs"`
|
|
|
|
|
}
|