From 12b97599151856590e52d9255a40b723f0c7a6cf Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 24 Nov 2023 10:56:01 -0500 Subject: [PATCH] command: reject version with --path for install To avoid plugins being installed with a specific version when a path is used for installing a plugin from a locally sourced plugin binary, we explicitly reject the combination of both a path and a version for plugins install. --- command/plugins_install.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/command/plugins_install.go b/command/plugins_install.go index fbb2876cda5..81b74cbd601 100644 --- a/command/plugins_install.go +++ b/command/plugins_install.go @@ -50,6 +50,7 @@ Options: installs the plugin where a normal invocation would, but will not try to download it from a web server, but instead directly install the binary for Packer to be able to load it later on. + This option cannot be specified with a version constraint. - force: forces installation of a plugin, even if it is already there. ` @@ -105,6 +106,12 @@ func (c *PluginsInstallCommand) ParseArgs(args []string) (*PluginsInstallArgs, i pa.Version = args[1] } + if pa.Path != "" && pa.Version != "" { + c.Ui.Error("Invalid arguments: a version cannot be specified with --path") + flags.Usage() + return pa, 1 + } + pa.PluginName = args[0] return pa, 0 @@ -256,12 +263,6 @@ an issue on our Github repo to signal it.`) }}) } - // Let's override the plugin's version if we specify it in the options - // of the command - if args.Version != "" { - desc.Version = args.Version - } - pluginBinary, err := os.Open(args.PluginPath) if err != nil { return writeDiags(c.Ui, nil, hcl.Diagnostics{&hcl.Diagnostic{