grafana/pkg/cmd/grafana-cli/commands/upgrade_command.go
Marcus Efraimsson b47ec36d0d
CLI: Allow relative symlinks in zip archives when installing plugins (#50537)
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>
2022-06-15 14:38:59 +02:00

38 lines
925 B
Go

package commands
import (
"fmt"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
)
func (cmd Command) upgradeCommand(c utils.CommandLine) error {
pluginsDir := c.PluginDirectory()
pluginName := c.Args().First()
localPlugin, err := services.ReadPlugin(pluginsDir, pluginName)
if err != nil {
return err
}
plugin, err2 := cmd.Client.GetPlugin(pluginName, c.PluginRepoURL())
if err2 != nil {
return err2
}
if shouldUpgrade(localPlugin.Info.Version, &plugin) {
if err := services.RemoveInstalledPlugin(pluginsDir, pluginName); err != nil {
return fmt.Errorf("failed to remove plugin '%s': %w", pluginName, err)
}
return InstallPlugin(pluginName, "", c)
}
logger.Infof("%s %s is up to date \n", color.GreenString("✔"), pluginName)
return nil
}