Files
coder/enterprise/audit/backends/postgres.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

41 lines
1018 B
Go

package backends
import (
"context"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/enterprise/audit"
)
type postgresBackend struct {
// internal indicates if the exporter is exporting to the Postgres database
// that the rest of Coderd uses. Since this is a generic Postgres exporter,
// we make different decisions to store the audit log based on if it's
// pointing to the Coderd database.
internal bool
db database.Store
}
func NewPostgres(db database.Store, internal bool) audit.Backend {
return &postgresBackend{db: db, internal: internal}
}
func (b *postgresBackend) Decision() audit.FilterDecision {
if b.internal {
return audit.FilterDecisionStore
}
return audit.FilterDecisionExport
}
func (b *postgresBackend) Export(ctx context.Context, alog database.AuditLog) error {
_, err := b.db.InsertAuditLog(ctx, database.InsertAuditLogParams(alog))
if err != nil {
return xerrors.Errorf("insert audit log: %w", err)
}
return nil
}