Skip to content

Commit

Permalink
Merge pull request #14 from Comcast/log-testing
Browse files Browse the repository at this point in the history
Fix log statements
  • Loading branch information
johnabass authored Apr 12, 2019
2 parents 574ba5d + cfc829d commit cf05272
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.2.1]
- Removed request from logging statements

## [v0.2.0]
- Added checks
- Added configurable behavior on a key not found in `enforcer`
Expand All @@ -21,7 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added constructor, enforcer, and listener alice decorators
- Basic code and structure established

[Unreleased]: https://github.com/Comcast/comcast-bascule/compare/v0.2.0...HEAD
[Unreleased]: https://github.com/Comcast/comcast-bascule/compare/v0.2.1...HEAD
[v0.2.1]: https://github.com/Comcast/comcast-bascule/compare/0.2.0...v0.2.1
[v0.2.0]: https://github.com/Comcast/comcast-bascule/compare/0.1.1...v0.2.0
[v0.1.1]: https://github.com/Comcast/comcast-bascule/compare/0.1.0...v0.1.1
[v0.1.0]: https://github.com/Comcast/comcast-bascule/compare/0.0.0...v0.1.0
14 changes: 7 additions & 7 deletions bascule/basculehttp/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func (c *constructor) decorate(next http.Handler) http.Handler {
}
authorization := request.Header.Get(c.headerName)
if len(authorization) == 0 {
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, "no authorization header", "request", request)
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, "no authorization header")
response.WriteHeader(http.StatusForbidden)
return
}

i := strings.IndexByte(authorization, ' ')
if i < 1 {
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, "unexpected authorization header value",
"request", request, "auth", authorization)
"auth", authorization)
response.WriteHeader(http.StatusBadRequest)
return
}
Expand All @@ -47,17 +47,17 @@ func (c *constructor) decorate(next http.Handler) http.Handler {

tf, supported := c.authorizations[key]
if !supported {
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, "key not supported", "request", request,
"key", key, "auth", authorization[i+1:])
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, "key not supported", "key", key,
"auth", authorization[i+1:])
response.WriteHeader(http.StatusForbidden)
return
}

ctx := request.Context()
token, err := tf.ParseAndValidate(ctx, request, key, authorization[i+1:])
if err != nil {
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, err.Error(), "request", request,
"key", key, "auth", authorization[i+1:])
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, err.Error(), "key", key,
"auth", authorization[i+1:])
WriteResponse(response, http.StatusUnauthorized, err)
return
}
Expand All @@ -69,7 +69,7 @@ func (c *constructor) decorate(next http.Handler) http.Handler {
Token: token,
},
)
logger.Log(level.Key(), level.DebugValue(), "msg", "authentication added to context", "request", request,
logger.Log(level.Key(), level.DebugValue(), "msg", "authentication added to context",
"token", token, "key", key)

next.ServeHTTP(response, request.WithContext(ctx))
Expand Down
12 changes: 5 additions & 7 deletions bascule/basculehttp/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func (e *enforcer) decorate(next http.Handler) http.Handler {
}
auth, ok := bascule.FromContext(ctx)
if !ok {
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, "no authentication found",
"request", request)
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, "no authentication found")
response.WriteHeader(http.StatusForbidden)
return
}
rules, ok := e.rules[auth.Authorization]
if !ok {
logger.Log(level.Key(), level.ErrorValue(),
bascule.ErrorKey, "no rules found for authorization", "request", request)
bascule.ErrorKey, "no rules found for authorization", "rules", rules,
"authorization", auth.Authorization, "behavior", e.notFoundBehavior)
switch e.notFoundBehavior {
case Forbid:
response.WriteHeader(http.StatusForbidden)
Expand All @@ -61,14 +61,12 @@ func (e *enforcer) decorate(next http.Handler) http.Handler {
errs = append(errs, e.Error())
}
}
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, errs,
"request", request)
logger.Log(level.Key(), level.ErrorValue(), bascule.ErrorKey, errs)
WriteResponse(response, http.StatusUnauthorized, err)
return
}
}
logger.Log(level.Key(), level.DebugValue(), "msg", "authentication accepted by enforcer",
"request", request)
logger.Log(level.Key(), level.DebugValue(), "msg", "authentication accepted by enforcer")
next.ServeHTTP(response, request)
})
}
Expand Down

0 comments on commit cf05272

Please sign in to comment.