e871b05b38
CI / Test (linux/amd64) (pull_request) Successful in 34s
CI / Lint (pull_request) Failing after 16s
CI / Build (windows/amd64) (pull_request) Successful in 22s
CI / Build (linux/amd64) (pull_request) Successful in 20s
CI / Build (linux/arm64) (pull_request) Successful in 21s
Cleanup pass over the repo so CI can enforce lint going forward
without the only-new-issues escape hatch:
* gofumpt -w across the tree (31 hits, all formatting)
* misspell --fix (25 hits, US-locale spelling) — but reverted on
api.JobCancelled = "cancelled" since that literal is the wire +
DB CHECK constraint value, plus matched the case in store/fleet.go
back to "cancelled" and added //nolint:misspell on both for the
next time someone reaches for the auto-fix
* Wrap every `defer rows.Close()` / `defer stmt.Close()` /
`defer res.Body.Close()` in `defer func() { _ = .Close() }()`
to satisfy errcheck without losing the close itself
* websocket.Dial callers (1 prod, 4 tests) now capture + close the
upgrade response Body — coder/websocket can return res with a nil
Body on success, so the test deferred-closes guard against that
* Annotate the two genuine-by-design nilerr cases with //nolint
comments explaining why nil-on-error is the contract (cookie
missing = no session; ctx cancelled mid-backoff = clean shutdown)
* Add brief godoc on the 10 exported const groups + types that
revive flagged (api.HostOS/HostArch/JobKind/JobStatus/LogStream/
ErrorCode, restic.EventKind, store.Role, web.FS)
* Drop the unused (*Server).userByID method
* Inline the unparam baseView(active) — every UI page is under
the dashboard primary nav today
Result: `golangci-lint run ./...` reports 0 issues. CI lint job
no longer needs only-new-issues: true; X-06 follow-up entry in
tasks.md removed.
37 lines
920 B
Go
37 lines
920 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// AppendAudit records an audit log entry.
|
|
func (s *Store) AppendAudit(ctx context.Context, e AuditEntry) error {
|
|
if len(e.Payload) == 0 {
|
|
e.Payload = json.RawMessage("{}")
|
|
}
|
|
_, err := s.db.ExecContext(ctx,
|
|
`INSERT INTO audit_log (id, user_id, actor, action, target_kind, target_id, ts, payload)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
e.ID, nullable(e.UserID), e.Actor, e.Action,
|
|
nullable(e.TargetKind), nullable(e.TargetID),
|
|
e.TS.UTC().Format(time.RFC3339Nano),
|
|
string(e.Payload))
|
|
if err != nil {
|
|
return fmt.Errorf("store: append audit: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// nullable returns nil for nil/empty *string so SQLite stores NULL.
|
|
// SQLite's driver treats Go nil as NULL but treats *string("") as ”.
|
|
// We want NULL semantics for "absent."
|
|
func nullable(p *string) any {
|
|
if p == nil || *p == "" {
|
|
return nil
|
|
}
|
|
return *p
|
|
}
|