Files
gitea/routers/common/audit.go
T
bircni da37b7916b feat: Add audit logging (#38189)
Co-authored-by: bircni <bircni@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-09-12 08:15:23 +00:00

27 lines
809 B
Go

// 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)
})
}
}