From c850422cc496f85edac00897b9e960942efcab92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Urban?= Date: Wed, 11 Oct 2023 13:57:21 +0200 Subject: [PATCH] fix(backend): fix go dependencies --- backend/cmd/kubevoyage/main.go | 2 +- backend/go.mod | 2 +- backend/go.sum | 2 -- backend/internal/handlers/middleware.go | 6 +++--- backend/internal/handlers/requests.go | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/cmd/kubevoyage/main.go b/backend/cmd/kubevoyage/main.go index 844930f..0e79dc6 100644 --- a/backend/cmd/kubevoyage/main.go +++ b/backend/cmd/kubevoyage/main.go @@ -68,7 +68,7 @@ func setupServer(handle *handlers.Handler) http.Handler { handle.HandleAuthenticate(w, r) }) mux.HandleFunc("/api/request", func(w http.ResponseWriter, r *http.Request) { - handlers.HandleRequestSite(w, r, db) + handle.HandleRequestSite(w, r, db) }) return handler diff --git a/backend/go.mod b/backend/go.mod index b9e9a07..b2987fa 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -3,6 +3,7 @@ module github.com/B-Urb/KubeVoyage go 1.21 require ( + github.com/golang-jwt/jwt/v5 v5.0.0 github.com/rs/cors v1.10.0 github.com/stretchr/testify v1.8.4 golang.org/x/crypto v0.13.0 @@ -15,7 +16,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect - github.com/golang-jwt/jwt/v5 v5.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.3.1 // indirect diff --git a/backend/go.sum b/backend/go.sum index 8fa8c51..5887347 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -2,8 +2,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= diff --git a/backend/internal/handlers/middleware.go b/backend/internal/handlers/middleware.go index f884435..0627c6b 100644 --- a/backend/internal/handlers/middleware.go +++ b/backend/internal/handlers/middleware.go @@ -1,7 +1,7 @@ package handlers import ( - "github.com/dgrijalva/jwt-go" + "github.com/golang-jwt/jwt/v5" "net/http" "net/url" ) @@ -16,7 +16,7 @@ func handleUnauthenticated(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, url.QueryEscape(redirectURL), http.StatusSeeOther) } -func authenticate(next http.HandlerFunc) http.HandlerFunc { +func (h *Handler) authenticate(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cookie, err := r.Cookie("auth_token") if err != nil { @@ -28,7 +28,7 @@ func authenticate(next http.HandlerFunc) http.HandlerFunc { claims := &jwt.MapClaims{} token, err := jwt.ParseWithClaims(tokenStr, claims, func(token *jwt.Token) (interface{}, error) { - return jwtKey, nil + return h.JWTKey, nil }) if err != nil || !token.Valid { diff --git a/backend/internal/handlers/requests.go b/backend/internal/handlers/requests.go index b3a4a6d..80f43ae 100644 --- a/backend/internal/handlers/requests.go +++ b/backend/internal/handlers/requests.go @@ -31,8 +31,8 @@ func HandleRequests(w http.ResponseWriter, r *http.Request, db *gorm.DB) { } -func HandleRequestSite(w http.ResponseWriter, r *http.Request, db *gorm.DB) { - userEmail, err := getUserEmailFromToken(r) +func (h *Handler) HandleRequestSite(w http.ResponseWriter, r *http.Request, db *gorm.DB) { + userEmail, err := h.getUserEmailFromToken(r) if err != nil { http.Error(w, err.Error(), http.StatusUnauthorized) return