Skip to content

Commit 31f1722

Browse files
authored
Merge pull request #4 from coder/audit-package
Add audit package and simplify rules to boolean logic
2 parents 7b60fd0 + 4e2a4d3 commit 31f1722

File tree

9 files changed

+890
-305
lines changed

9 files changed

+890
-305
lines changed

audit/logging_auditor.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package audit
2+
3+
import "log/slog"
4+
5+
// LoggingAuditor implements Auditor by logging to slog
6+
type LoggingAuditor struct {
7+
logger *slog.Logger
8+
}
9+
10+
// NewLoggingAuditor creates a new LoggingAuditor
11+
func NewLoggingAuditor(logger *slog.Logger) *LoggingAuditor {
12+
return &LoggingAuditor{
13+
logger: logger,
14+
}
15+
}
16+
17+
// AuditRequest logs the request using structured logging
18+
func (a *LoggingAuditor) AuditRequest(req *Request) {
19+
if req.Allowed {
20+
a.logger.Info("ALLOW",
21+
"method", req.Method,
22+
"url", req.URL,
23+
"rule", req.Rule)
24+
} else {
25+
a.logger.Warn("DENY",
26+
"method", req.Method,
27+
"url", req.URL)
28+
}
29+
}

0 commit comments

Comments
 (0)