Skip to content

Commit

Permalink
Merge pull request #5717 from hashicorp/backwards-compat
Browse files Browse the repository at this point in the history
Try list if get fails
  • Loading branch information
Becca Petrin authored Nov 7, 2018
2 parents 442b667 + ba57fa0 commit 5b6d88c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions api/sys_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
Expand Down

0 comments on commit 5b6d88c

Please sign in to comment.