241e3b5f2d
- Introduced a new `auditlog` package to handle audit logging for user actions, including creation, updates, deletions, and authentication events. - Enhanced existing services (customer, user) to log relevant actions using the new audit logger, capturing details such as actor ID, action type, target type, and success status. - Added middleware to enrich request context with metadata for audit logging, ensuring comprehensive tracking of user interactions. - Integrated Elasticsearch for persistent storage of audit logs, with fallback to file-only logging if Elasticsearch is unavailable. - Updated API documentation to include new audit log endpoints for administrative access. This update significantly improves the system's ability to track and audit user actions, enhancing security and accountability within the application.
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package auditlog
|
|
|
|
// Entry represents an audit log record returned by the API.
|
|
type Entry struct {
|
|
ActorID string `json:"actor_id"`
|
|
ActorType string `json:"actor_type"`
|
|
Action string `json:"action"`
|
|
TargetType string `json:"target_type"`
|
|
TargetID string `json:"target_id"`
|
|
At int64 `json:"at"`
|
|
IP string `json:"ip,omitempty"`
|
|
RequestID string `json:"request_id,omitempty"`
|
|
UserAgent string `json:"user_agent,omitempty"`
|
|
Success bool `json:"success"`
|
|
Metadata map[string]string `json:"metadata,omitempty"`
|
|
}
|
|
|
|
// ListResponse is the paginated audit log list response.
|
|
type ListResponse struct {
|
|
Logs []*Entry `json:"logs"`
|
|
Meta *ListMeta `json:"meta,omitempty"`
|
|
}
|
|
|
|
// ListMeta contains pagination metadata.
|
|
type ListMeta struct {
|
|
Total int64 `json:"total"`
|
|
Limit int `json:"limit"`
|
|
Offset int `json:"offset"`
|
|
Page int `json:"page"`
|
|
Pages int `json:"pages"`
|
|
}
|