mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-11 09:40:17 -04:00
plugin: factorise calling describe on binaries
Given that calling the describe command on plugins and deserialising the output as a plugin description is something done in multiple places in the code, we factorise this operation so we don't need to copy/paste the code around.
This commit is contained in:
parent
747cb00cdc
commit
56fab30fa1
2 changed files with 16 additions and 15 deletions
|
|
@ -211,18 +211,12 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL
|
|||
}
|
||||
}
|
||||
|
||||
descOut, err := exec.Command(path, "describe").Output()
|
||||
describeInfo, err := GetPluginDescription(path)
|
||||
if err != nil {
|
||||
log.Printf("couldn't call describe on %q, ignoring", path)
|
||||
log.Printf("failed to call describe on %q: %s", path, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var describeInfo pluginsdk.SetDescription
|
||||
err = json.Unmarshal(descOut, &describeInfo)
|
||||
if err != nil {
|
||||
log.Printf("%q: describe output deserialization error %q, ignoring", path, err)
|
||||
}
|
||||
|
||||
// versionsStr now looks like v1.2.3_x5.1 or amazon_v1.2.3_x5.1
|
||||
parts := strings.SplitN(versionsStr, "_", 2)
|
||||
pluginVersionStr, protocolVersionStr := parts[0], parts[1]
|
||||
|
|
@ -933,6 +927,18 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
return nil, errs
|
||||
}
|
||||
|
||||
func GetPluginDescription(pluginPath string) (pluginsdk.SetDescription, error) {
|
||||
out, err := exec.Command(pluginPath, "describe").Output()
|
||||
if err != nil {
|
||||
return pluginsdk.SetDescription{}, err
|
||||
}
|
||||
|
||||
desc := pluginsdk.SetDescription{}
|
||||
err = json.Unmarshal(out, &desc)
|
||||
|
||||
return desc, err
|
||||
}
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
// Should never error if both components are set
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ package packer
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -127,13 +126,9 @@ func (c *PluginConfig) Discover() error {
|
|||
// if the "packer-plugin-amazon" binary had an "ebs" builder one could use
|
||||
// the "amazon-ebs" builder.
|
||||
func (c *PluginConfig) DiscoverMultiPlugin(pluginName, pluginPath string) error {
|
||||
out, err := exec.Command(pluginPath, "describe").Output()
|
||||
desc, err := plugingetter.GetPluginDescription(pluginPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var desc pluginsdk.SetDescription
|
||||
if err := json.Unmarshal(out, &desc); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to get plugin description from executable %q: %s", pluginPath, err)
|
||||
}
|
||||
|
||||
pluginPrefix := pluginName + "-"
|
||||
|
|
|
|||
Loading…
Reference in a new issue