feat(api): 审计查询支持按结果筛选
- AuditFilter 增加 Result 字段,Query 按 result 精确过滤 - GET /audit 接口解析 result 查询参数(success/failed)
This commit is contained in:
@@ -53,6 +53,7 @@ func (h *AuditHandler) List(c *gin.Context) {
|
|||||||
Action: c.Query("action"),
|
Action: c.Query("action"),
|
||||||
ResourceType: c.Query("resource_type"),
|
ResourceType: c.Query("resource_type"),
|
||||||
ResourceID: c.Query("resource_id"),
|
ResourceID: c.Query("resource_id"),
|
||||||
|
Result: c.Query("result"),
|
||||||
Since: since,
|
Since: since,
|
||||||
Until: until,
|
Until: until,
|
||||||
Page: page,
|
Page: page,
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ type AuditFilter struct {
|
|||||||
Action string // 动作精确匹配
|
Action string // 动作精确匹配
|
||||||
ResourceType string // 资源类型(user / ssh_key / approval ...)
|
ResourceType string // 资源类型(user / ssh_key / approval ...)
|
||||||
ResourceID string // 资源 ID
|
ResourceID string // 资源 ID
|
||||||
|
Result string // 结果(success / failed)
|
||||||
Since *time.Time // 起始时间(含)
|
Since *time.Time // 起始时间(含)
|
||||||
Until *time.Time // 结束时间(含)
|
Until *time.Time // 结束时间(含)
|
||||||
Page int
|
Page int
|
||||||
@@ -74,6 +75,9 @@ func (s *AuditService) Query(ctx context.Context, f AuditFilter) ([]model.AuditL
|
|||||||
if f.ResourceID != "" {
|
if f.ResourceID != "" {
|
||||||
q = q.Where("resource_id = ?", f.ResourceID)
|
q = q.Where("resource_id = ?", f.ResourceID)
|
||||||
}
|
}
|
||||||
|
if f.Result != "" {
|
||||||
|
q = q.Where("result = ?", f.Result)
|
||||||
|
}
|
||||||
if f.Since != nil {
|
if f.Since != nil {
|
||||||
q = q.Where("created_at >= ?", *f.Since)
|
q = q.Where("created_at >= ?", *f.Since)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user