File tree Expand file tree Collapse file tree 5 files changed +14
-10
lines changed Expand file tree Collapse file tree 5 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 9
9
"github.com/coder/coder/coderd/database"
10
10
)
11
11
12
- type pgBackend struct {
12
+ type postgresBackend struct {
13
13
// internal indicates if the exporter is exporting to the Postgres database
14
14
// that the rest of Coderd uses. Since this is a generic Postgres exporter,
15
15
// we make different decisions to store the audit log based on if it's
@@ -18,19 +18,19 @@ type pgBackend struct {
18
18
db database.Store
19
19
}
20
20
21
- func NewPGBackend (db database.Store , internal bool ) audit.Backend {
22
- return & pgBackend {db : db , internal : internal }
21
+ func NewPostgres (db database.Store , internal bool ) audit.Backend {
22
+ return & postgresBackend {db : db , internal : internal }
23
23
}
24
24
25
- func (b * pgBackend ) Decision () audit.FilterDecision {
25
+ func (b * postgresBackend ) Decision () audit.FilterDecision {
26
26
if b .internal {
27
27
return audit .FilterDecisionStore
28
28
}
29
29
30
30
return audit .FilterDecisionExport
31
31
}
32
32
33
- func (b * pgBackend ) Export (ctx context.Context , alog database.AuditLog ) error {
33
+ func (b * postgresBackend ) Export (ctx context.Context , alog database.AuditLog ) error {
34
34
_ , err := b .db .InsertAuditLog (ctx , database.InsertAuditLogParams {
35
35
ID : alog .ID ,
36
36
Time : alog .Time ,
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func TestPostgresBackend(t *testing.T) {
24
24
var (
25
25
ctx , cancel = context .WithCancel (context .Background ())
26
26
db = databasefake .New ()
27
- pgb = backends .NewPGBackend (db , true )
27
+ pgb = backends .NewPostgres (db , true )
28
28
alog = randomAuditLog ()
29
29
)
30
30
defer cancel ()
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ type slogBackend struct {
14
14
log slog.Logger
15
15
}
16
16
17
- func NewSlogBackend (logger slog.Logger ) audit.Backend {
17
+ func NewSlog (logger slog.Logger ) audit.Backend {
18
18
return slogBackend {log : logger }
19
19
}
20
20
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ func TestSlogBackend(t *testing.T) {
21
21
22
22
sink = & fakeSink {}
23
23
logger = slog .Make (sink )
24
- backend = backends .NewSlogBackend (logger )
24
+ backend = backends .NewSlog (logger )
25
25
26
26
alog = randomAuditLog ()
27
27
)
Original file line number Diff line number Diff line change @@ -8,27 +8,31 @@ import (
8
8
"github.com/coder/coder/coderd/database"
9
9
)
10
10
11
- // Backends can accept and store or send audit logs elsewhere .
11
+ // Backends can store or send audit logs to arbitrary locations .
12
12
type Backend interface {
13
13
// Decision determines the FilterDecisions that the backend tolerates.
14
14
Decision () FilterDecision
15
15
// Export sends an audit log to the backend.
16
16
Export (ctx context.Context , alog database.AuditLog ) error
17
17
}
18
18
19
- // Exporter exports audit logs to an arbitrary amount of backends.
19
+ // Exporter exports audit logs to an arbitrary list of backends.
20
20
type Exporter struct {
21
21
filter Filter
22
22
backends []Backend
23
23
}
24
24
25
+ // NewExporter creates an exporter from the given filter and backends.
25
26
func NewExporter (filter Filter , backends ... Backend ) * Exporter {
26
27
return & Exporter {
27
28
filter : filter ,
28
29
backends : backends ,
29
30
}
30
31
}
31
32
33
+ // Export exports and audit log. Before exporting to a backend, it uses the
34
+ // filter to determine if the backend tolerates the audit log. If not, it is
35
+ // dropped.
32
36
func (e * Exporter ) Export (ctx context.Context , alog database.AuditLog ) error {
33
37
for _ , backend := range e .backends {
34
38
decision , err := e .filter .Check (ctx , alog )
You can’t perform that action at this time.
0 commit comments