open-vault/http/help.go

48 lines
1.1 KiB
Go
Raw Normal View History

2015-04-03 05:21:33 +00:00
package http
import (
"net/http"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/vault"
)
func wrapHelpHandler(h http.Handler, core *vault.Core) http.Handler {
2017-05-04 20:58:50 +00:00
return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
// If the help parameter is not blank, then show the help. We request
// forward because standby nodes do not have mounts and other state.
if v := req.URL.Query().Get("help"); v != "" || req.Method == "HELP" {
2017-05-04 20:58:50 +00:00
handleRequestForwarding(core,
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleHelp(core, w, r)
})).ServeHTTP(writer, req)
2015-04-03 05:21:33 +00:00
return
}
2017-05-04 20:58:50 +00:00
h.ServeHTTP(writer, req)
2015-04-03 05:21:33 +00:00
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
}
lreq := requestAuth(core, req, &logical.Request{
Operation: logical.HelpOperation,
Path: path,
Connection: getConnection(req),
})
resp, err := core.HandleRequest(lreq)
2015-04-03 05:21:33 +00:00
if err != nil {
respondErrorCommon(w, lreq, resp, err)
2015-04-03 05:21:33 +00:00
return
}
respondOk(w, resp.Data)
}