feat(access): instance network rules at the capture receiver; policies reload without a restart

This commit is contained in:
sam committed 2026-10-04 12:58:00 +11:00
1 parent 8f519006ab
commit f298befb6b
33 files changed
+1682 -814

No files matched your search

@@ -69,6 +69,50 @@ func (q *Queries) ArmedBindingsForSource(ctx context.Context, source string) ([]
return items, nil
}
const captureRefusalSummary = `-- name: CaptureRefusalSummary :many
WITH r AS (
SELECT source, count(*) AS refused, array_agg(DISTINCT addr ORDER BY addr)::text[] AS addrs
FROM capture_refusals WHERE refused_at >= $1 GROUP BY source
), a AS (
SELECT source, count(*) AS accepted FROM captures WHERE received_at >= $1 GROUP BY source
)
SELECT r.source, r.refused, COALESCE(a.accepted, 0)::bigint AS accepted, r.addrs
FROM r LEFT JOIN a ON a.source = r.source
ORDER BY r.source
`
type CaptureRefusalSummaryRow struct {
Source string
Refused int64
Accepted int64
Addrs []string
}
func (q *Queries) CaptureRefusalSummary(ctx context.Context, refusedAt time.Time) ([]CaptureRefusalSummaryRow, error) {
rows, err := q.db.Query(ctx, captureRefusalSummary, refusedAt)
if err != nil {
return nil, err
}
defer rows.Close()
var items []CaptureRefusalSummaryRow
for rows.Next() {
var i CaptureRefusalSummaryRow
if err := rows.Scan(
&i.Source,
&i.Refused,
&i.Accepted,
&i.Addrs,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const deleteBinding = `-- name: DeleteBinding :execrows
DELETE FROM bindings WHERE id = $1
`
@@ -81,6 +125,15 @@ func (q *Queries) DeleteBinding(ctx context.Context, id string) (int64, error) {
return result.RowsAffected(), nil
}
const deleteCaptureRefusalsBefore = `-- name: DeleteCaptureRefusalsBefore :exec
DELETE FROM capture_refusals WHERE refused_at < $1
`
func (q *Queries) DeleteCaptureRefusalsBefore(ctx context.Context, refusedAt time.Time) error {
_, err := q.db.Exec(ctx, deleteCaptureRefusalsBefore, refusedAt)
return err
}
const deleteCapturesBeyondCount = `-- name: DeleteCapturesBeyondCount :exec
DELETE FROM captures WHERE id NOT IN (
SELECT id FROM captures ORDER BY received_at DESC LIMIT $1
@@ -399,6 +452,21 @@ func (q *Queries) InsertCapture(ctx context.Context, arg InsertCaptureParams) er
return err
}
const insertCaptureRefusal = `-- name: InsertCaptureRefusal :exec
INSERT INTO capture_refusals (source, addr, refused_at) VALUES ($1, $2, $3)
`
type InsertCaptureRefusalParams struct {
Source string
Addr string
RefusedAt time.Time
}
func (q *Queries) InsertCaptureRefusal(ctx context.Context, arg InsertCaptureRefusalParams) error {
_, err := q.db.Exec(ctx, insertCaptureRefusal, arg.Source, arg.Addr, arg.RefusedAt)
return err
}
const insertEventType = `-- name: InsertEventType :exec
INSERT INTO event_types (id, source, name, rule, schema)
VALUES ($1, $2, $3, $4, $5)
@@ -95,6 +95,12 @@ type Capture struct {
WorkspaceID string
}
type CaptureRefusal struct {
Source string
Addr string
RefusedAt time.Time
}
type ChannelStatus struct {
ID string
Name string