feat:[ML-534]: store path with audit middleware (#3256)

* feat:[ML-534]: store path with audit middleware
This commit is contained in:
Cameron Motevasselani 2025-01-15 00:16:29 +00:00 committed by Harness
parent 90858bcbaa
commit 15fdf984f3
2 changed files with 12 additions and 0 deletions

View File

@ -22,6 +22,7 @@ const (
realIPKey key = iota
requestID
requestMethod
pathKey
)
// GetRealIP returns IP address from context.
@ -34,6 +35,16 @@ func GetRealIP(ctx context.Context) string {
return ip
}
// GetPath returns Path from context.
func GetPath(ctx context.Context) string {
path, ok := ctx.Value(pathKey).(string)
if !ok {
return ""
}
return path
}
// GetRequestID returns requestID from context.
func GetRequestID(ctx context.Context) string {
id, ok := ctx.Value(requestID).(string)

View File

@ -36,6 +36,7 @@ func Middleware() func(next http.Handler) http.Handler {
ctx = context.WithValue(ctx, realIPKey, rip)
}
ctx = context.WithValue(ctx, pathKey, r.URL.Path)
ctx = context.WithValue(ctx, requestMethod, r.Method)
ctx = context.WithValue(ctx, requestID, w.Header().Get("X-Request-Id"))