mirror of https://github.com/grafana/grafana.git
Plugins: Introduce plugin asset provider (#108063)
* introduce plugin asset provider * simply with PR feedback * fix linter
This commit is contained in:
parent
8548530dc4
commit
f6ed9e6ff0
|
@ -1050,4 +1050,9 @@ export interface FeatureToggles {
|
|||
* @default false
|
||||
*/
|
||||
alertingNotificationHistory?: boolean;
|
||||
/**
|
||||
* Allows decoupled core plugins to load from the Grafana CDN
|
||||
* @default false
|
||||
*/
|
||||
pluginAssetProvider?: boolean;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ type Features struct {
|
|||
// Needed only until Tempo Alerting / metrics TraceQL is stable
|
||||
// https://github.com/grafana/grafana/issues/106888
|
||||
TempoAlertingEnabled bool
|
||||
PluginAssetProvider bool
|
||||
}
|
||||
|
||||
// NewPluginManagementCfg returns a new PluginManagementCfg.
|
||||
|
|
|
@ -117,12 +117,10 @@ type PluginLoaderAuthorizer interface {
|
|||
|
||||
type Licensing interface {
|
||||
Environment() []string
|
||||
|
||||
Edition() string
|
||||
|
||||
Path() string
|
||||
|
||||
AppURL() string
|
||||
ContentDeliveryPrefix() string
|
||||
}
|
||||
|
||||
type SignatureCalculator interface {
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/plugins/auth"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||
"github.com/grafana/grafana/pkg/plugins/storage"
|
||||
)
|
||||
|
@ -378,6 +379,7 @@ type FakeLicensingService struct {
|
|||
TokenRaw string
|
||||
LicensePath string
|
||||
LicenseAppURL string
|
||||
CDNPrefix string
|
||||
}
|
||||
|
||||
func NewFakeLicensingService() *FakeLicensingService {
|
||||
|
@ -400,6 +402,10 @@ func (s *FakeLicensingService) Environment() []string {
|
|||
return []string{fmt.Sprintf("GF_ENTERPRISE_LICENSE_TEXT=%s", s.TokenRaw)}
|
||||
}
|
||||
|
||||
func (s *FakeLicensingService) ContentDeliveryPrefix() string {
|
||||
return s.CDNPrefix
|
||||
}
|
||||
|
||||
type FakeRoleRegistry struct {
|
||||
ExpectedErr error
|
||||
}
|
||||
|
@ -665,3 +671,26 @@ func (p *FakeBackendPlugin) Target() backendplugin.Target {
|
|||
func (p *FakeBackendPlugin) Logger() log.Logger {
|
||||
return log.NewTestLogger()
|
||||
}
|
||||
|
||||
type AssetProvider struct {
|
||||
ModuleFunc func(plugin pluginassets.PluginInfo) (string, error)
|
||||
AssetPathFunc func(plugin pluginassets.PluginInfo, assetPath ...string) (string, error)
|
||||
}
|
||||
|
||||
func NewFakeAssetProvider() *AssetProvider {
|
||||
return &AssetProvider{}
|
||||
}
|
||||
|
||||
func (p *AssetProvider) Module(plugin pluginassets.PluginInfo) (string, error) {
|
||||
if p.ModuleFunc != nil {
|
||||
return p.ModuleFunc(plugin)
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (p *AssetProvider) AssetPath(plugin pluginassets.PluginInfo, assetPath ...string) (string, error) {
|
||||
if p.AssetPathFunc != nil {
|
||||
return p.AssetPathFunc(plugin, assetPath...)
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
||||
)
|
||||
|
||||
|
@ -16,82 +18,77 @@ import (
|
|||
// It supports core plugins, external plugins stored on the local filesystem, and external plugins stored
|
||||
// on the plugins CDN, and it will switch to the correct implementation depending on the plugin and the config.
|
||||
type Service struct {
|
||||
cdn *pluginscdn.Service
|
||||
cfg *config.PluginManagementCfg
|
||||
cdn *pluginscdn.Service
|
||||
cfg *config.PluginManagementCfg
|
||||
assetProvider pluginassets.Provider
|
||||
}
|
||||
|
||||
func ProvideService(cfg *config.PluginManagementCfg, cdn *pluginscdn.Service) *Service {
|
||||
return &Service{cfg: cfg, cdn: cdn}
|
||||
}
|
||||
|
||||
type PluginInfo struct {
|
||||
pluginJSON plugins.JSONData
|
||||
class plugins.Class
|
||||
fs plugins.FS
|
||||
parent *PluginInfo
|
||||
}
|
||||
|
||||
func NewPluginInfo(pluginJSON plugins.JSONData, class plugins.Class, fs plugins.FS, parent *PluginInfo) PluginInfo {
|
||||
return PluginInfo{
|
||||
pluginJSON: pluginJSON,
|
||||
class: class,
|
||||
fs: fs,
|
||||
parent: parent,
|
||||
}
|
||||
func ProvideService(cfg *config.PluginManagementCfg, cdn *pluginscdn.Service, assetProvider pluginassets.Provider) *Service {
|
||||
return &Service{cfg: cfg, cdn: cdn, assetProvider: assetProvider}
|
||||
}
|
||||
|
||||
func DefaultService(cfg *config.PluginManagementCfg) *Service {
|
||||
return &Service{cfg: cfg, cdn: pluginscdn.ProvideService(cfg)}
|
||||
return &Service{cfg: cfg, cdn: pluginscdn.ProvideService(cfg), assetProvider: fakes.NewFakeAssetProvider()}
|
||||
}
|
||||
|
||||
// Base returns the base path for the specified plugin.
|
||||
func (s *Service) Base(n PluginInfo) (string, error) {
|
||||
if n.class == plugins.ClassCDN {
|
||||
return n.fs.Base(), nil
|
||||
func (s *Service) Base(n pluginassets.PluginInfo) (string, error) {
|
||||
if s.cfg.Features.PluginAssetProvider {
|
||||
return s.assetProvider.AssetPath(n)
|
||||
}
|
||||
if s.cdn.PluginSupported(n.pluginJSON.ID) {
|
||||
return s.cdn.AssetURL(n.pluginJSON.ID, n.pluginJSON.Info.Version, "")
|
||||
|
||||
if n.Class == plugins.ClassCDN {
|
||||
return n.FS.Base(), nil
|
||||
}
|
||||
if n.parent != nil {
|
||||
relPath, err := n.parent.fs.Rel(n.fs.Base())
|
||||
if s.cdn.PluginSupported(n.JsonData.ID) {
|
||||
return s.cdn.AssetURL(n.JsonData.ID, n.JsonData.Info.Version, "")
|
||||
}
|
||||
if n.Parent != nil {
|
||||
relPath, err := n.Parent.FS.Rel(n.FS.Base())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if s.cdn.PluginSupported(n.parent.pluginJSON.ID) {
|
||||
return s.cdn.AssetURL(n.parent.pluginJSON.ID, n.parent.pluginJSON.Info.Version, relPath)
|
||||
if s.cdn.PluginSupported(n.Parent.JsonData.ID) {
|
||||
return s.cdn.AssetURL(n.Parent.JsonData.ID, n.Parent.JsonData.Info.Version, relPath)
|
||||
}
|
||||
}
|
||||
|
||||
return path.Join("public/plugins", n.pluginJSON.ID), nil
|
||||
return path.Join("public/plugins", n.JsonData.ID), nil
|
||||
}
|
||||
|
||||
// Module returns the module.js path for the specified plugin.
|
||||
func (s *Service) Module(n PluginInfo) (string, error) {
|
||||
if n.class == plugins.ClassCore {
|
||||
if filepath.Base(n.fs.Base()) != "dist" {
|
||||
return path.Join("core:plugin", filepath.Base(n.fs.Base())), nil
|
||||
}
|
||||
func (s *Service) Module(n pluginassets.PluginInfo) (string, error) {
|
||||
if s.cfg.Features.PluginAssetProvider {
|
||||
return s.assetProvider.Module(n)
|
||||
}
|
||||
|
||||
if n.Class == plugins.ClassCore && filepath.Base(n.FS.Base()) != "dist" {
|
||||
return path.Join("core:plugin", filepath.Base(n.FS.Base())), nil
|
||||
}
|
||||
|
||||
return s.RelativeURL(n, "module.js")
|
||||
}
|
||||
|
||||
// RelativeURL returns the relative URL for an arbitrary plugin asset.
|
||||
func (s *Service) RelativeURL(n PluginInfo, pathStr string) (string, error) {
|
||||
if n.class == plugins.ClassCDN {
|
||||
return pluginscdn.JoinPath(n.fs.Base(), pathStr)
|
||||
func (s *Service) RelativeURL(n pluginassets.PluginInfo, pathStr string) (string, error) {
|
||||
if s.cfg.Features.PluginAssetProvider {
|
||||
return s.assetProvider.AssetPath(n, pathStr)
|
||||
}
|
||||
|
||||
if s.cdn.PluginSupported(n.pluginJSON.ID) {
|
||||
return s.cdn.NewCDNURLConstructor(n.pluginJSON.ID, n.pluginJSON.Info.Version).StringPath(pathStr)
|
||||
if n.Class == plugins.ClassCDN {
|
||||
return pluginscdn.JoinPath(n.FS.Base(), pathStr)
|
||||
}
|
||||
if n.parent != nil {
|
||||
if s.cdn.PluginSupported(n.parent.pluginJSON.ID) {
|
||||
relPath, err := n.parent.fs.Rel(n.fs.Base())
|
||||
|
||||
if s.cdn.PluginSupported(n.JsonData.ID) {
|
||||
return s.cdn.NewCDNURLConstructor(n.JsonData.ID, n.JsonData.Info.Version).StringPath(pathStr)
|
||||
}
|
||||
if n.Parent != nil {
|
||||
if s.cdn.PluginSupported(n.Parent.JsonData.ID) {
|
||||
relPath, err := n.Parent.FS.Rel(n.FS.Base())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.cdn.AssetURL(n.parent.pluginJSON.ID, n.parent.pluginJSON.Info.Version, path.Join(relPath, pathStr))
|
||||
return s.cdn.AssetURL(n.Parent.JsonData.ID, n.Parent.JsonData.Info.Version, path.Join(relPath, pathStr))
|
||||
}
|
||||
}
|
||||
// Local
|
||||
|
@ -120,7 +117,7 @@ func (s *Service) DefaultLogoPath(pluginType plugins.Type) string {
|
|||
return path.Join("public/img", fmt.Sprintf("icn-%s.svg", string(pluginType)))
|
||||
}
|
||||
|
||||
func (s *Service) GetTranslations(n PluginInfo) (map[string]string, error) {
|
||||
func (s *Service) GetTranslations(n pluginassets.PluginInfo) (map[string]string, error) {
|
||||
pathToTranslations, err := s.RelativeURL(n, "locales")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get locales: %w", err)
|
||||
|
@ -128,8 +125,8 @@ func (s *Service) GetTranslations(n PluginInfo) (map[string]string, error) {
|
|||
|
||||
// loop through all the languages specified in the plugin.json and add them to the list
|
||||
translations := map[string]string{}
|
||||
for _, language := range n.pluginJSON.Languages {
|
||||
file := fmt.Sprintf("%s.json", n.pluginJSON.ID)
|
||||
for _, language := range n.JsonData.Languages {
|
||||
file := fmt.Sprintf("%s.json", n.JsonData.ID)
|
||||
translations[language], err = url.JoinPath(pathToTranslations, language, file)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("join path: %w", err)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
||||
)
|
||||
|
||||
|
@ -44,7 +45,7 @@ func TestService(t *testing.T) {
|
|||
"two": {},
|
||||
},
|
||||
}
|
||||
svc := ProvideService(cfg, pluginscdn.ProvideService(cfg))
|
||||
svc := ProvideService(cfg, pluginscdn.ProvideService(cfg), fakes.NewFakeAssetProvider())
|
||||
|
||||
tableOldFS := fakes.NewFakePluginFS("/grafana/public/app/plugins/panel/table-old")
|
||||
jsonData := map[string]plugins.JSONData{
|
||||
|
@ -61,22 +62,22 @@ func TestService(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Base", func(t *testing.T) {
|
||||
base, err := svc.Base(NewPluginInfo(jsonData["one"], plugins.ClassExternal, pluginFS("one"), nil))
|
||||
base, err := svc.Base(pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassExternal, pluginFS("one"), nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
oneCDNURL, err := url.JoinPath(tc.cdnBaseURL, "/one/1.0.0/public/plugins/one")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, oneCDNURL, base)
|
||||
|
||||
base, err = svc.Base(NewPluginInfo(jsonData["one"], plugins.ClassCDN, pluginFS(oneCDNURL), nil))
|
||||
base, err = svc.Base(pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassCDN, pluginFS(oneCDNURL), nil))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, oneCDNURL, base)
|
||||
|
||||
base, err = svc.Base(NewPluginInfo(jsonData["two"], plugins.ClassExternal, pluginFS("two"), nil))
|
||||
base, err = svc.Base(pluginassets.NewPluginInfo(jsonData["two"], plugins.ClassExternal, pluginFS("two"), nil))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "public/plugins/two", base)
|
||||
|
||||
base, err = svc.Base(NewPluginInfo(jsonData["table-old"], plugins.ClassCore, tableOldFS, nil))
|
||||
base, err = svc.Base(pluginassets.NewPluginInfo(jsonData["table-old"], plugins.ClassCore, tableOldFS, nil))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "public/plugins/table-old", base)
|
||||
|
||||
|
@ -84,8 +85,8 @@ func TestService(t *testing.T) {
|
|||
parentFS.RelFunc = func(_ string) (string, error) {
|
||||
return "child-plugins/two", nil
|
||||
}
|
||||
parent := NewPluginInfo(jsonData["one"], plugins.ClassExternal, parentFS, nil)
|
||||
child := NewPluginInfo(jsonData["two"], plugins.ClassExternal, fakes.NewFakePluginFS(""), &parent)
|
||||
parent := pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassExternal, parentFS, nil)
|
||||
child := pluginassets.NewPluginInfo(jsonData["two"], plugins.ClassExternal, fakes.NewFakePluginFS(""), &parent)
|
||||
base, err = svc.Base(child)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -95,7 +96,7 @@ func TestService(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Module", func(t *testing.T) {
|
||||
module, err := svc.Module(NewPluginInfo(jsonData["one"], plugins.ClassExternal, pluginFS("one"), nil))
|
||||
module, err := svc.Module(pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassExternal, pluginFS("one"), nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
oneCDNURL, err := url.JoinPath(tc.cdnBaseURL, "/one/1.0.0/public/plugins/one")
|
||||
|
@ -106,15 +107,15 @@ func TestService(t *testing.T) {
|
|||
require.Equal(t, oneCDNModuleURL, module)
|
||||
|
||||
fs := pluginFS("one")
|
||||
module, err = svc.Module(NewPluginInfo(jsonData["one"], plugins.ClassCDN, fs, nil))
|
||||
module, err = svc.Module(pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassCDN, fs, nil))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, path.Join(fs.Base(), "module.js"), module)
|
||||
|
||||
module, err = svc.Module(NewPluginInfo(jsonData["two"], plugins.ClassExternal, pluginFS("two"), nil))
|
||||
module, err = svc.Module(pluginassets.NewPluginInfo(jsonData["two"], plugins.ClassExternal, pluginFS("two"), nil))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "public/plugins/two/module.js", module)
|
||||
|
||||
module, err = svc.Module(NewPluginInfo(jsonData["table-old"], plugins.ClassCore, tableOldFS, nil))
|
||||
module, err = svc.Module(pluginassets.NewPluginInfo(jsonData["table-old"], plugins.ClassCore, tableOldFS, nil))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "core:plugin/table-old", module)
|
||||
|
||||
|
@ -122,8 +123,8 @@ func TestService(t *testing.T) {
|
|||
parentFS.RelFunc = func(_ string) (string, error) {
|
||||
return "child-plugins/two", nil
|
||||
}
|
||||
parent := NewPluginInfo(jsonData["one"], plugins.ClassExternal, parentFS, nil)
|
||||
child := NewPluginInfo(jsonData["two"], plugins.ClassExternal, fakes.NewFakePluginFS(""), &parent)
|
||||
parent := pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassExternal, parentFS, nil)
|
||||
child := pluginassets.NewPluginInfo(jsonData["two"], plugins.ClassExternal, fakes.NewFakePluginFS(""), &parent)
|
||||
module, err = svc.Module(child)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -142,29 +143,29 @@ func TestService(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
u, err := svc.RelativeURL(NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassExternal, pluginFS("one"), nil), "")
|
||||
u, err := svc.RelativeURL(pluginassets.NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassExternal, pluginFS("one"), nil), "")
|
||||
require.NoError(t, err)
|
||||
// given an empty path, base URL will be returned
|
||||
baseURL, err := svc.Base(NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassExternal, pluginFS("one"), nil))
|
||||
baseURL, err := svc.Base(pluginassets.NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassExternal, pluginFS("one"), nil))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, baseURL, u)
|
||||
|
||||
u, err = svc.RelativeURL(NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassExternal, pluginFS("one"), nil), "path/to/file.txt")
|
||||
u, err = svc.RelativeURL(pluginassets.NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassExternal, pluginFS("one"), nil), "path/to/file.txt")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, strings.TrimRight(tc.cdnBaseURL, "/")+"/one/1.0.0/public/plugins/one/path/to/file.txt", u)
|
||||
|
||||
u, err = svc.RelativeURL(NewPluginInfo(pluginsMap["two"].JSONData, plugins.ClassExternal, pluginFS("two"), nil), "path/to/file.txt")
|
||||
u, err = svc.RelativeURL(pluginassets.NewPluginInfo(pluginsMap["two"].JSONData, plugins.ClassExternal, pluginFS("two"), nil), "path/to/file.txt")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "public/plugins/two/path/to/file.txt", u)
|
||||
|
||||
u, err = svc.RelativeURL(NewPluginInfo(pluginsMap["two"].JSONData, plugins.ClassExternal, pluginFS("two"), nil), "default")
|
||||
u, err = svc.RelativeURL(pluginassets.NewPluginInfo(pluginsMap["two"].JSONData, plugins.ClassExternal, pluginFS("two"), nil), "default")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "public/plugins/two/default", u)
|
||||
|
||||
oneCDNURL, err := url.JoinPath(tc.cdnBaseURL, "/one/1.0.0/public/plugins/one")
|
||||
require.NoError(t, err)
|
||||
|
||||
u, err = svc.RelativeURL(NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassCDN, pluginFS(oneCDNURL), nil), "path/to/file.txt")
|
||||
u, err = svc.RelativeURL(pluginassets.NewPluginInfo(pluginsMap["one"].JSONData, plugins.ClassCDN, pluginFS(oneCDNURL), nil), "path/to/file.txt")
|
||||
require.NoError(t, err)
|
||||
|
||||
oneCDNRelativeURL, err := url.JoinPath(oneCDNURL, "path/to/file.txt")
|
||||
|
@ -175,8 +176,8 @@ func TestService(t *testing.T) {
|
|||
parentFS.RelFunc = func(_ string) (string, error) {
|
||||
return "child-plugins/two", nil
|
||||
}
|
||||
parent := NewPluginInfo(jsonData["one"], plugins.ClassExternal, parentFS, nil)
|
||||
child := NewPluginInfo(jsonData["two"], plugins.ClassExternal, fakes.NewFakePluginFS(""), &parent)
|
||||
parent := pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassExternal, parentFS, nil)
|
||||
child := pluginassets.NewPluginInfo(jsonData["two"], plugins.ClassExternal, fakes.NewFakePluginFS(""), &parent)
|
||||
u, err = svc.RelativeURL(child, "path/to/file.txt")
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -192,8 +193,8 @@ func TestService(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("GetTranslations", func(t *testing.T) {
|
||||
pluginInfo := NewPluginInfo(jsonData["one"], plugins.ClassExternal, pluginFS("one"), nil)
|
||||
pluginInfo.pluginJSON.Languages = []string{"en-US", "pt-BR"}
|
||||
pluginInfo := pluginassets.NewPluginInfo(jsonData["one"], plugins.ClassExternal, pluginFS("one"), nil)
|
||||
pluginInfo.JsonData.Languages = []string{"en-US", "pt-BR"}
|
||||
translations, err := svc.GetTranslations(pluginInfo)
|
||||
require.NoError(t, err)
|
||||
oneCDNURL, err := url.JoinPath(tc.cdnBaseURL, "one", "1.0.0", "public", "plugins", "one")
|
||||
|
@ -219,14 +220,14 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
tcs := []struct {
|
||||
name string
|
||||
cfg *config.PluginManagementCfg
|
||||
pluginInfo func() PluginInfo
|
||||
pluginInfo func() pluginassets.PluginInfo
|
||||
expected expected
|
||||
}{
|
||||
{
|
||||
name: "Local FS external plugin",
|
||||
cfg: &config.PluginManagementCfg{},
|
||||
pluginInfo: func() PluginInfo {
|
||||
return NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
return pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
},
|
||||
expected: expected{
|
||||
module: "public/plugins/parent/module.js",
|
||||
|
@ -237,9 +238,9 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
{
|
||||
name: "Local FS external plugin with child",
|
||||
cfg: &config.PluginManagementCfg{},
|
||||
pluginInfo: func() PluginInfo {
|
||||
parentInfo := NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
childInfo := NewPluginInfo(plugins.JSONData{ID: "child", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent/child"), &parentInfo)
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
parentInfo := pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
childInfo := pluginassets.NewPluginInfo(plugins.JSONData{ID: "child", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent/child"), &parentInfo)
|
||||
return childInfo
|
||||
},
|
||||
expected: expected{
|
||||
|
@ -251,8 +252,8 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
{
|
||||
name: "Local FS core plugin",
|
||||
cfg: &config.PluginManagementCfg{},
|
||||
pluginInfo: func() PluginInfo {
|
||||
return NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCore, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
return pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCore, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
},
|
||||
expected: expected{
|
||||
module: "core:plugin/parent",
|
||||
|
@ -263,8 +264,8 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
{
|
||||
name: "Externally-built Local FS core plugin",
|
||||
cfg: &config.PluginManagementCfg{},
|
||||
pluginInfo: func() PluginInfo {
|
||||
return NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCore, plugins.NewLocalFS("/plugins/parent/dist"), nil)
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
return pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCore, plugins.NewLocalFS("/plugins/parent/dist"), nil)
|
||||
},
|
||||
expected: expected{
|
||||
module: "public/plugins/parent/module.js",
|
||||
|
@ -277,8 +278,8 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
cfg: &config.PluginManagementCfg{
|
||||
PluginsCDNURLTemplate: "https://cdn.example.com",
|
||||
},
|
||||
pluginInfo: func() PluginInfo {
|
||||
return NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCDN, pluginFS("https://cdn.example.com/plugins/parent"), nil)
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
return pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCDN, pluginFS("https://cdn.example.com/plugins/parent"), nil)
|
||||
},
|
||||
expected: expected{
|
||||
module: "https://cdn.example.com/plugins/parent/module.js",
|
||||
|
@ -291,10 +292,10 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
cfg: &config.PluginManagementCfg{
|
||||
PluginsCDNURLTemplate: "https://cdn.example.com",
|
||||
},
|
||||
pluginInfo: func() PluginInfo {
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
// Note: fake plugin FS is the most convenient way to mock the plugin FS for CDN plugins
|
||||
parentInfo := NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCDN, pluginFS("https://cdn.example.com/parent"), nil)
|
||||
childInfo := NewPluginInfo(plugins.JSONData{ID: "child", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCDN, pluginFS("https://cdn.example.com/parent/some/other/dir/child"), &parentInfo)
|
||||
parentInfo := pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCDN, pluginFS("https://cdn.example.com/parent"), nil)
|
||||
childInfo := pluginassets.NewPluginInfo(plugins.JSONData{ID: "child", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassCDN, pluginFS("https://cdn.example.com/parent/some/other/dir/child"), &parentInfo)
|
||||
return childInfo
|
||||
},
|
||||
expected: expected{
|
||||
|
@ -311,8 +312,8 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
"parent": {"cdn": "true"},
|
||||
},
|
||||
},
|
||||
pluginInfo: func() PluginInfo {
|
||||
return NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
return pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
},
|
||||
expected: expected{
|
||||
module: "https://cdn.example.com/parent/1.0.0/public/plugins/parent/module.js",
|
||||
|
@ -328,9 +329,9 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
"parent": {"cdn": "true"},
|
||||
},
|
||||
},
|
||||
pluginInfo: func() PluginInfo {
|
||||
parentInfo := NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
childInfo := NewPluginInfo(plugins.JSONData{ID: "child", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent/child"), &parentInfo)
|
||||
pluginInfo: func() pluginassets.PluginInfo {
|
||||
parentInfo := pluginassets.NewPluginInfo(plugins.JSONData{ID: "parent", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent"), nil)
|
||||
childInfo := pluginassets.NewPluginInfo(plugins.JSONData{ID: "child", Info: plugins.Info{Version: "1.0.0"}}, plugins.ClassExternal, plugins.NewLocalFS("/plugins/parent/child"), &parentInfo)
|
||||
return childInfo
|
||||
},
|
||||
expected: expected{
|
||||
|
@ -342,7 +343,7 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
}
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
svc := ProvideService(tc.cfg, pluginscdn.ProvideService(tc.cfg))
|
||||
svc := ProvideService(tc.cfg, pluginscdn.ProvideService(tc.cfg), fakes.NewFakeAssetProvider())
|
||||
|
||||
module, err := svc.Module(tc.pluginInfo())
|
||||
require.NoError(t, err)
|
||||
|
@ -358,3 +359,72 @@ func TestService_ChildPlugins(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_AssetProviderPrecedence(t *testing.T) {
|
||||
cfg := &config.PluginManagementCfg{
|
||||
PluginsCDNURLTemplate: "https://cdn.example.com",
|
||||
PluginSettings: map[string]map[string]string{
|
||||
"test-plugin": {"cdn": "true"},
|
||||
},
|
||||
Features: config.Features{PluginAssetProvider: true},
|
||||
}
|
||||
cdn := pluginscdn.ProvideService(cfg)
|
||||
|
||||
pluginInfo := pluginassets.NewPluginInfo(
|
||||
plugins.JSONData{ID: "test-plugin", Info: plugins.Info{Version: "1.0.0"}},
|
||||
plugins.ClassExternal,
|
||||
pluginFS("/plugins/test-plugin"),
|
||||
nil,
|
||||
)
|
||||
|
||||
t.Run("Asset provider enabled takes precedence when feature enabled", func(t *testing.T) {
|
||||
assetProvider := fakes.NewFakeAssetProvider()
|
||||
assetProvider.AssetPathFunc = func(n pluginassets.PluginInfo, pathElems ...string) (string, error) {
|
||||
return "from-asset-provider", nil
|
||||
}
|
||||
assetProvider.ModuleFunc = func(n pluginassets.PluginInfo) (string, error) {
|
||||
return "module-from-asset-provider", nil
|
||||
}
|
||||
|
||||
svc := ProvideService(cfg, cdn, assetProvider)
|
||||
|
||||
base, err := svc.Base(pluginInfo)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "from-asset-provider", base)
|
||||
|
||||
module, err := svc.Module(pluginInfo)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "module-from-asset-provider", module)
|
||||
|
||||
relURL, err := svc.RelativeURL(pluginInfo, "path/to/file.txt")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "from-asset-provider", relURL)
|
||||
})
|
||||
|
||||
t.Run("GetTranslations uses asset provider when feature enabled", func(t *testing.T) {
|
||||
assetProvider := fakes.NewFakeAssetProvider()
|
||||
assetProvider.AssetPathFunc = func(n pluginassets.PluginInfo, pathElems ...string) (string, error) {
|
||||
return path.Join("translation-path", path.Join(pathElems...)), nil
|
||||
}
|
||||
|
||||
pluginWithLangs := pluginassets.NewPluginInfo(
|
||||
plugins.JSONData{
|
||||
ID: "multilang-plugin",
|
||||
Info: plugins.Info{Version: "1.0.0"},
|
||||
Languages: []string{"en-US", "es-ES", "fr-FR"},
|
||||
},
|
||||
plugins.ClassExternal,
|
||||
pluginFS("/plugins/multilang-plugin"),
|
||||
nil,
|
||||
)
|
||||
|
||||
svc := ProvideService(cfg, cdn, assetProvider)
|
||||
translations, err := svc.GetTranslations(pluginWithLangs)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, translations, 3)
|
||||
// All translation paths should come from the asset provider
|
||||
require.Equal(t, "translation-path/locales/en-US/multilang-plugin.json", translations["en-US"])
|
||||
require.Equal(t, "translation-path/locales/es-ES/multilang-plugin.json", translations["es-ES"])
|
||||
require.Equal(t, "translation-path/locales/fr-FR/multilang-plugin.json", translations["fr-FR"])
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/loader/assetpath"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
)
|
||||
|
||||
type pluginFactoryFunc func(p *plugins.FoundBundle, pluginClass plugins.Class, sig plugins.Signature) (*plugins.Plugin, error)
|
||||
|
@ -27,7 +28,7 @@ func NewDefaultPluginFactory(features *config.Features, assetPath *assetpath.Ser
|
|||
|
||||
func (f *DefaultPluginFactory) createPlugin(bundle *plugins.FoundBundle, class plugins.Class,
|
||||
sig plugins.Signature) (*plugins.Plugin, error) {
|
||||
parentInfo := assetpath.NewPluginInfo(bundle.Primary.JSONData, class, bundle.Primary.FS, nil)
|
||||
parentInfo := pluginassets.NewPluginInfo(bundle.Primary.JSONData, class, bundle.Primary.FS, nil)
|
||||
plugin, err := f.newPlugin(bundle.Primary, class, sig, parentInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -39,7 +40,7 @@ func (f *DefaultPluginFactory) createPlugin(bundle *plugins.FoundBundle, class p
|
|||
|
||||
plugin.Children = make([]*plugins.Plugin, 0, len(bundle.Children))
|
||||
for _, child := range bundle.Children {
|
||||
childInfo := assetpath.NewPluginInfo(child.JSONData, class, child.FS, &parentInfo)
|
||||
childInfo := pluginassets.NewPluginInfo(child.JSONData, class, child.FS, &parentInfo)
|
||||
cp, err := f.newPlugin(*child, class, sig, childInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -52,7 +53,7 @@ func (f *DefaultPluginFactory) createPlugin(bundle *plugins.FoundBundle, class p
|
|||
}
|
||||
|
||||
func (f *DefaultPluginFactory) newPlugin(p plugins.FoundPlugin, class plugins.Class, sig plugins.Signature,
|
||||
info assetpath.PluginInfo) (*plugins.Plugin, error) {
|
||||
info pluginassets.PluginInfo) (*plugins.Plugin, error) {
|
||||
baseURL, err := f.assetPath.Base(info)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base url: %w", err)
|
||||
|
@ -86,7 +87,7 @@ func (f *DefaultPluginFactory) newPlugin(p plugins.FoundPlugin, class plugins.Cl
|
|||
return plugin, nil
|
||||
}
|
||||
|
||||
func setImages(p *plugins.Plugin, assetPath *assetpath.Service, info assetpath.PluginInfo) error {
|
||||
func setImages(p *plugins.Plugin, assetPath *assetpath.Service, info pluginassets.PluginInfo) error {
|
||||
var err error
|
||||
for _, dst := range []*string{&p.Info.Logos.Small, &p.Info.Logos.Large} {
|
||||
if len(*dst) == 0 {
|
||||
|
@ -109,7 +110,7 @@ func setImages(p *plugins.Plugin, assetPath *assetpath.Service, info assetpath.P
|
|||
return nil
|
||||
}
|
||||
|
||||
func setTranslations(p *plugins.Plugin, assetPath *assetpath.Service, info assetpath.PluginInfo) error {
|
||||
func setTranslations(p *plugins.Plugin, assetPath *assetpath.Service, info pluginassets.PluginInfo) error {
|
||||
translations, err := assetPath.GetTranslations(info)
|
||||
if err != nil {
|
||||
return fmt.Errorf("set translations: %w", err)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package pluginassets
|
||||
|
||||
import "github.com/grafana/grafana/pkg/plugins"
|
||||
|
||||
type Provider interface {
|
||||
Module(plugin PluginInfo) (string, error)
|
||||
AssetPath(plugin PluginInfo, assetPath ...string) (string, error)
|
||||
}
|
||||
|
||||
type PluginInfo struct {
|
||||
JsonData plugins.JSONData
|
||||
Class plugins.Class
|
||||
FS plugins.FS
|
||||
Parent *PluginInfo
|
||||
}
|
||||
|
||||
func NewPluginInfo(jsonData plugins.JSONData, class plugins.Class, fs plugins.FS, parent *PluginInfo) PluginInfo {
|
||||
return PluginInfo{
|
||||
JsonData: jsonData,
|
||||
Class: class,
|
||||
FS: fs,
|
||||
Parent: parent,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package pluginassets
|
||||
|
||||
import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
)
|
||||
|
||||
var _ Provider = (*LocalProvider)(nil)
|
||||
|
||||
type LocalProvider struct{}
|
||||
|
||||
func ProvideService() *LocalProvider {
|
||||
return &LocalProvider{}
|
||||
}
|
||||
|
||||
func (s *LocalProvider) Module(plugin PluginInfo) (string, error) {
|
||||
if plugin.Class == plugins.ClassCore && filepath.Base(plugin.FS.Base()) != "dist" {
|
||||
return path.Join("core:plugin", filepath.Base(plugin.FS.Base())), nil
|
||||
}
|
||||
|
||||
return s.AssetPath(plugin, "module.js")
|
||||
}
|
||||
|
||||
func (s *LocalProvider) AssetPath(plugin PluginInfo, assetPath ...string) (string, error) {
|
||||
return path.Join("public/plugins", plugin.JsonData.ID, path.Join(assetPath...)), nil
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package pluginassets
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
)
|
||||
|
||||
func TestLocalProvider_Module(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
plugin PluginInfo
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "core plugin without dist in base path should use core:plugin prefix",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "grafana-testdata-datasource"},
|
||||
Class: plugins.ClassCore,
|
||||
FS: plugins.NewLocalFS("/grafana/plugins/grafana-testdata-datasource"),
|
||||
},
|
||||
expected: "core:plugin/grafana-testdata-datasource",
|
||||
},
|
||||
{
|
||||
name: "core plugin with dist in base path should use standard path",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "grafana-testdata-datasource"},
|
||||
Class: plugins.ClassCore,
|
||||
FS: plugins.NewLocalFS("/grafana/plugins/grafana-testdata-datasource/dist"),
|
||||
},
|
||||
expected: "public/plugins/grafana-testdata-datasource/module.js",
|
||||
},
|
||||
{
|
||||
name: "external plugin should always use standard path",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "external-plugin"},
|
||||
Class: plugins.ClassExternal,
|
||||
FS: plugins.NewLocalFS("/var/lib/grafana/plugins/external-plugin"),
|
||||
},
|
||||
expected: "public/plugins/external-plugin/module.js",
|
||||
},
|
||||
{
|
||||
name: "CDN plugin should use standard path",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "cdn-plugin"},
|
||||
Class: plugins.ClassCDN,
|
||||
FS: plugins.NewLocalFS("/cdn/plugins/cdn-plugin"),
|
||||
},
|
||||
expected: "public/plugins/cdn-plugin/module.js",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := &LocalProvider{}
|
||||
got, err := p.Module(tt.plugin)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalProvider_AssetPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
plugin PluginInfo
|
||||
assetPath []string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "single asset path",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "test-plugin"},
|
||||
},
|
||||
assetPath: []string{"img/logo.svg"},
|
||||
expected: "public/plugins/test-plugin/img/logo.svg",
|
||||
},
|
||||
{
|
||||
name: "multiple asset path segments",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "test-plugin"},
|
||||
},
|
||||
assetPath: []string{"static", "img", "icon.png"},
|
||||
expected: "public/plugins/test-plugin/static/img/icon.png",
|
||||
},
|
||||
{
|
||||
name: "empty asset path",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "test-plugin"},
|
||||
},
|
||||
assetPath: []string{},
|
||||
expected: "public/plugins/test-plugin",
|
||||
},
|
||||
{
|
||||
name: "asset path with special characters",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "test-plugin"},
|
||||
},
|
||||
assetPath: []string{"dist/panel-options.json"},
|
||||
expected: "public/plugins/test-plugin/dist/panel-options.json",
|
||||
},
|
||||
{
|
||||
name: "core plugin asset path",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "grafana-testdata-datasource"},
|
||||
Class: plugins.ClassCore,
|
||||
},
|
||||
assetPath: []string{"query-editor.js"},
|
||||
expected: "public/plugins/grafana-testdata-datasource/query-editor.js",
|
||||
},
|
||||
{
|
||||
name: "deeply nested asset path",
|
||||
plugin: PluginInfo{
|
||||
JsonData: plugins.JSONData{ID: "test-plugin"},
|
||||
},
|
||||
assetPath: []string{"very", "deep", "nested", "path", "to", "file.js"},
|
||||
expected: "public/plugins/test-plugin/very/deep/nested/path/to/file.js",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := &LocalProvider{}
|
||||
got, err := p.AssetPath(tt.plugin, tt.assetPath...)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/signature"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/sources"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||
"github.com/grafana/grafana/pkg/registry/apis"
|
||||
|
@ -168,7 +169,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/services/pluginsintegration/managedplugins"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pipeline"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginaccesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginassets"
|
||||
pluginassets2 "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginchecker"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginconfig"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
|
||||
|
@ -349,7 +350,8 @@ func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Ser
|
|||
keyretrieverService := keyretriever.ProvideService(keyRetriever)
|
||||
signatureSignature := signature.ProvideService(pluginManagementCfg, keyretrieverService)
|
||||
pluginscdnService := pluginscdn.ProvideService(pluginManagementCfg)
|
||||
assetpathService := assetpath.ProvideService(pluginManagementCfg, pluginscdnService)
|
||||
localProvider := pluginassets.ProvideService()
|
||||
assetpathService := assetpath.ProvideService(pluginManagementCfg, pluginscdnService, localProvider)
|
||||
bootstrap := pipeline.ProvideBootstrapStage(pluginManagementCfg, signatureSignature, assetpathService)
|
||||
unsignedPluginAuthorizer := signature.ProvideOSSAuthorizer(pluginManagementCfg)
|
||||
validation := signature.ProvideValidatorService(unsignedPluginAuthorizer)
|
||||
|
@ -613,7 +615,7 @@ func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Ser
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pluginassetsService := pluginassets.ProvideService(pluginManagementCfg, pluginscdnService, signatureSignature, pluginstoreService)
|
||||
pluginassetsService := pluginassets2.ProvideService(pluginManagementCfg, pluginscdnService, signatureSignature, pluginstoreService)
|
||||
avatarCacheServer := avatar.ProvideAvatarCacheServer(cfg)
|
||||
prefService := prefimpl.ProvideService(sqlStore, cfg)
|
||||
dashboardPermissionsService, err := ossaccesscontrol.ProvideDashboardPermissions(cfg, featureToggles, routeRegisterImpl, sqlStore, accessControl, ossLicensingService, dashboardService, folderimplService, acimplService, teamService, userService, actionSetService, dashboardServiceImpl)
|
||||
|
@ -898,7 +900,8 @@ func InitializeForTest(t sqlutil.ITestDB, testingT interface {
|
|||
keyretrieverService := keyretriever.ProvideService(keyRetriever)
|
||||
signatureSignature := signature.ProvideService(pluginManagementCfg, keyretrieverService)
|
||||
pluginscdnService := pluginscdn.ProvideService(pluginManagementCfg)
|
||||
assetpathService := assetpath.ProvideService(pluginManagementCfg, pluginscdnService)
|
||||
localProvider := pluginassets.ProvideService()
|
||||
assetpathService := assetpath.ProvideService(pluginManagementCfg, pluginscdnService, localProvider)
|
||||
bootstrap := pipeline.ProvideBootstrapStage(pluginManagementCfg, signatureSignature, assetpathService)
|
||||
unsignedPluginAuthorizer := signature.ProvideOSSAuthorizer(pluginManagementCfg)
|
||||
validation := signature.ProvideValidatorService(unsignedPluginAuthorizer)
|
||||
|
@ -1164,7 +1167,7 @@ func InitializeForTest(t sqlutil.ITestDB, testingT interface {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pluginassetsService := pluginassets.ProvideService(pluginManagementCfg, pluginscdnService, signatureSignature, pluginstoreService)
|
||||
pluginassetsService := pluginassets2.ProvideService(pluginManagementCfg, pluginscdnService, signatureSignature, pluginstoreService)
|
||||
avatarCacheServer := avatar.ProvideAvatarCacheServer(cfg)
|
||||
prefService := prefimpl.ProvideService(sqlStore, cfg)
|
||||
dashboardPermissionsService, err := ossaccesscontrol.ProvideDashboardPermissions(cfg, featureToggles, routeRegisterImpl, sqlStore, accessControl, ossLicensingService, dashboardService, folderimplService, acimplService, teamService, userService, actionSetService, dashboardServiceImpl)
|
||||
|
|
|
@ -1809,6 +1809,16 @@ var (
|
|||
HideFromDocs: true,
|
||||
Expression: "false",
|
||||
},
|
||||
{
|
||||
Name: "pluginAssetProvider",
|
||||
Description: "Allows decoupled core plugins to load from the Grafana CDN",
|
||||
Stage: FeatureStageExperimental,
|
||||
Owner: grafanaPluginsPlatformSquad,
|
||||
HideFromAdminPage: true,
|
||||
HideFromDocs: true,
|
||||
Expression: "false",
|
||||
RequiresRestart: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -234,3 +234,4 @@ foldersAppPlatformAPI,experimental,@grafana/grafana-search-navigate-organise,fal
|
|||
enablePluginImporter,experimental,@grafana/plugins-platform-backend,false,false,true
|
||||
otelLogsFormatting,experimental,@grafana/observability-logs,false,false,true
|
||||
alertingNotificationHistory,experimental,@grafana/alerting-squad,false,false,false
|
||||
pluginAssetProvider,experimental,@grafana/plugins-platform-backend,false,true,false
|
||||
|
|
|
|
@ -946,4 +946,8 @@ const (
|
|||
// FlagAlertingNotificationHistory
|
||||
// Enables the notification history feature
|
||||
FlagAlertingNotificationHistory = "alertingNotificationHistory"
|
||||
|
||||
// FlagPluginAssetProvider
|
||||
// Allows decoupled core plugins to load from the Grafana CDN
|
||||
FlagPluginAssetProvider = "pluginAssetProvider"
|
||||
)
|
||||
|
|
|
@ -2467,6 +2467,22 @@
|
|||
"expression": "false"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"name": "pluginAssetProvider",
|
||||
"resourceVersion": "1752486584712",
|
||||
"creationTimestamp": "2025-07-14T09:49:44Z"
|
||||
},
|
||||
"spec": {
|
||||
"description": "Allows decoupled core plugins to load from the Grafana CDN",
|
||||
"stage": "experimental",
|
||||
"codeowner": "@grafana/plugins-platform-backend",
|
||||
"requiresRestart": true,
|
||||
"hideFromAdminPage": true,
|
||||
"hideFromDocs": true,
|
||||
"expression": "false"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"name": "pluginProxyPreserveTrailingSlash",
|
||||
|
@ -3420,4 +3436,4 @@
|
|||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func ProvideLicensing(cfg *setting.Cfg, l licensing.Licensing) *Service {
|
|||
}
|
||||
}
|
||||
|
||||
func (l Service) Environment() []string {
|
||||
func (l *Service) Environment() []string {
|
||||
var env []string
|
||||
if envProvider, ok := l.license.(licensing.LicenseEnvironment); ok {
|
||||
for k, v := range envProvider.Environment() {
|
||||
|
@ -31,14 +31,18 @@ func (l Service) Environment() []string {
|
|||
return env
|
||||
}
|
||||
|
||||
func (l Service) Edition() string {
|
||||
func (l *Service) Edition() string {
|
||||
return l.license.Edition()
|
||||
}
|
||||
|
||||
func (l Service) Path() string {
|
||||
func (l *Service) Path() string {
|
||||
return l.licensePath
|
||||
}
|
||||
|
||||
func (l Service) AppURL() string {
|
||||
func (l *Service) AppURL() string {
|
||||
return l.appURL
|
||||
}
|
||||
|
||||
func (l *Service) ContentDeliveryPrefix() string {
|
||||
return l.license.ContentDeliveryPrefix()
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/signature"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/sources"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pipeline"
|
||||
|
@ -1572,7 +1573,7 @@ type loaderDepOpts struct {
|
|||
func newLoader(t *testing.T, cfg *config.PluginManagementCfg, reg registry.Service, proc process.Manager,
|
||||
backendFactory plugins.BackendFactoryProvider, errTracker pluginerrs.ErrorTracker,
|
||||
) *Loader {
|
||||
assets := assetpath.ProvideService(cfg, pluginscdn.ProvideService(cfg))
|
||||
assets := assetpath.ProvideService(cfg, pluginscdn.ProvideService(cfg), pluginassets.ProvideService())
|
||||
angularInspector := angularinspector.NewStaticInspector()
|
||||
|
||||
terminate, err := pipeline.ProvideTerminationStage(cfg, reg, proc)
|
||||
|
@ -1586,7 +1587,7 @@ func newLoader(t *testing.T, cfg *config.PluginManagementCfg, reg registry.Servi
|
|||
}
|
||||
|
||||
func newLoaderWithOpts(t *testing.T, cfg *config.PluginManagementCfg, opts loaderDepOpts) *Loader {
|
||||
assets := assetpath.ProvideService(cfg, pluginscdn.ProvideService(cfg))
|
||||
assets := assetpath.ProvideService(cfg, pluginscdn.ProvideService(cfg), pluginassets.ProvideService())
|
||||
reg := fakes.NewFakePluginRegistry()
|
||||
proc := fakes.NewFakeProcessManager()
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ func ProvidePluginManagementConfig(cfg *setting.Cfg, settingProvider setting.Pro
|
|||
PluginsCDNSyncLoaderEnabled: features.IsEnabledGlobally(featuremgmt.FlagPluginsCDNSyncLoader),
|
||||
LocalizationForPlugins: features.IsEnabledGlobally(featuremgmt.FlagLocalizationForPlugins),
|
||||
TempoAlertingEnabled: features.IsEnabledGlobally(featuremgmt.FlagTempoAlerting),
|
||||
PluginAssetProvider: features.IsEnabledGlobally(featuremgmt.FlagPluginAssetProvider),
|
||||
},
|
||||
cfg.GrafanaComAPIURL,
|
||||
cfg.DisablePlugins,
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/signature"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/sources"
|
||||
pluginassets2 "github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||
"github.com/grafana/grafana/pkg/services/caching"
|
||||
|
@ -154,6 +155,8 @@ var WireExtensionSet = wire.NewSet(
|
|||
wire.Bind(new(sources.Registry), new(*sources.Service)),
|
||||
checkregistry.ProvideService,
|
||||
wire.Bind(new(checkregistry.CheckService), new(*checkregistry.Service)),
|
||||
pluginassets2.ProvideService,
|
||||
wire.Bind(new(pluginassets2.Provider), new(*pluginassets2.LocalProvider)),
|
||||
)
|
||||
|
||||
func ProvideClientWithMiddlewares(
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/grafana/grafana/pkg/plugins/manager/signature"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/signature/statickey"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/sources"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pipeline"
|
||||
|
@ -51,7 +52,7 @@ func CreateIntegrationTestCtx(t *testing.T, cfg *setting.Cfg, coreRegistry *core
|
|||
proc := process.ProvideService()
|
||||
|
||||
disc := pipeline.ProvideDiscoveryStage(pCfg, reg)
|
||||
boot := pipeline.ProvideBootstrapStage(pCfg, signature.ProvideService(pCfg, statickey.New()), assetpath.ProvideService(pCfg, cdn))
|
||||
boot := pipeline.ProvideBootstrapStage(pCfg, signature.ProvideService(pCfg, statickey.New()), assetpath.ProvideService(pCfg, cdn, pluginassets.ProvideService()))
|
||||
valid := pipeline.ProvideValidationStage(pCfg, signature.NewValidator(signature.NewUnsignedAuthorizer(pCfg)), angularInspector)
|
||||
init := pipeline.ProvideInitializationStage(pCfg, reg, provider.ProvideService(coreRegistry), proc, &fakes.FakeAuthService{}, fakes.NewFakeRoleRegistry(), fakes.NewFakeActionSetRegistry(), nil, tracing.InitializeTracerForTest())
|
||||
term, err := pipeline.ProvideTerminationStage(pCfg, reg, proc)
|
||||
|
@ -89,7 +90,7 @@ func CreateTestLoader(t *testing.T, cfg *pluginsCfg.PluginManagementCfg, opts Lo
|
|||
}
|
||||
|
||||
if opts.Bootstrapper == nil {
|
||||
opts.Bootstrapper = pipeline.ProvideBootstrapStage(cfg, signature.ProvideService(cfg, statickey.New()), assetpath.ProvideService(cfg, pluginscdn.ProvideService(cfg)))
|
||||
opts.Bootstrapper = pipeline.ProvideBootstrapStage(cfg, signature.ProvideService(cfg, statickey.New()), assetpath.ProvideService(cfg, pluginscdn.ProvideService(cfg), pluginassets.ProvideService()))
|
||||
}
|
||||
|
||||
if opts.Validator == nil {
|
||||
|
|
Loading…
Reference in New Issue