Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Comcast/talaria
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtw committed Nov 16, 2017
2 parents a8f1480 + ebbab6f commit 68a5716
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
49 changes: 31 additions & 18 deletions src/glide.lock

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

34 changes: 23 additions & 11 deletions src/talaria/primaryHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"net/http"

"github.com/Comcast/webpa-common/device"
"github.com/Comcast/webpa-common/secure"
"github.com/Comcast/webpa-common/secure/handler"
"github.com/Comcast/webpa-common/wrp"
"github.com/go-kit/kit/log"
"github.com/gorilla/mux"
Expand All @@ -39,32 +41,42 @@ const (

func NewPrimaryHandler(logger log.Logger, manager device.Manager, v *viper.Viper) (http.Handler, error) {
var (
handler = mux.NewRouter()
apiHandler = handler.PathPrefix(fmt.Sprintf("%s/%s", baseURI, version)).Subrouter()
authKey = v.GetString("inbound.authKey")
r = mux.NewRouter()
apiHandler = r.PathPrefix(fmt.Sprintf("%s/%s", baseURI, version)).Subrouter()
authorizationDecorator = func(h http.Handler) http.Handler { return h }
)

apiHandler.Handle("/device/send", &device.MessageHandler{
if len(authKey) > 0 {
authorizationDecorator = handler.AuthorizationHandler{
Logger: logger,
Validator: secure.ExactMatchValidator(authKey),
}.Decorate
}

apiHandler.Handle("/device/send", authorizationDecorator(&device.MessageHandler{
Logger: logger,
Decoders: wrp.NewDecoderPool(poolSize, wrp.JSON),
Router: manager,
}).
})).
Methods("POST", "PATCH").
Headers("Content-Type", wrp.JSON.ContentType())

apiHandler.Handle("/device/send", &device.MessageHandler{
apiHandler.Handle("/device/send", authorizationDecorator(&device.MessageHandler{
Logger: logger,
Decoders: wrp.NewDecoderPool(poolSize, wrp.Msgpack),
Router: manager,
}).
})).
Methods("POST", "PATCH").
Headers("Content-Type", wrp.Msgpack.ContentType())

apiHandler.Handle("/devices", &device.ListHandler{
apiHandler.Handle("/devices", authorizationDecorator(&device.ListHandler{
Logger: logger,
Registry: manager,
}).
})).
Methods("GET")

// the connect handler is not decorated for authorization
apiHandler.Handle(
"/device",
device.UseID.FromHeader(&device.ConnectHandler{
Expand All @@ -75,12 +87,12 @@ func NewPrimaryHandler(logger log.Logger, manager device.Manager, v *viper.Viper

apiHandler.Handle(
"/device/{deviceID}/stat",
&device.StatHandler{
authorizationDecorator(&device.StatHandler{
Logger: logger,
Registry: manager,
Variable: "deviceID",
},
}),
)

return handler, nil
return r, nil
}

0 comments on commit 68a5716

Please sign in to comment.