Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mhilton committed Mar 30, 2016
1 parent 06ef106 commit eb3fa39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions debugstatus/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type Handler struct {
// not, which will not be masked. If this is nil, no access will
// be allowed to either /debug/events or /debug/requests - the
// error returned will be ErrNoTraceConfigured. If access is
// allowed the sensative boolean is passed on the the trace
// handles.
CheckTraceAllowed func(req *http.Request) (err error, sensitive bool)
// allowed, the sensitive value specifies whether sensitive trace
// events will be shown.
CheckTraceAllowed func(req *http.Request) (sensitive bool, err error)
}

// DebugStatusRequest describes the /debug/status endpoint.
Expand Down Expand Up @@ -134,9 +134,9 @@ type DebugEventsRequest struct {

// DebugEvents serves the /debug/events endpoint.
func (h *Handler) DebugEvents(p httprequest.Params, r *DebugEventsRequest) error {
err, sensitive := h.checkTraceAllowed(p.Request)
sensitive, err := h.checkTraceAllowed(p.Request)
if err != nil {
return err
return errgo.Mask(err, errgo.Any)
}
trace.RenderEvents(p.Response, p.Request, sensitive)
return nil
Expand All @@ -149,9 +149,9 @@ type DebugRequestsRequest struct {

// DebugRequests serves the /debug/requests endpoint.
func (h *Handler) DebugRequests(p httprequest.Params, r *DebugRequestsRequest) error {
err, sensitive := h.checkTraceAllowed(p.Request)
sensitive, err := h.checkTraceAllowed(p.Request)
if err != nil {
return err
return errgo.Mask(err, errgo.Any)
}
trace.Render(p.Response, p.Request, sensitive)
return nil
Expand All @@ -163,9 +163,9 @@ var ErrNoTraceConfigured = errgo.New("no trace access configured")

// checkTraceAllowed is used instead of h.CheckTraceAllowed
// so that we don't panic if that is nil.
func (h *Handler) checkTraceAllowed(req *http.Request) (error, bool) {
func (h *Handler) checkTraceAllowed(req *http.Request) (bool, error) {
if h.CheckTraceAllowed == nil {
return ErrNoTraceConfigured, false
return false, ErrNoTraceConfigured
}
return h.CheckTraceAllowed(req)
}
8 changes: 4 additions & 4 deletions debugstatus/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var errUnauthorized = errgo.New("you shall not pass!")
func newHTTPHandler(h *debugstatus.Handler) http.Handler {
errMapper := httprequest.ErrorMapper(func(err error) (httpStatus int, errorBody interface{}) {
code, status := "", http.StatusInternalServerError
switch err {
switch errgo.Cause(err) {
case errUnauthorized:
code, status = "unauthorized", http.StatusUnauthorized
case debugstatus.ErrNoPprofConfigured:
Expand Down Expand Up @@ -169,11 +169,11 @@ var debugTracePaths = []string{

func (s *handlerSuite) TestServeTraceEvents(c *gc.C) {
httpHandler := newHTTPHandler(&debugstatus.Handler{
CheckTraceAllowed: func(req *http.Request) (error, bool) {
CheckTraceAllowed: func(req *http.Request) (bool, error) {
if req.Header.Get("Authorization") == "" {
return errUnauthorized, false
return false, errUnauthorized
}
return nil, false
return false, nil
},
})
authHeader := make(http.Header)
Expand Down

0 comments on commit eb3fa39

Please sign in to comment.