refactor: extract request context utilities into dedicated package
Move ClaimsFromContext and MustUserID helpers from httpserver to new requestctx package for better separation of concerns. Update all imports across auth, device, policy, and user handlers. Fix Dockerfile to copy go.sum and run go mod tidy before download.
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/nexavpn/nexavpn/backend/internal/apiutil"
|
||||
"github.com/nexavpn/nexavpn/backend/internal/audit"
|
||||
"github.com/nexavpn/nexavpn/backend/internal/httpserver"
|
||||
"github.com/nexavpn/nexavpn/backend/internal/requestctx"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
@@ -28,7 +28,7 @@ func (h *Handler) Enroll(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
userID, ok := httpserver.MustUserID(r.Context())
|
||||
userID, ok := requestctx.MustUserID(r.Context())
|
||||
if !ok {
|
||||
apiutil.Error(w, http.StatusUnauthorized, "unauthorized", "missing auth claims")
|
||||
return
|
||||
@@ -56,7 +56,7 @@ func (h *Handler) Enroll(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *Handler) ListOwn(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := httpserver.MustUserID(r.Context())
|
||||
userID, ok := requestctx.MustUserID(r.Context())
|
||||
if !ok {
|
||||
apiutil.Error(w, http.StatusUnauthorized, "unauthorized", "missing auth claims")
|
||||
return
|
||||
@@ -82,7 +82,7 @@ func (h *Handler) ListAll(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *Handler) ConnectionStatus(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := httpserver.MustUserID(r.Context())
|
||||
userID, ok := requestctx.MustUserID(r.Context())
|
||||
if !ok {
|
||||
apiutil.Error(w, http.StatusUnauthorized, "unauthorized", "missing auth claims")
|
||||
return
|
||||
@@ -98,7 +98,7 @@ func (h *Handler) ConnectionStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *Handler) GetOwnProfile(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := httpserver.MustUserID(r.Context())
|
||||
userID, ok := requestctx.MustUserID(r.Context())
|
||||
if !ok {
|
||||
apiutil.Error(w, http.StatusUnauthorized, "unauthorized", "missing auth claims")
|
||||
return
|
||||
@@ -139,7 +139,7 @@ func (h *Handler) Revoke(w http.ResponseWriter, r *http.Request) {
|
||||
apiutil.Error(w, http.StatusInternalServerError, "device_revoke_failed", "unable to revoke device")
|
||||
return
|
||||
}
|
||||
if claims, ok := httpserver.ClaimsFromContext(r.Context()); ok {
|
||||
if claims, ok := requestctx.ClaimsFromContext(r.Context()); ok {
|
||||
_ = h.audit.Record(r.Context(), audit.Entry{
|
||||
ActorUserID: &claims.UserID,
|
||||
EntityType: "device",
|
||||
@@ -162,7 +162,7 @@ func (h *Handler) Rotate(w http.ResponseWriter, r *http.Request) {
|
||||
apiutil.Error(w, http.StatusInternalServerError, "device_rotate_failed", "unable to rotate device profile")
|
||||
return
|
||||
}
|
||||
if claims, ok := httpserver.ClaimsFromContext(r.Context()); ok {
|
||||
if claims, ok := requestctx.ClaimsFromContext(r.Context()); ok {
|
||||
_ = h.audit.Record(r.Context(), audit.Entry{
|
||||
ActorUserID: &claims.UserID,
|
||||
EntityType: "device",
|
||||
|
||||
Reference in New Issue
Block a user