Plugins: Add -version flag to 'vault plugin info' (#17454)

* Add -version flag to 'vault plugin info'
* Allow specifying a builtin tag when reading a single plugin from the catalog
This commit is contained in:
Tom Proctor
2022-10-07 15:28:15 +01:00
committed by GitHub
parent f3940ce0a6
commit 4dd8fc6ed5
8 changed files with 228 additions and 17 deletions

View File

@@ -17,6 +17,8 @@ var (
type PluginInfoCommand struct {
*BaseCommand
flagVersion string
}
func (c *PluginInfoCommand) Synopsis() string {
@@ -41,7 +43,18 @@ Usage: vault plugin info [options] TYPE NAME
}
func (c *PluginInfoCommand) Flags() *FlagSets {
return c.flagSet(FlagSetHTTP | FlagSetOutputField | FlagSetOutputFormat)
set := c.flagSet(FlagSetHTTP | FlagSetOutputField | FlagSetOutputFormat)
f := set.NewFlagSet("Command Options")
f.StringVar(&StringVar{
Name: "version",
Target: &c.flagVersion,
Completion: complete.PredictAnything,
Usage: "Semantic version of the plugin. Optional.",
})
return set
}
func (c *PluginInfoCommand) AutocompleteArgs() complete.Predictor {
@@ -93,8 +106,9 @@ func (c *PluginInfoCommand) Run(args []string) int {
pluginName := strings.TrimSpace(pluginNameRaw)
resp, err := client.Sys().GetPlugin(&api.GetPluginInput{
Name: pluginName,
Type: pluginType,
Name: pluginName,
Type: pluginType,
Version: c.flagVersion,
})
if err != nil {
c.UI.Error(fmt.Sprintf("Error reading plugin named %s: %s", pluginName, err))
@@ -113,6 +127,7 @@ func (c *PluginInfoCommand) Run(args []string) int {
"name": resp.Name,
"sha256": resp.SHA256,
"deprecation_status": resp.DeprecationStatus,
"version": resp.Version,
}
if c.flagField != "" {