Skip to content

Commit

Permalink
Revert #12061 due to failures in TestLogical_RequestSizeLimit (#12093)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncabatoff committed Jul 15, 2021
1 parent 2c647d1 commit 4348c13
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 38 deletions.
18 changes: 3 additions & 15 deletions api/response.go
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions changelog/12061.txt

This file was deleted.

5 changes: 1 addition & 4 deletions http/handler.go
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions sdk/logical/response_util.go
Expand Up @@ -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")
Expand Down
7 changes: 1 addition & 6 deletions vault/logical_system.go
Expand Up @@ -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"
Expand Down

0 comments on commit 4348c13

Please sign in to comment.