Skip to content

Commit

Permalink
Merge pull request #53 from Comcast/hotfix/smallRefactor
Browse files Browse the repository at this point in the history
small temporary refactor for jwt validation metrics
  • Loading branch information
joe94 authored Jan 27, 2018
2 parents bb03a20 + 31bd9a2 commit d13e9f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package: .
homepage: https://github.com/Comcast/tr1d1um
import:
- package: github.com/Comcast/webpa-common
version: 7ace8d3c96f2e4725e713378f744c3c090a880ce
version: d7cf234676e116d7b627936493c3259d35fe290f
- package: github.com/go-ozzo/ozzo-validation
version: v3.3
37 changes: 18 additions & 19 deletions src/tr1d1um/tr1d1um.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func tr1d1um(arguments []string) (exitCode int) {
return 1
}

valMetrics := secure.NewJWTValidationMeasures(metricsRegistry)
preHandler, err := SetUpPreHandler(v, logger, valMetrics)
preHandler, err := SetUpPreHandler(v, logger, metricsRegistry)

if err != nil {
fmt.Fprintf(os.Stderr, "error setting up prehandler: %s\n", err.Error())
Expand Down Expand Up @@ -242,30 +241,30 @@ func SetUpHandler(v *viper.Viper, logger log.Logger) (cHandler *ConversionHandle
}

//SetUpPreHandler configures the authorization requirements for requests to reach the main handler
func SetUpPreHandler(v *viper.Viper, logger log.Logger, m *secure.JWTValidationMeasures) (preHandler *alice.Chain, err error) {
validator, err := GetValidator(v, m)
if err != nil {
return
}

authHandler := handler.AuthorizationHandler{
HeaderName: "Authorization",
ForbiddenStatusCode: 403,
Validator: validator,
Logger: logger,
}
func SetUpPreHandler(v *viper.Viper, logger log.Logger, registry xmetrics.Registry) (preHandler *alice.Chain, err error) {
m := secure.NewJWTValidationMeasures(registry)
var validator secure.Validator
if validator, err = getValidator(v, m); err == nil {

authHandler := handler.AuthorizationHandler{
HeaderName: "Authorization",
ForbiddenStatusCode: 403,
Validator: validator,
Logger: logger,
}

authHandler.DefineMeasures(m)
authHandler.DefineMeasures(m)

newPreHandler := alice.New(authHandler.Decorate)
preHandler = &newPreHandler
newPreHandler := alice.New(authHandler.Decorate)
preHandler = &newPreHandler
}
return
}

//GetValidator returns a validator for JWT/Basic tokens
//getValidator returns a validator for JWT/Basic tokens
//It reads in tokens from a config file. Zero or more tokens
//can be read.
func GetValidator(v *viper.Viper, m *secure.JWTValidationMeasures) (validator secure.Validator, err error) {
func getValidator(v *viper.Viper, m *secure.JWTValidationMeasures) (validator secure.Validator, err error) {
var jwtVals []JWTValidator

v.UnmarshalKey("jwtValidators", &jwtVals)
Expand Down

0 comments on commit d13e9f6

Please sign in to comment.