Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try list if get fails #5717

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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