Skip to content

Commit

Permalink
Merge pull request #15 from Comcast/context-additions
Browse files Browse the repository at this point in the history
Context additions
  • Loading branch information
kristinapathak authored Apr 15, 2019
2 parents cf05272 + bc7b5dc commit bfe47e1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.2.2]
- Updated Errors `Error()` function
- Added request URL and method to context

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

Expand All @@ -24,7 +28,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.1...HEAD
[Unreleased]: https://github.com/Comcast/comcast-bascule/compare/v0.2.2...HEAD
[v0.2.2]: https://github.com/Comcast/comcast-bascule/compare/0.2.1...v0.2.2
[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
Expand Down
4 changes: 4 additions & 0 deletions bascule/basculehttp/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (c *constructor) decorate(next http.Handler) http.Handler {
bascule.Authentication{
Authorization: key,
Token: token,
Request: bascule.Request{
URL: request.URL.EscapedPath(),
Method: request.Method,
},
},
)
logger.Log(level.Key(), level.DebugValue(), "msg", "authentication added to context",
Expand Down
10 changes: 9 additions & 1 deletion bascule/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package bascule

import "context"
import (
"context"
)

// Authorization represents the authorization mechanism performed on the token,
// e.g. "Basic", "Bearer", etc for HTTP security environments.
Expand All @@ -10,6 +12,12 @@ type Authorization string
type Authentication struct {
Authorization Authorization
Token Token
Request Request
}

type Request struct {
URL string
Method string
}

type authenticationKey struct{}
Expand Down
8 changes: 7 additions & 1 deletion bascule/error.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bascule

import "fmt"

// Error is an optional interface to be implemented by security related errors
type Error interface {
Cause() error
Expand All @@ -13,7 +15,11 @@ type MultiError interface {
type Errors []error

func (e Errors) Error() string {
return "multiple errors"
var errors string
for _, err := range e {
errors = errors + ", " + err.Error()
}
return fmt.Sprintf("multiple errors: [%v]", errors)
}

func (e Errors) Errors() []error {
Expand Down

0 comments on commit bfe47e1

Please sign in to comment.