MCPcopy Create free account
hub / github.com/astercloud/aster / matchesQuery

Method matchesQuery

pkg/security/audit.go:545–586  ·  view source on GitHub ↗

matchesQuery 检查事件是否匹配查询条件

(event *AuditEvent, query *AuditQuery)

Source from the content-addressed store, hash-verified

543
544// matchesQuery 检查事件是否匹配查询条件
545func (al *InMemoryAuditLog) matchesQuery(event *AuditEvent, query *AuditQuery) bool {
546 // 时间范围过滤
547 if query.TimeRange != nil {
548 if event.Timestamp.Before(query.TimeRange.Start) || event.Timestamp.After(query.TimeRange.End) {
549 return false
550 }
551 }
552
553 // 类型过滤
554 if len(query.Types) > 0 && !containsAuditType(query.Types, event.Type) {
555 return false
556 }
557
558 // 严重级别过滤
559 if len(query.Severities) > 0 && !containsAuditSeverity(query.Severities, event.Severity) {
560 return false
561 }
562
563 // 用户过滤
564 if len(query.Users) > 0 && !containsString(query.Users, event.UserID) {
565 return false
566 }
567
568 // 资源过滤
569 if len(query.Resources) > 0 && !containsString(query.Resources, event.Resource) {
570 return false
571 }
572
573 // 操作过滤
574 if len(query.Actions) > 0 && !containsString(query.Actions, event.Action) {
575 return false
576 }
577
578 // 文本搜索
579 if query.SearchText != "" {
580 if !containsSearchText(event, query.SearchText) {
581 return false
582 }
583 }
584
585 return true
586}
587
588// sortEvents 排序事件
589func (al *InMemoryAuditLog) sortEvents(events []*AuditEvent, orderBy string, desc bool) {

Callers 1

QueryEventsMethod · 0.95

Calls 4

containsAuditTypeFunction · 0.85
containsAuditSeverityFunction · 0.85
containsSearchTextFunction · 0.85
containsStringFunction · 0.70

Tested by

no test coverage detected