Files
coder/coderd/audit/audit.go
Kyle Carberry 22e781eced chore: add /v2 to import module path (#9072)
* chore: add /v2 to import module path

go mod requires semantic versioning with versions greater than 1.x

This was a mechanical update by running:
```
go install github.com/marwan-at-work/mod/cmd/mod@latest
mod upgrade
```

Migrate generated files to import /v2

* Fix gen
2023-08-18 18:55:43 +00:00

71 lines
1.4 KiB
Go

package audit
import (
"context"
"sync"
"github.com/coder/coder/v2/coderd/database"
)
type Auditor interface {
Export(ctx context.Context, alog database.AuditLog) error
diff(old, new any) Map
}
type AdditionalFields struct {
WorkspaceName string `json:"workspace_name"`
BuildNumber string `json:"build_number"`
BuildReason database.BuildReason `json:"build_reason"`
WorkspaceOwner string `json:"workspace_owner"`
}
func NewNop() Auditor {
return nop{}
}
type nop struct{}
func (nop) Export(context.Context, database.AuditLog) error {
return nil
}
func (nop) diff(any, any) Map {
return Map{}
}
func NewMock() *MockAuditor {
return &MockAuditor{}
}
type MockAuditor struct {
mutex sync.Mutex
auditLogs []database.AuditLog
}
// ResetLogs removes all audit logs from the mock auditor.
// This is helpful for testing to get a clean slate.
func (a *MockAuditor) ResetLogs() {
a.mutex.Lock()
defer a.mutex.Unlock()
a.auditLogs = make([]database.AuditLog, 0)
}
func (a *MockAuditor) AuditLogs() []database.AuditLog {
a.mutex.Lock()
defer a.mutex.Unlock()
logs := make([]database.AuditLog, len(a.auditLogs))
copy(logs, a.auditLogs)
return logs
}
func (a *MockAuditor) Export(_ context.Context, alog database.AuditLog) error {
a.mutex.Lock()
defer a.mutex.Unlock()
a.auditLogs = append(a.auditLogs, alog)
return nil
}
func (*MockAuditor) diff(any, any) Map {
return Map{}
}