Skip to content

Commit

Permalink
all: Fix interop context filler usage
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansmares committed Apr 5, 2024
1 parent c4d6aad commit 233150f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func New(logger log.Stack, config *Config, opts ...Option) (c *Component, err er
}

config.Interop.SenderClientCA.BlobConfig = config.Blob
c.interop, err = interop.NewServer(c, c.fillers, config.Interop)
c.interop, err = interop.NewServer(c, c.FillContext, config.Interop)
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/fillcontext/fillcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ package fillcontext

import "context"

// Filler extends the context
// Filler extends the context.
type Filler func(context.Context) context.Context

// Noop is a filler that does nothing.
func Noop(ctx context.Context) context.Context {
return ctx
}
4 changes: 2 additions & 2 deletions pkg/interop/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Component interface {
}

// NewServer builds a new server.
func NewServer(c Component, contextFillers []fillcontext.Filler, conf config.InteropServer) (*Server, error) {
func NewServer(c Component, contextFiller fillcontext.Filler, conf config.InteropServer) (*Server, error) {
ctx := log.NewContextWithField(c.Context(), "namespace", "interop")
logger := log.FromContext(ctx)

Expand Down Expand Up @@ -133,7 +133,7 @@ func NewServer(c Component, contextFillers []fillcontext.Filler, conf config.Int
s.router.NotFoundHandler = http.HandlerFunc(webhandlers.NotFound)
s.router.Use(
mux.MiddlewareFunc(webmiddleware.Recover()),
mux.MiddlewareFunc(webmiddleware.FillContext(contextFillers...)),
mux.MiddlewareFunc(webmiddleware.FillContext(contextFiller)),
mux.MiddlewareFunc(webmiddleware.RequestURL()),
mux.MiddlewareFunc(webmiddleware.RequestID()),
mux.MiddlewareFunc(webmiddleware.MaxBody(1<<15)), // 32 kB.
Expand Down
3 changes: 2 additions & 1 deletion pkg/interop/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/smarty/assertions"
"go.thethings.network/lorawan-stack/v3/pkg/config"
"go.thethings.network/lorawan-stack/v3/pkg/fillcontext"
"go.thethings.network/lorawan-stack/v3/pkg/httpclient"
"go.thethings.network/lorawan-stack/v3/pkg/interop"
"go.thethings.network/lorawan-stack/v3/pkg/ratelimit"
Expand Down Expand Up @@ -316,7 +317,7 @@ func TestServer(t *testing.T) { //nolint:gocyclo

pbIssuer, pbToken := makePacketBrokerTokenIssuer(ctx, "test.packetbroker.io")

s, err := interop.NewServer(&mockComponent{ctx}, nil, config.InteropServer{
s, err := interop.NewServer(&mockComponent{ctx}, fillcontext.Noop, config.InteropServer{
SenderClientCA: config.SenderClientCA{
Source: "directory",
Directory: "testdata/server",
Expand Down

0 comments on commit 233150f

Please sign in to comment.