Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2fe34ec

Browse filesBrowse files
committed
gcs: Simplify middleware error handling
1 parent cdc6c44 commit 2fe34ec
Copy full SHA for 2fe34ec

2 files changed

+4-35Lines changed: 4 additions & 35 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/internal/shared/gatewayconfigurationserver/config.go‎

Copy file name to clipboardExpand all lines: cmd/internal/shared/gatewayconfigurationserver/config.go
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import (
1919
)
2020

2121
// DefaultGatewayConfigurationServerConfig is the default configuration for the Application Server.
22-
var DefaultGatewayConfigurationServerConfig = gatewayconfigurationserver.Config{}
22+
var DefaultGatewayConfigurationServerConfig = gatewayconfigurationserver.Config{
23+
RequireAuth: true,
24+
}
2325

2426
func init() {
2527
DefaultGatewayConfigurationServerConfig.TheThingsGateway.Default.UpdateChannel = "stable"
Collapse file

‎pkg/gatewayconfigurationserver/middleware.go‎

Copy file name to clipboardExpand all lines: pkg/gatewayconfigurationserver/middleware.go
+1-34Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,12 @@
1515
package gatewayconfigurationserver
1616

1717
import (
18-
"strings"
19-
2018
echo "github.com/labstack/echo/v4"
2119
"go.thethings.network/lorawan-stack/pkg/auth/rights"
22-
web_errors "go.thethings.network/lorawan-stack/pkg/errors/web"
23-
"go.thethings.network/lorawan-stack/pkg/log"
2420
"go.thethings.network/lorawan-stack/pkg/ttnpb"
25-
"google.golang.org/grpc/metadata"
2621
)
2722

28-
func (gcs *GatewayConfigurationServer) handleError() echo.MiddlewareFunc {
29-
return func(next echo.HandlerFunc) echo.HandlerFunc {
30-
return func(c echo.Context) error {
31-
ctx := gcs.getContext(c)
32-
err := next(c)
33-
if err == nil || c.Response().Committed {
34-
return err
35-
}
36-
log.FromContext(ctx).WithError(err).Debug("HTTP request failed")
37-
statusCode, err := web_errors.ProcessError(err)
38-
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), "application/json") {
39-
return c.JSON(statusCode, err)
40-
}
41-
return c.String(statusCode, err.Error())
42-
}
43-
}
44-
}
45-
46-
const (
47-
gatewayIDKey = "gateway_id"
48-
)
23+
const gatewayIDKey = "gateway_id"
4924

5025
func (gcs *GatewayConfigurationServer) validateAndFillIDs() echo.MiddlewareFunc {
5126
return func(next echo.HandlerFunc) echo.HandlerFunc {
@@ -69,14 +44,6 @@ func (gcs *GatewayConfigurationServer) requireGatewayRights(required ...ttnpb.Ri
6944
return func(c echo.Context) error {
7045
ctx := gcs.getContext(c)
7146
gtwID := c.Get(gatewayIDKey).(ttnpb.GatewayIdentifiers)
72-
md := metadata.New(map[string]string{
73-
"id": gtwID.GatewayID,
74-
"authorization": c.Request().Header.Get(echo.HeaderAuthorization),
75-
})
76-
if ctxMd, ok := metadata.FromIncomingContext(ctx); ok {
77-
md = metadata.Join(ctxMd, md)
78-
}
79-
ctx = metadata.NewIncomingContext(ctx, md)
8047
if err := rights.RequireGateway(ctx, gtwID, required...); err != nil {
8148
return err
8249
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.