Files
grafana/pkg/cmd/grafana-cli/commands/upgrade_all_command.go
T
Marcus Efraimsson e0d1f9aedc CLI: Allow relative symlinks in zip archives when installing plugins (#50537) (#50877)
Earlier we only allowed symlinks in plugins starting with grafana- in zip archives when
installing plugins using the grafana-cli. This changes so that symlinks in zip archives
containing relative links to files in the zip archive are always allowed when installing
plugins. The reasoning behind this is that Grafana per default doesn't load a plugin
that has an invalid plugin signature meaning that any symlink must be included in
the plugin signature manifest.

Co-authored-by: Will Browne <will.browne@grafana.com>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
(cherry picked from commit b47ec36d0d)
2022-06-15 17:06:08 +02:00

65 lines
1.5 KiB
Go

package commands
import (
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/hashicorp/go-version"
)
func shouldUpgrade(installed string, remote *models.Plugin) bool {
installedVersion, err := version.NewVersion(installed)
if err != nil {
return false
}
latest := latestSupportedVersion(remote)
latestVersion, err := version.NewVersion(latest.Version)
if err != nil {
return false
}
return installedVersion.LessThan(latestVersion)
}
func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
pluginsDir := c.PluginDirectory()
localPlugins := services.GetLocalPlugins(pluginsDir)
remotePlugins, err := cmd.Client.ListAllPlugins(c.String("repo"))
if err != nil {
return err
}
pluginsToUpgrade := make([]models.InstalledPlugin, 0)
for _, localPlugin := range localPlugins {
for _, p := range remotePlugins.Plugins {
remotePlugin := p
if localPlugin.ID != remotePlugin.ID {
continue
}
if shouldUpgrade(localPlugin.Info.Version, &remotePlugin) {
pluginsToUpgrade = append(pluginsToUpgrade, localPlugin)
}
}
}
for _, p := range pluginsToUpgrade {
logger.Infof("Updating %v \n", p.ID)
err := services.RemoveInstalledPlugin(pluginsDir, p.ID)
if err != nil {
return err
}
err = InstallPlugin(p.ID, "", c)
if err != nil {
return err
}
}
return nil
}