mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
feat: add activity logs on user actions with authentication, resource… (#6748)
* feat: add activity logs on user actions with authentication, resourceAPI and sessionAPI * feat: add activity logs on user actions with authentication, resourceAPI and sessionAPI * feat: add activity logs on user actions with authentication, resourceAPI and sessionAPI * feat: add activity logs on user actions with authentication, resourceAPI and sessionAPI * feat: add activity logs on user actions with authentication, resourceAPI and sessionAPI * fix: add unit tests to info package for context changes * fix: add activity_interceptor.go suggestion Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> * fix: refactoring and fixes through PR review * fix: add auth service to lists of resourceAPIs --------- Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> Co-authored-by: Fabi <fabienne@zitadel.com>
This commit is contained in:
32
internal/api/http/middleware/activity_interceptor.go
Normal file
32
internal/api/http/middleware/activity_interceptor.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/info"
|
||||
)
|
||||
|
||||
func ActivityHandler(handlerPrefixes []string) func(next http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
activityInfo := info.ActivityInfoFromContext(ctx)
|
||||
hasPrefix := false
|
||||
// only add path to context if handler is called
|
||||
for _, prefix := range handlerPrefixes {
|
||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||
activityInfo.SetPath(r.URL.Path)
|
||||
hasPrefix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// last call is with grpc method as path
|
||||
if !hasPrefix {
|
||||
activityInfo.SetMethod(r.URL.Path)
|
||||
}
|
||||
ctx = activityInfo.SetRequestMethod(r.Method).IntoContext(ctx)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user