From ba57fa0fd9d137a8d431cb235239047db27b9b5b Mon Sep 17 00:00:00 2001 From: Becca Petrin Date: Tue, 6 Nov 2018 17:04:43 -0800 Subject: [PATCH] try listing if getting fails --- api/sys_plugins.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/api/sys_plugins.go b/api/sys_plugins.go index fda919449997..52be04f6678a 100644 --- a/api/sys_plugins.go +++ b/api/sys_plugins.go @@ -20,6 +20,9 @@ type ListPluginsInput struct { type ListPluginsResponse struct { // PluginsByType is the list of plugins by type. PluginsByType map[consts.PluginType][]string `json:"types"` + + // NamesDeprecated is the list of names of the plugins. + NamesDeprecated []string `json:"names"` } // ListPlugins lists all plugins in the catalog and returns their names as a @@ -53,6 +56,26 @@ func (c *Sys) ListPlugins(i *ListPluginsInput) (*ListPluginsResponse, error) { return nil, errors.New("data from server response is empty") } + if resp.StatusCode == 405 && req.Method == "GET" { + // We received an Unsupported Operation response from Vault, indicating + // Vault of an older version that doesn't support the READ method yet. + req.Method = "LIST" + resp, err := c.c.RawRequestWithContext(ctx, req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var result struct { + Data struct { + Keys []string `json:"keys"` + } `json:"data"` + } + if err := resp.DecodeJSON(&result); err != nil { + return nil, err + } + return &ListPluginsResponse{NamesDeprecated: result.Data.Keys}, nil + } + result := &ListPluginsResponse{ PluginsByType: make(map[consts.PluginType][]string), }