Use logical passthrough for renew API calls

This commit is contained in:
Jeff Mitchell 2015-08-26 13:22:16 -07:00
parent 0057c76aaf
commit ea6cd25d78
2 changed files with 1 additions and 46 deletions

View file

@ -28,7 +28,7 @@ func Handler(core *vault.Core) http.Handler {
mux.Handle("/v1/sys/remount", proxySysRequest(core))
mux.Handle("/v1/sys/policy", handleSysListPolicies(core))
mux.Handle("/v1/sys/policy/", handleSysPolicy(core))
mux.Handle("/v1/sys/renew/", handleSysRenew(core))
mux.Handle("/v1/sys/renew/", proxySysRequest(core))
mux.Handle("/v1/sys/revoke/", handleSysRevoke(core))
mux.Handle("/v1/sys/revoke-prefix/", handleSysRevokePrefix(core))
mux.Handle("/v1/sys/auth", handleSysListAuth(core))

View file

@ -1,7 +1,6 @@
package http
import (
"io"
"net/http"
"strings"
@ -9,50 +8,6 @@ import (
"github.com/hashicorp/vault/vault"
)
func handleSysRenew(core *vault.Core) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "PUT" {
respondError(w, http.StatusMethodNotAllowed, nil)
return
}
// Determine the path...
prefix := "/v1/sys/renew/"
if !strings.HasPrefix(r.URL.Path, prefix) {
respondError(w, http.StatusNotFound, nil)
return
}
path := r.URL.Path[len(prefix):]
if path == "" {
respondError(w, http.StatusNotFound, nil)
return
}
// Parse the request if we can
var req RenewRequest
if err := parseRequest(r, &req); err != nil {
if err != io.EOF {
respondError(w, http.StatusBadRequest, err)
return
}
}
resp, ok := request(core, w, r, requestAuth(r, &logical.Request{
Operation: logical.WriteOperation,
Path: "sys/renew/" + path,
Connection: getConnection(r),
Data: map[string]interface{}{
"increment": req.Increment,
},
}))
if !ok {
return
}
respondLogical(w, r, path, false, resp)
})
}
func handleSysRevoke(core *vault.Core) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "PUT" {