feat: Add audit logging (#38189)

Co-authored-by: bircni <bircni@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
bircni
2026-09-12 08:15:23 +00:00
committed by GitHub
co-authored by bircni wxiaoguang
parent 4d43445532
commit da37b7916b
136 changed files with 3863 additions and 208 deletions
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package common
import (
"net/http"
audit_model "gitea.dev/models/audit"
"gitea.dev/modules/httplib"
"gitea.dev/modules/reqctx"
audit_service "gitea.dev/services/audit"
)
// AuditOrigin publishes the origin and the client address of the request, so
// audit events recorded while serving it are attributed to it.
func AuditOrigin(origin audit_model.Origin) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if store := reqctx.GetRequestDataStore(req.Context()); store != nil {
audit_service.SetRequestInfo(store, origin, httplib.RemoteHost(req))
}
next.ServeHTTP(resp, req)
})
}
}