mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 22:46:09 -05:00
The audit log tests read the audit records from a copy of the server output, which the CI wrote with "| tee" to a file given to the tests in AUDIT_RECORDS_FILE. The ocwrapper reads the server output anyway: it now keeps the audit records, and returns them on GET /audit (DELETE /audit clears them). The tests clear them when a scenario starts and fetch them from there, so they need no extra setup in the CI or locally. Assisted-by: Claude Code:claude-opus-5-5
39 lines
1003 B
Go
39 lines
1003 B
Go
package opencloud
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// The audit service writes every audit record as one line of JSON to stdout.
|
|
// The wrapper keeps these lines, so that the tests can fetch them (GET /audit).
|
|
var (
|
|
auditMu sync.Mutex
|
|
auditRecords = []json.RawMessage{}
|
|
)
|
|
|
|
// collectAuditRecord keeps the line if it is an audit record
|
|
func collectAuditRecord(line string) {
|
|
if !strings.HasPrefix(line, "{") || !strings.Contains(line, `"event.name"`) || !json.Valid([]byte(line)) {
|
|
return
|
|
}
|
|
auditMu.Lock()
|
|
defer auditMu.Unlock()
|
|
auditRecords = append(auditRecords, json.RawMessage(line))
|
|
}
|
|
|
|
// AuditRecords returns the audit records written since the last ClearAuditRecords
|
|
func AuditRecords() []json.RawMessage {
|
|
auditMu.Lock()
|
|
defer auditMu.Unlock()
|
|
return append([]json.RawMessage{}, auditRecords...)
|
|
}
|
|
|
|
// ClearAuditRecords forgets the audit records kept so far
|
|
func ClearAuditRecords() {
|
|
auditMu.Lock()
|
|
defer auditMu.Unlock()
|
|
auditRecords = []json.RawMessage{}
|
|
}
|