internal: cleanup duplicate and redundant code, properly set sentry SDK scope settings
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		| @ -12,6 +12,8 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/coreos/go-oidc" | ||||
| 	"github.com/getsentry/sentry-go" | ||||
| 	sentryhttp "github.com/getsentry/sentry-go/http" | ||||
| 	"github.com/gorilla/mux" | ||||
| 	"github.com/gorilla/sessions" | ||||
| 	"github.com/pkg/errors" | ||||
| @ -109,6 +111,11 @@ func NewApplication(p api.ProxyOutpostConfig, c *http.Client, cs *ak.CryptoStore | ||||
| 			user := "" | ||||
| 			if c != nil { | ||||
| 				user = c.PreferredUsername | ||||
| 				sentry.GetHubFromContext(r.Context()).Scope().SetUser(sentry.User{ | ||||
| 					Username:  user, | ||||
| 					ID:        c.Sub, | ||||
| 					IPAddress: r.RemoteAddr, | ||||
| 				}) | ||||
| 			} | ||||
| 			before := time.Now() | ||||
| 			inner.ServeHTTP(rw, r) | ||||
| @ -124,6 +131,7 @@ func NewApplication(p api.ProxyOutpostConfig, c *http.Client, cs *ak.CryptoStore | ||||
| 			}).Observe(float64(after)) | ||||
| 		}) | ||||
| 	}) | ||||
| 	mux.Use(sentryhttp.New(sentryhttp.Options{}).Handle) | ||||
|  | ||||
| 	// Support /start and /sign_in for backwards compatibility | ||||
| 	mux.HandleFunc("/akprox/start", a.handleRedirect) | ||||
|  | ||||
| @ -10,6 +10,7 @@ import ( | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	sentryhttp "github.com/getsentry/sentry-go/http" | ||||
| 	"github.com/gorilla/mux" | ||||
| 	"github.com/pires/go-proxyproto" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| @ -52,6 +53,7 @@ func NewProxyServer(ac *ak.APIController, portOffset int) *ProxyServer { | ||||
|  | ||||
| 	globalMux := rootMux.NewRoute().Subrouter() | ||||
| 	globalMux.Use(web.NewLoggingHandler(l.WithField("logger", "authentik.outpost.proxyv2.http"), nil)) | ||||
| 	globalMux.Use(sentryhttp.New(sentryhttp.Options{}).Handle) | ||||
| 	s := &ProxyServer{ | ||||
| 		Listen:     "0.0.0.0:%d", | ||||
| 		PortOffset: portOffset, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer