From ea6cd25d781d0235c42e3abfa64f28a6213f4a7b Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 26 Aug 2015 13:22:16 -0700 Subject: [PATCH] Use logical passthrough for renew API calls --- http/handler.go | 2 +- http/sys_lease.go | 45 --------------------------------------------- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/http/handler.go b/http/handler.go index 757f5166ed..194efb042d 100644 --- a/http/handler.go +++ b/http/handler.go @@ -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)) diff --git a/http/sys_lease.go b/http/sys_lease.go index 35c4cb54ad..1bffb08afa 100644 --- a/http/sys_lease.go +++ b/http/sys_lease.go @@ -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" {