mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-04 04:28:08 +00:00 
			
		
		
		
	http: /v1/sys/mount DELETE
This commit is contained in:
		@@ -16,7 +16,7 @@ func Handler(core *vault.Core) http.Handler {
 | 
				
			|||||||
	mux.Handle("/v1/sys/seal", handleSysSeal(core))
 | 
						mux.Handle("/v1/sys/seal", handleSysSeal(core))
 | 
				
			||||||
	mux.Handle("/v1/sys/unseal", handleSysUnseal(core))
 | 
						mux.Handle("/v1/sys/unseal", handleSysUnseal(core))
 | 
				
			||||||
	mux.Handle("/v1/sys/mounts", handleSysListMounts(core))
 | 
						mux.Handle("/v1/sys/mounts", handleSysListMounts(core))
 | 
				
			||||||
	mux.Handle("/v1/sys/mount/", handleSysMount(core))
 | 
						mux.Handle("/v1/sys/mount/", handleSysMountUnmount(core))
 | 
				
			||||||
	mux.Handle("/v1/", handleLogical(core))
 | 
						mux.Handle("/v1/", handleLogical(core))
 | 
				
			||||||
	return mux
 | 
						return mux
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,10 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func testHttpDelete(t *testing.T, addr string) *http.Response {
 | 
				
			||||||
 | 
						return testHttpData(t, "DELETE", addr, nil)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func testHttpPost(t *testing.T, addr string, body interface{}) *http.Response {
 | 
					func testHttpPost(t *testing.T, addr string, body interface{}) *http.Response {
 | 
				
			||||||
	return testHttpData(t, "POST", addr, body)
 | 
						return testHttpData(t, "POST", addr, body)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,9 +28,12 @@ func handleSysListMounts(core *vault.Core) http.Handler {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleSysMount(core *vault.Core) http.Handler {
 | 
					func handleSysMountUnmount(core *vault.Core) http.Handler {
 | 
				
			||||||
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
						return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		if r.Method != "POST" {
 | 
							switch r.Method {
 | 
				
			||||||
 | 
							case "POST":
 | 
				
			||||||
 | 
							case "DELETE":
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
			respondError(w, http.StatusMethodNotAllowed, nil)
 | 
								respondError(w, http.StatusMethodNotAllowed, nil)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -47,6 +50,22 @@ func handleSysMount(core *vault.Core) http.Handler {
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch r.Method {
 | 
				
			||||||
 | 
							case "POST":
 | 
				
			||||||
 | 
								handleSysMount(core, w, r, path)
 | 
				
			||||||
 | 
							case "DELETE":
 | 
				
			||||||
 | 
								handleSysUnmount(core, w, r, path)
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								panic("should never happen")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleSysMount(
 | 
				
			||||||
 | 
						core *vault.Core,
 | 
				
			||||||
 | 
						w http.ResponseWriter,
 | 
				
			||||||
 | 
						r *http.Request,
 | 
				
			||||||
 | 
						path string) {
 | 
				
			||||||
	// Parse the request if we can
 | 
						// Parse the request if we can
 | 
				
			||||||
	var req MountRequest
 | 
						var req MountRequest
 | 
				
			||||||
	if err := parseRequest(r, &req); err != nil {
 | 
						if err := parseRequest(r, &req); err != nil {
 | 
				
			||||||
@@ -68,7 +87,23 @@ func handleSysMount(core *vault.Core) http.Handler {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	respondOk(w, nil)
 | 
						respondOk(w, nil)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleSysUnmount(
 | 
				
			||||||
 | 
						core *vault.Core,
 | 
				
			||||||
 | 
						w http.ResponseWriter,
 | 
				
			||||||
 | 
						r *http.Request,
 | 
				
			||||||
 | 
						path string) {
 | 
				
			||||||
 | 
						_, err := core.HandleRequest(&logical.Request{
 | 
				
			||||||
 | 
							Operation: logical.DeleteOperation,
 | 
				
			||||||
 | 
							Path:      "sys/mount/" + path,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							respondError(w, http.StatusInternalServerError, err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						respondOk(w, nil)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MountRequest struct {
 | 
					type MountRequest struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,3 +73,40 @@ func TestSysMount(t *testing.T) {
 | 
				
			|||||||
		t.Fatalf("bad: %#v", actual)
 | 
							t.Fatalf("bad: %#v", actual)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSysUnmount(t *testing.T) {
 | 
				
			||||||
 | 
						core, _ := vault.TestCoreUnsealed(t)
 | 
				
			||||||
 | 
						ln, addr := TestServer(t, core)
 | 
				
			||||||
 | 
						defer ln.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp := testHttpPost(t, addr+"/v1/sys/mount/foo", map[string]interface{}{
 | 
				
			||||||
 | 
							"type":        "generic",
 | 
				
			||||||
 | 
							"description": "foo",
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						testResponseStatus(t, resp, 204)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp = testHttpDelete(t, addr+"/v1/sys/mount/foo")
 | 
				
			||||||
 | 
						testResponseStatus(t, resp, 204)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := http.Get(addr + "/v1/sys/mounts")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatalf("err: %s", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var actual map[string]interface{}
 | 
				
			||||||
 | 
						expected := map[string]interface{}{
 | 
				
			||||||
 | 
							"secret/": map[string]interface{}{
 | 
				
			||||||
 | 
								"description": "generic secret storage",
 | 
				
			||||||
 | 
								"type":        "generic",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							"sys/": map[string]interface{}{
 | 
				
			||||||
 | 
								"description": "system endpoints used for control, policy and debugging",
 | 
				
			||||||
 | 
								"type":        "system",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						testResponseStatus(t, resp, 200)
 | 
				
			||||||
 | 
						testResponseBody(t, resp, &actual)
 | 
				
			||||||
 | 
						if !reflect.DeepEqual(actual, expected) {
 | 
				
			||||||
 | 
							t.Fatalf("bad: %#v", actual)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user