From 4348c13611cba395bbc343b2b5088e451daec925 Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Thu, 15 Jul 2021 18:55:09 +0200 Subject: [PATCH] Revert #12061 due to failures in TestLogical_RequestSizeLimit (#12093) --- api/response.go | 18 +++--------------- changelog/12061.txt | 3 --- http/handler.go | 5 +---- sdk/logical/response_util.go | 10 ---------- vault/logical_system.go | 7 +------ 5 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 changelog/12061.txt diff --git a/api/response.go b/api/response.go index 0fcfa9b207ca6..ae350c9791655 100644 --- a/api/response.go +++ b/api/response.go @@ -41,14 +41,12 @@ func (r *Response) Error() error { r.Body.Close() r.Body = ioutil.NopCloser(bodyBuf) - ns := r.Header.Get("X-Vault-Namespace") // Build up the error object respErr := &ResponseError{ - HTTPMethod: r.Request.Method, - URL: r.Request.URL.String(), - StatusCode: r.StatusCode, - NamespacePath: ns, + HTTPMethod: r.Request.Method, + URL: r.Request.URL.String(), + StatusCode: r.StatusCode, } // Decode the error response if we can. Note that we wrap the bodyBuf @@ -94,10 +92,6 @@ type ResponseError struct { // Errors are the underlying errors returned by Vault. Errors []string - - // Namespace path to be reported to the client if it is set to anything other - // than root - NamespacePath string } // Error returns a human-readable error string for the response error. @@ -107,15 +101,9 @@ func (r *ResponseError) Error() string { errString = "Raw Message" } - ns := r.NamespacePath - if ns != "" && ns != "root" { - ns = "Namespace: " + ns + "\n" - } - var errBody bytes.Buffer errBody.WriteString(fmt.Sprintf( "Error making API request.\n\n"+ - ns+ "URL: %s %s\n"+ "Code: %d. %s:\n\n", r.HTTPMethod, r.URL, r.StatusCode, errString)) diff --git a/changelog/12061.txt b/changelog/12061.txt deleted file mode 100644 index 28b6b6467b2ec..0000000000000 --- a/changelog/12061.txt +++ /dev/null @@ -1,3 +0,0 @@ -```release-note:bug -core (enterprise): namespace header included in responses, Go client uses it when displaying error messages -``` diff --git a/http/handler.go b/http/handler.go index 463aea91b2b6f..01a8fdcec08da 100644 --- a/http/handler.go +++ b/http/handler.go @@ -350,10 +350,7 @@ func wrapGenericHandler(core *vault.Core, h http.Handler, props *vault.HandlerPr return } - h.ServeHTTP(&logical.NamespaceResponseWriter{ - ResponseWriter: w, - NamespacePath: r.Header.Get("X-Vault-Namespace"), - }, r) + h.ServeHTTP(w, r) cancelFunc() return diff --git a/sdk/logical/response_util.go b/sdk/logical/response_util.go index 40c93ce538e5f..a05f74684951e 100644 --- a/sdk/logical/response_util.go +++ b/sdk/logical/response_util.go @@ -155,17 +155,7 @@ func AdjustErrorStatusCode(status *int, err error) { } } -type NamespaceResponseWriter struct { - http.ResponseWriter - NamespacePath string -} - func RespondError(w http.ResponseWriter, status int, err error) { - nw, ok := w.(*NamespaceResponseWriter) - if ok && nw.NamespacePath != "" && nw.NamespacePath != "root" { - nw.Header().Set("X-Vault-Namespace", nw.NamespacePath) - } - AdjustErrorStatusCode(&status, err) w.Header().Set("Content-Type", "application/json") diff --git a/vault/logical_system.go b/vault/logical_system.go index 6e06b2bd74cc0..47773697e834d 100644 --- a/vault/logical_system.go +++ b/vault/logical_system.go @@ -2925,12 +2925,7 @@ func (b *SystemBackend) handleMonitor(ctx context.Context, req *logical.Request, flusher, ok := w.ResponseWriter.(http.Flusher) if !ok { - // Casting the logical.ResponseWriter and try http.Flusher again - nw := w.ResponseWriter.(*logical.NamespaceResponseWriter) - flusher, ok = nw.ResponseWriter.(http.Flusher) - if !ok { - return logical.ErrorResponse("streaming not supported"), nil - } + return logical.ErrorResponse("streaming not supported"), nil } isJson := b.Core.LogFormat() == "json"