Skip to content

Commit

Permalink
made updates based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Oct 11, 2023
1 parent 9a5a768 commit 187c79c
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions primaryHandler.go
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/xmidt-org/sallust"
"github.com/xmidt-org/touchstone"
"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/xmidt-org/webpa-common/secure/handler"
Expand Down Expand Up @@ -63,7 +64,7 @@ const (
jwtAuthConfigKey = "jwtValidator"
wrpCheckConfigKey = "WRPCheck"

deviceID = "deviceID"
deviceID = "devicID"

enforceCheck = "enforce"
)
Expand Down Expand Up @@ -566,28 +567,26 @@ func ValidateWRP() func(http.Handler) http.Handler {
return func(delegate http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

if req, err := wrphttp.DecodeRequest(r, nil); err == nil {
r = req
}

ctx := r.Context()
if msg, ok := wrpcontext.Get[*wrp.Message](ctx); ok {
validators := wrp.SpecValidators()
var err error
for _, v := range validators {
err := v.Validate(*msg)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(
w,
`{"code": %d, "message": "%s"}`,
http.StatusBadRequest,
fmt.Sprintf("failed to validate wrp message: %s", err),
)
return
}
err = multierr.Append(err, v.Validate(*msg))
}
if err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(
w,
`{"code": %d, "message": "%s"}`,
http.StatusBadRequest,
fmt.Sprintf("failed to validate WRP message: %s", err),
)
return
}

Check warning on line 587 in primaryHandler.go

View check run for this annotation

Codecov / codecov/patch

primaryHandler.go#L566-L587

Added lines #L566 - L587 were not covered by tests
}
delegate.ServeHTTP(w, r.WithContext(ctx))
delegate.ServeHTTP(w, r)

Check warning on line 589 in primaryHandler.go

View check run for this annotation

Codecov / codecov/patch

primaryHandler.go#L589

Added line #L589 was not covered by tests
})
}
}

0 comments on commit 187c79c

Please sign in to comment.