Skip to content

Commit a60c1f7

Browse files
committed
backend renaming and more docs
1 parent 49b69b4 commit a60c1f7

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

coderd/audit/backends/postgres.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/coder/coder/coderd/database"
1010
)
1111

12-
type pgBackend struct {
12+
type postgresBackend struct {
1313
// internal indicates if the exporter is exporting to the Postgres database
1414
// that the rest of Coderd uses. Since this is a generic Postgres exporter,
1515
// we make different decisions to store the audit log based on if it's
@@ -18,19 +18,19 @@ type pgBackend struct {
1818
db database.Store
1919
}
2020

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}
2323
}
2424

25-
func (b *pgBackend) Decision() audit.FilterDecision {
25+
func (b *postgresBackend) Decision() audit.FilterDecision {
2626
if b.internal {
2727
return audit.FilterDecisionStore
2828
}
2929

3030
return audit.FilterDecisionExport
3131
}
3232

33-
func (b *pgBackend) Export(ctx context.Context, alog database.AuditLog) error {
33+
func (b *postgresBackend) Export(ctx context.Context, alog database.AuditLog) error {
3434
_, err := b.db.InsertAuditLog(ctx, database.InsertAuditLogParams{
3535
ID: alog.ID,
3636
Time: alog.Time,

coderd/audit/backends/postgres_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestPostgresBackend(t *testing.T) {
2424
var (
2525
ctx, cancel = context.WithCancel(context.Background())
2626
db = databasefake.New()
27-
pgb = backends.NewPGBackend(db, true)
27+
pgb = backends.NewPostgres(db, true)
2828
alog = randomAuditLog()
2929
)
3030
defer cancel()

coderd/audit/backends/slog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type slogBackend struct {
1414
log slog.Logger
1515
}
1616

17-
func NewSlogBackend(logger slog.Logger) audit.Backend {
17+
func NewSlog(logger slog.Logger) audit.Backend {
1818
return slogBackend{log: logger}
1919
}
2020

coderd/audit/backends/slog_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestSlogBackend(t *testing.T) {
2121

2222
sink = &fakeSink{}
2323
logger = slog.Make(sink)
24-
backend = backends.NewSlogBackend(logger)
24+
backend = backends.NewSlog(logger)
2525

2626
alog = randomAuditLog()
2727
)

coderd/audit/exporter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@ import (
88
"github.com/coder/coder/coderd/database"
99
)
1010

11-
// Backends can accept and store or send audit logs elsewhere.
11+
// Backends can store or send audit logs to arbitrary locations.
1212
type Backend interface {
1313
// Decision determines the FilterDecisions that the backend tolerates.
1414
Decision() FilterDecision
1515
// Export sends an audit log to the backend.
1616
Export(ctx context.Context, alog database.AuditLog) error
1717
}
1818

19-
// Exporter exports audit logs to an arbitrary amount of backends.
19+
// Exporter exports audit logs to an arbitrary list of backends.
2020
type Exporter struct {
2121
filter Filter
2222
backends []Backend
2323
}
2424

25+
// NewExporter creates an exporter from the given filter and backends.
2526
func NewExporter(filter Filter, backends ...Backend) *Exporter {
2627
return &Exporter{
2728
filter: filter,
2829
backends: backends,
2930
}
3031
}
3132

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.
3236
func (e *Exporter) Export(ctx context.Context, alog database.AuditLog) error {
3337
for _, backend := range e.backends {
3438
decision, err := e.filter.Check(ctx, alog)

0 commit comments

Comments
 (0)