mirror of
https://github.com/harness/drone.git
synced 2025-05-03 10:40:04 +08:00
feat:[ML-534]: store path with audit middleware (#3256)
* feat:[ML-534]: store path with audit middleware
This commit is contained in:
parent
90858bcbaa
commit
15fdf984f3
@ -22,6 +22,7 @@ const (
|
|||||||
realIPKey key = iota
|
realIPKey key = iota
|
||||||
requestID
|
requestID
|
||||||
requestMethod
|
requestMethod
|
||||||
|
pathKey
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetRealIP returns IP address from context.
|
// GetRealIP returns IP address from context.
|
||||||
@ -34,6 +35,16 @@ func GetRealIP(ctx context.Context) string {
|
|||||||
return ip
|
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.
|
// GetRequestID returns requestID from context.
|
||||||
func GetRequestID(ctx context.Context) string {
|
func GetRequestID(ctx context.Context) string {
|
||||||
id, ok := ctx.Value(requestID).(string)
|
id, ok := ctx.Value(requestID).(string)
|
||||||
|
@ -36,6 +36,7 @@ func Middleware() func(next http.Handler) http.Handler {
|
|||||||
ctx = context.WithValue(ctx, realIPKey, rip)
|
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, requestMethod, r.Method)
|
||||||
ctx = context.WithValue(ctx, requestID, w.Header().Get("X-Request-Id"))
|
ctx = context.WithValue(ctx, requestID, w.Header().Get("X-Request-Id"))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user