cli/api: Update plugin listing to always include version info in the response (#17347)

This commit is contained in:
Tom Proctor
2022-09-29 18:22:33 +01:00
committed by GitHub
parent 6771e564d4
commit d467681e15
7 changed files with 161 additions and 90 deletions

View File

@@ -2,7 +2,6 @@ package command
import (
"fmt"
"sort"
"strings"
"github.com/hashicorp/vault/api"
@@ -128,31 +127,34 @@ func (c *PluginListCommand) Run(args []string) int {
c.UI.Output(tableOutput(c.detailedResponse(resp), nil))
return 0
}
c.UI.Output(tableOutput(c.simpleResponse(resp), nil))
c.UI.Output(tableOutput(c.simpleResponse(resp, pluginType), nil))
return 0
default:
res := make(map[string]interface{})
for k, v := range resp.PluginsByType {
res[k.String()] = v
}
res["details"] = resp.Details
return OutputData(c.UI, res)
}
}
func (c *PluginListCommand) simpleResponse(plugins *api.ListPluginsResponse) []string {
var flattenedNames []string
namesAdded := make(map[string]bool)
for _, names := range plugins.PluginsByType {
for _, name := range names {
if ok := namesAdded[name]; !ok {
flattenedNames = append(flattenedNames, name)
namesAdded[name] = true
}
func (c *PluginListCommand) simpleResponse(plugins *api.ListPluginsResponse, pluginType consts.PluginType) []string {
var out []string
switch pluginType {
case consts.PluginTypeUnknown:
out = []string{"Name | Type | Version"}
for _, plugin := range plugins.Details {
out = append(out, fmt.Sprintf("%s | %s | %s", plugin.Name, plugin.Type, plugin.Version))
}
default:
out = []string{"Name | Version"}
for _, plugin := range plugins.Details {
out = append(out, fmt.Sprintf("%s | %s", plugin.Name, plugin.Version))
}
sort.Strings(flattenedNames)
}
list := append([]string{"Plugins"}, flattenedNames...)
return list
return out
}
func (c *PluginListCommand) detailedResponse(plugins *api.ListPluginsResponse) []string {