2015-04-03 05:21:33 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
2016-12-15 22:53:07 +00:00
|
|
|
func wrapHelpHandler(h http.Handler, core *vault.Core) http.Handler {
|
2015-04-03 05:21:33 +00:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
// If the help parameter is not blank, then show the help
|
2016-08-15 13:42:42 +00:00
|
|
|
if v := req.URL.Query().Get("help"); v != "" || req.Method == "HELP" {
|
2015-04-03 05:21:33 +00:00
|
|
|
handleHelp(core, w, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
h.ServeHTTP(w, req)
|
|
|
|
return
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleHelp(core *vault.Core, w http.ResponseWriter, req *http.Request) {
|
|
|
|
path, ok := stripPrefix("/v1/", req.URL.Path)
|
|
|
|
if !ok {
|
|
|
|
respondError(w, http.StatusNotFound, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-10-29 21:01:49 +00:00
|
|
|
lreq := requestAuth(core, req, &logical.Request{
|
2015-06-19 00:17:18 +00:00
|
|
|
Operation: logical.HelpOperation,
|
|
|
|
Path: path,
|
|
|
|
Connection: getConnection(req),
|
2016-10-29 21:01:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
resp, err := core.HandleRequest(lreq)
|
2015-04-03 05:21:33 +00:00
|
|
|
if err != nil {
|
2016-12-02 16:22:13 +00:00
|
|
|
respondErrorCommon(w, resp, err)
|
2015-04-03 05:21:33 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
respondOk(w, resp.Data)
|
|
|
|
}
|