2015-04-01 02:21:02 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2015-04-14 00:21:31 +00:00
|
|
|
"io"
|
2015-04-01 02:21:02 +00:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
2015-04-14 00:21:31 +00:00
|
|
|
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, requestAuth(r, &logical.Request{
|
|
|
|
Operation: logical.WriteOperation,
|
|
|
|
Path: "sys/renew/" + path,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"increment": req.Increment,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
respondLogical(w, r, resp)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-01 02:21:02 +00:00
|
|
|
func handleSysRevoke(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/revoke/"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := core.HandleRequest(requestAuth(r, &logical.Request{
|
|
|
|
Operation: logical.WriteOperation,
|
|
|
|
Path: "sys/revoke/" + path,
|
|
|
|
}))
|
|
|
|
if err != nil {
|
|
|
|
respondError(w, http.StatusBadRequest, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
respondOk(w, nil)
|
|
|
|
})
|
|
|
|
}
|
2015-04-01 02:23:32 +00:00
|
|
|
|
|
|
|
func handleSysRevokePrefix(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/revoke-prefix/"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := core.HandleRequest(requestAuth(r, &logical.Request{
|
|
|
|
Operation: logical.WriteOperation,
|
|
|
|
Path: "sys/revoke-prefix/" + path,
|
|
|
|
}))
|
|
|
|
if err != nil {
|
|
|
|
respondError(w, http.StatusBadRequest, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
respondOk(w, nil)
|
|
|
|
})
|
|
|
|
}
|
2015-04-14 00:21:31 +00:00
|
|
|
|
|
|
|
type RenewRequest struct {
|
|
|
|
Increment int `json:"increment"`
|
|
|
|
}
|