Merge pull request #1368 from hashicorp/issue-1365

In a list response, if there are no keys, 404 to be consistent with GET
This commit is contained in:
Jeff Mitchell 2016-05-02 20:01:06 -04:00
commit 3e0667a6bd
1 changed files with 28 additions and 3 deletions

View File

@ -92,11 +92,36 @@ func handleLogical(core *vault.Core, dataOnly bool, prepareRequestCallback Prepa
if !ok {
return
}
if (op == logical.ReadOperation || op == logical.ListOperation) && resp == nil {
switch {
case op == logical.ReadOperation:
if resp == nil {
respondError(w, http.StatusNotFound, nil)
return
}
// Basically: if we have empty "keys" or no keys at all, 404. This
// provides consistency with GET.
case op == logical.ListOperation:
if resp == nil || len(resp.Data) == 0 {
respondError(w, http.StatusNotFound, nil)
return
}
keysInt, ok := resp.Data["keys"]
if !ok || keysInt == nil {
respondError(w, http.StatusNotFound, nil)
return
}
keys, ok := keysInt.([]string)
if !ok {
respondError(w, http.StatusInternalServerError, nil)
return
}
if len(keys) == 0 {
respondError(w, http.StatusNotFound, nil)
return
}
}
// Build the proper response
respondLogical(w, r, path, dataOnly, resp)
})