From b225e39ac48f6b6461af65e4b32c101a4edef983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=C3=A9=20Wilke?= <francewilke@gmail.com> Date: Thu, 27 Feb 2025 13:51:43 +0200 Subject: [PATCH] Use ip_utils.GetRequestSourceIP when getting the source IP --- api_logs/api-logs.go | 3 ++- auth/session.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/api_logs/api-logs.go b/api_logs/api-logs.go index d486db3..e648f0c 100644 --- a/api_logs/api-logs.go +++ b/api_logs/api-logs.go @@ -2,6 +2,7 @@ package api_logs import ( "github.com/thoas/go-funk" + "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/ip_utils" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/number_utils" "net/url" "strings" @@ -80,7 +81,7 @@ func GenerateIncomingAPILog(startTime time.Time, requestID *string, claim map[st RequestID: currentRequestID, InitialAuthType: authType, InitialAuthUsername: authUsername, - SourceIP: req.RequestContext.Identity.SourceIP, + SourceIP: ip_utils.GetRequestSourceIP(&req, nil), UserAgent: req.RequestContext.Identity.UserAgent, UserID: userID, Username: username, diff --git a/auth/session.go b/auth/session.go index da9035e..6d1d94f 100644 --- a/auth/session.go +++ b/auth/session.go @@ -10,6 +10,7 @@ import ( "github.com/thoas/go-funk" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/date_utils" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/handler_utils" + "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/ip_utils" "time" ) @@ -30,7 +31,7 @@ func SignSessionTokenWithKey(secretKey string, sessionTokenString string) string // GetSessionTokenString creates a unique session token string from the API request. func GetSessionTokenString(request events.APIGatewayProxyRequest) (string, error) { sessionToken := SessionToken{ - IP: request.RequestContext.Identity.SourceIP, + IP: ip_utils.GetRequestSourceIP(&request, nil), UserAgent: handler_utils.FindHeaderValue(request.Headers, "user-agent"), TimeCreated: date_utils.CurrentDate().Round(time.Second), Token: uuid.New().String(), -- GitLab