mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add audit exporting and filtering (#1314)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
)
|
||||
|
||||
// FilterDecision is a bitwise flag describing the actions a given filter allows
|
||||
// for a given audit log.
|
||||
type FilterDecision uint8
|
||||
|
||||
const (
|
||||
// FilterDecisionDrop indicates that the audit log should be dropped. It
|
||||
// should not be stored or exported anywhere.
|
||||
FilterDecisionDrop FilterDecision = 0
|
||||
// FilterDecisionStore indicates that the audit log should be allowed to be
|
||||
// stored in the Coder database.
|
||||
FilterDecisionStore FilterDecision = 1 << iota
|
||||
// FilterDecisionExport indicates that the audit log should be exported
|
||||
// externally of Coder.
|
||||
FilterDecisionExport
|
||||
)
|
||||
|
||||
// Filters produce a FilterDecision for a given audit log.
|
||||
type Filter interface {
|
||||
Check(ctx context.Context, alog database.AuditLog) (FilterDecision, error)
|
||||
}
|
||||
|
||||
// DefaultFilter is the default filter used when exporting audit logs. It allows
|
||||
// storage and exporting for all audit logs.
|
||||
var DefaultFilter Filter = FilterFunc(func(ctx context.Context, alog database.AuditLog) (FilterDecision, error) {
|
||||
// Store and export all audit logs for now.
|
||||
return FilterDecisionStore | FilterDecisionExport, nil
|
||||
})
|
||||
|
||||
// FilterFunc constructs a Filter from a simple function.
|
||||
type FilterFunc func(ctx context.Context, alog database.AuditLog) (FilterDecision, error)
|
||||
|
||||
func (f FilterFunc) Check(ctx context.Context, alog database.AuditLog) (FilterDecision, error) {
|
||||
return f(ctx, alog)
|
||||
}
|
||||
Reference in New Issue
Block a user