Plugins: Remove unnecessary CDN code (#65929)

remove unnecessary code
This commit is contained in:
Will Browne
2023-04-04 16:01:49 +01:00
committed by GitHub
parent 42be20cbf3
commit 819c2f4ad8
4 changed files with 98 additions and 86 deletions

View File

@ -18,7 +18,6 @@ import (
"github.com/grafana/grafana/pkg/plugins/manager/process"
"github.com/grafana/grafana/pkg/plugins/manager/registry"
"github.com/grafana/grafana/pkg/plugins/manager/signature"
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
"github.com/grafana/grafana/pkg/plugins/storage"
"github.com/grafana/grafana/pkg/util"
)
@ -33,7 +32,6 @@ type Loader struct {
pluginInitializer initializer.Initializer
signatureValidator signature.Validator
pluginStorage storage.Manager
pluginsCDN *pluginscdn.Service
assetPath *assetpath.Service
log log.Logger
cfg *config.Cfg
@ -43,16 +41,16 @@ type Loader struct {
func ProvideService(cfg *config.Cfg, license plugins.Licensing, authorizer plugins.PluginLoaderAuthorizer,
pluginRegistry registry.Service, backendProvider plugins.BackendFactoryProvider, pluginFinder finder.Finder,
roleRegistry plugins.RoleRegistry, pluginsCDNService *pluginscdn.Service, assetPath *assetpath.Service) *Loader {
roleRegistry plugins.RoleRegistry, assetPath *assetpath.Service) *Loader {
return New(cfg, license, authorizer, pluginRegistry, backendProvider, process.NewManager(pluginRegistry),
storage.FileSystem(log.NewPrettyLogger("loader.fs"), cfg.PluginsPath), roleRegistry, pluginsCDNService,
assetPath, pluginFinder)
storage.FileSystem(log.NewPrettyLogger("loader.fs"), cfg.PluginsPath), roleRegistry, assetPath,
pluginFinder)
}
func New(cfg *config.Cfg, license plugins.Licensing, authorizer plugins.PluginLoaderAuthorizer,
pluginRegistry registry.Service, backendProvider plugins.BackendFactoryProvider,
processManager process.Service, pluginStorage storage.Manager, roleRegistry plugins.RoleRegistry,
pluginsCDNService *pluginscdn.Service, assetPath *assetpath.Service, pluginFinder finder.Finder) *Loader {
assetPath *assetpath.Service, pluginFinder finder.Finder) *Loader {
return &Loader{
pluginFinder: pluginFinder,
pluginRegistry: pluginRegistry,
@ -64,7 +62,6 @@ func New(cfg *config.Cfg, license plugins.Licensing, authorizer plugins.PluginLo
log: log.New("plugin.loader"),
roleRegistry: roleRegistry,
cfg: cfg,
pluginsCDN: pluginsCDNService,
assetPath: assetPath,
}
}
@ -86,20 +83,12 @@ func (l *Loader) loadPlugins(ctx context.Context, src plugins.PluginSource, foun
continue
}
var sig plugins.Signature
if l.pluginsCDN.PluginSupported(p.Primary.JSONData.ID) {
// CDN plugins have no signature checks for now.
sig = plugins.Signature{Status: plugins.SignatureValid}
} else {
var err error
sig, err = signature.Calculate(ctx, l.log, src, p.Primary)
if err != nil {
l.log.Warn("Could not calculate plugin signature state", "pluginID", p.Primary.JSONData.ID, "err", err)
continue
}
sig, err := signature.Calculate(ctx, l.log, src, p.Primary)
if err != nil {
l.log.Warn("Could not calculate plugin signature state", "pluginID", p.Primary.JSONData.ID, "err", err)
continue
}
class := src.PluginClass(ctx)
plugin, err := l.createPluginBase(p.Primary.JSONData, class, p.Primary.FS)
plugin, err := l.createPluginBase(p.Primary.JSONData, src.PluginClass(ctx), p.Primary.FS)
if err != nil {
l.log.Error("Could not create primary plugin base", "pluginID", p.Primary.JSONData.ID, "err", err)
continue
@ -117,7 +106,7 @@ func (l *Loader) loadPlugins(ctx context.Context, src plugins.PluginSource, foun
continue
}
cp, err := l.createPluginBase(c.JSONData, class, c.FS)
cp, err := l.createPluginBase(c.JSONData, plugin.Class, c.FS)
if err != nil {
l.log.Error("Could not create child plugin base", "pluginID", p.Primary.JSONData.ID, "err", err)
continue
@ -154,7 +143,7 @@ func (l *Loader) loadPlugins(ctx context.Context, src plugins.PluginSource, foun
if !plugin.IsRenderer() && !plugin.IsCorePlugin() {
_, err := plugin.FS.Open("module.js")
if err != nil {
if errors.Is(err, plugins.ErrFileNotExist) && !l.pluginsCDN.PluginSupported(plugin.ID) {
if errors.Is(err, plugins.ErrFileNotExist) {
l.log.Warn("Plugin missing module.js", "pluginID", plugin.ID,
"warning", "Missing module.js, If you loaded this plugin from git, make sure to compile it.")
}