mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-25 00:32:15 +00:00
* 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 <[email protected]> * fix: refactoring and fixes through PR review * fix: add auth service to lists of resourceAPIs --------- Co-authored-by: Tim Möhlmann <[email protected]> Co-authored-by: Fabi <[email protected]>
33 lines
856 B
Go
33 lines
856 B
Go
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))
|
|
})
|
|
}
|
|
}
|