955 lines
42 KiB
Go
955 lines
42 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: audit_feed.sql
|
|
|
|
package postgresdb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const auditHead = `-- name: AuditHead :one
|
|
SELECT
|
|
(SELECT COALESCE(max(id), 0)::bigint FROM sys_audit WHERE org_id = $1::text) AS sys_audit_id,
|
|
(SELECT COALESCE(max(id), 0)::bigint FROM identity_events
|
|
WHERE ($2::boolean
|
|
OR (org_id IS NOT NULL AND org_id = $1::text))) AS identity_event_id,
|
|
(SELECT COALESCE(max(id), 0)::bigint FROM access_denials WHERE org_id = $1::text) AS access_denial_id,
|
|
(SELECT COALESCE(sum(count), 0)::bigint FROM access_denials WHERE org_id = $1::text) AS access_denial_count,
|
|
(SELECT COALESCE(max(id), 0)::bigint FROM events WHERE org_id = $1::text) AS event_id
|
|
`
|
|
|
|
type AuditHeadParams struct {
|
|
OrgID string
|
|
InstanceAdmin bool
|
|
}
|
|
|
|
type AuditHeadRow struct {
|
|
SysAuditID int64
|
|
IdentityEventID int64
|
|
AccessDenialID int64
|
|
AccessDenialCount int64
|
|
EventID int64
|
|
}
|
|
|
|
// A token over the newest id of each trail the caller can read, plus the
|
|
// denials' count sum because a coalesced denial bumps its count in place
|
|
// without drawing a new id. It carries no rows and no org data.
|
|
func (q *Queries) AuditHead(ctx context.Context, arg AuditHeadParams) (AuditHeadRow, error) {
|
|
row := q.db.QueryRow(ctx, auditHead, arg.OrgID, arg.InstanceAdmin)
|
|
var i AuditHeadRow
|
|
err := row.Scan(
|
|
&i.SysAuditID,
|
|
&i.IdentityEventID,
|
|
&i.AccessDenialID,
|
|
&i.AccessDenialCount,
|
|
&i.EventID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const countAudit = `-- name: CountAudit :one
|
|
WITH sys_changes AS (
|
|
SELECT
|
|
a.org_id,
|
|
a.table_name,
|
|
a.record_key,
|
|
a.request_id,
|
|
a.record_version,
|
|
a.at,
|
|
a.actor,
|
|
a.source,
|
|
bool_and(a.old_value IS NULL) AS all_old_null,
|
|
bool_and(a.new_value IS NULL) AS all_new_null,
|
|
bool_or(a.field = 'reset') AS is_reset,
|
|
count(DISTINCT a.field)::int AS field_count,
|
|
bool_or(a.field IN (
|
|
'org', 'workspace', 'role', 'org_id',
|
|
'mapping', 'binding', 'source', 'event_type',
|
|
'install', 'remove', 'credential'
|
|
)) AS whole_record_field,
|
|
string_agg(DISTINCT a.field, ' ') AS field_names
|
|
FROM sys_audit a
|
|
WHERE a.org_id = $11::text
|
|
AND (
|
|
COALESCE(cardinality($1::text[]), 0) = 0
|
|
OR (a.table_name = 'resources' AND 'settings' = ANY($1::text[]))
|
|
OR (a.table_name = 'access_policies' AND 'access' = ANY($1::text[]))
|
|
OR (a.table_name IN ('memberships', 'org_agents') AND 'access' = ANY($1::text[]))
|
|
OR (a.table_name IN ('bindings', 'mappings', 'event_types') AND 'automation' = ANY($1::text[]))
|
|
OR (
|
|
a.table_name NOT IN (
|
|
'resources', 'access_policies',
|
|
'memberships', 'org_agents',
|
|
'bindings', 'mappings', 'event_types'
|
|
)
|
|
AND 'settings' = ANY($1::text[])
|
|
)
|
|
)
|
|
AND ($12::timestamptz IS NULL OR a.at >= $12::timestamptz)
|
|
AND ($13::timestamptz IS NULL OR a.at < $13::timestamptz)
|
|
AND ($4::text IS NULL OR a.actor = $4::text)
|
|
GROUP BY a.org_id, a.table_name, a.record_key, a.request_id, a.record_version, a.at, a.actor, a.source
|
|
)
|
|
SELECT count(*)::bigint AS count
|
|
FROM (
|
|
SELECT
|
|
CASE t.table_name WHEN 'access_policies' THEN 'access' ELSE 'settings' END AS category,
|
|
CASE
|
|
WHEN t.table_name = 'access_policies' AND t.is_reset THEN 'reset'
|
|
WHEN t.table_name = 'access_policies' AND t.all_new_null AND t.record_version > 0 THEN 'delete'
|
|
WHEN t.table_name = 'access_policies' AND t.all_old_null THEN 'create'
|
|
WHEN t.table_name = 'resources' AND t.record_version = 1 AND t.all_old_null THEN 'create'
|
|
ELSE 'update'
|
|
END AS action,
|
|
CASE t.table_name
|
|
WHEN 'resources' THEN t.target_id
|
|
ELSE 'access_policy'
|
|
END AS kind,
|
|
t.actor,
|
|
CASE t.table_name
|
|
WHEN 'resources' THEN 'resource'
|
|
ELSE 'policy'
|
|
END AS target_kind,
|
|
t.target_id,
|
|
CASE
|
|
WHEN t.table_name = 'access_policies' AND t.is_reset THEN 'warning'
|
|
WHEN t.table_name = 'access_policies' AND t.all_new_null AND t.record_version > 0 THEN 'warning'
|
|
ELSE 'info'
|
|
END AS severity,
|
|
'success'::text AS outcome,
|
|
concat_ws(' ', t.record_key, t.actor, t.source, t.field_names, t.target_id) AS search_text
|
|
FROM (
|
|
SELECT
|
|
g.org_id, g.table_name, g.record_key, g.request_id,
|
|
g.record_version, g.at, g.actor, g.source,
|
|
g.all_old_null, g.all_new_null, g.is_reset,
|
|
g.field_count, g.whole_record_field, g.field_names,
|
|
CASE g.table_name
|
|
WHEN 'resources' THEN
|
|
CASE
|
|
WHEN left(g.record_key, length(g.org_id) + 1) = g.org_id || '/'
|
|
THEN substr(g.record_key, length(g.org_id) + 2)
|
|
WHEN position('/' IN g.record_key) > 0
|
|
THEN regexp_replace(g.record_key, '^.*/', '')
|
|
ELSE g.record_key
|
|
END
|
|
ELSE
|
|
CASE
|
|
WHEN left(
|
|
g.record_key,
|
|
length(split_part(g.record_key, '/', 1)) + length(g.org_id) + 2
|
|
) = split_part(g.record_key, '/', 1) || '/' || g.org_id || '/'
|
|
THEN ltrim(substr(
|
|
g.record_key,
|
|
length(split_part(g.record_key, '/', 1)) + length(g.org_id) + 3
|
|
), '/')
|
|
ELSE g.record_key
|
|
END
|
|
END::text AS target_id
|
|
FROM sys_changes g
|
|
WHERE g.table_name IN ('resources', 'access_policies')
|
|
) t
|
|
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR category = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR action = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR kind = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR actor = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR target_kind = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR target_id = ANY($6::text[]))
|
|
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR severity = ANY($7::text[]))
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR outcome = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(search_text)) > 0)
|
|
UNION ALL
|
|
SELECT
|
|
'identity'::text AS category,
|
|
event_type AS action,
|
|
event_type AS kind,
|
|
actor_id AS actor,
|
|
'identity'::text AS target_kind,
|
|
identity_id::text AS target_id,
|
|
CASE WHEN event_type IN ('suspend', 'retire') THEN 'warning' ELSE 'info' END AS severity,
|
|
'success'::text AS outcome,
|
|
concat_ws(' ', identity_id, event_type, display_name, actor_id, source) AS search_text
|
|
FROM identity_events
|
|
WHERE event_type IN ('create', 'rename', 'suspend', 'reactivate', 'retire')
|
|
AND ($10::boolean
|
|
OR (org_id IS NOT NULL AND org_id = $11::text))
|
|
AND ($12::timestamptz IS NULL OR at >= $12::timestamptz)
|
|
AND ($13::timestamptz IS NULL OR at < $13::timestamptz)
|
|
AND (COALESCE(cardinality($1::text[]), 0) = 0 OR 'identity' = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR event_type = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR event_type = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR actor_id = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR 'identity' = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR identity_id::text = ANY($6::text[]))
|
|
AND (
|
|
COALESCE(cardinality($7::text[]), 0) = 0
|
|
OR (CASE WHEN event_type IN ('suspend', 'retire') THEN 'warning' ELSE 'info' END) = ANY($7::text[])
|
|
)
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR 'success' = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(concat_ws(' ', identity_id, event_type, display_name, actor_id, source))) > 0)
|
|
UNION ALL
|
|
SELECT
|
|
'access'::text AS category,
|
|
'deny'::text AS action,
|
|
'access_denial'::text AS kind,
|
|
principal AS actor,
|
|
resource_kind AS target_kind,
|
|
resource_id::text AS target_id,
|
|
'warning'::text AS severity,
|
|
'denied'::text AS outcome,
|
|
concat_ws(' ', principal, action, resource_kind, resource_id, level, array_to_string(policies, ' ')) AS search_text
|
|
FROM access_denials
|
|
WHERE org_id = $11::text
|
|
AND ($12::timestamptz IS NULL OR minute_at >= $12::timestamptz)
|
|
AND ($13::timestamptz IS NULL OR minute_at < $13::timestamptz)
|
|
AND (COALESCE(cardinality($1::text[]), 0) = 0 OR 'access' = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR 'deny' = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR 'access_denial' = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR principal = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR resource_kind = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR resource_id::text = ANY($6::text[]))
|
|
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR 'warning' = ANY($7::text[]))
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR 'denied' = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(concat_ws(' ', principal, action, resource_kind, resource_id, level, array_to_string(policies, ' ')))) > 0)
|
|
UNION ALL
|
|
SELECT
|
|
CASE
|
|
WHEN kind = ANY(ARRAY[
|
|
'binding_changed', 'binding_started', 'mapping_changed',
|
|
'curator_run', 'curator_action', 'curator_error',
|
|
'job_run', 'job_error',
|
|
'workflow_call_started', 'workflow_call_finished',
|
|
'turn_completed', 'work_request_submitted'
|
|
]::text[]) THEN 'automation'
|
|
ELSE 'runtime'
|
|
END AS category,
|
|
kind AS action,
|
|
kind,
|
|
actor_id AS actor,
|
|
CASE WHEN task_id > 0 THEN 'task' ELSE '' END AS target_kind,
|
|
(CASE WHEN task_id > 0 THEN task_id::text ELSE '' END)::text AS target_id,
|
|
CASE
|
|
WHEN kind = ANY(ARRAY[
|
|
'task_dead', 'pr_rejected',
|
|
'operator_rejected', 'agent_rejected', 'task_rejected',
|
|
'task_abandoned', 'task_withdrawn', 'step_retried',
|
|
'curator_error', 'job_error', 'binding_dispatch_failure'
|
|
]::text[]) THEN 'error'
|
|
WHEN kind = ANY(ARRAY[
|
|
'parked', 'task_retried', 'task_cancelled', 'task_stopped',
|
|
'alert', 'update_report'
|
|
]::text[]) THEN 'warning'
|
|
ELSE 'info'
|
|
END AS severity,
|
|
CASE
|
|
WHEN kind = ANY(ARRAY[
|
|
'task_dead', 'pr_rejected',
|
|
'operator_rejected', 'agent_rejected', 'task_rejected',
|
|
'task_abandoned', 'task_withdrawn', 'step_retried',
|
|
'curator_error', 'job_error', 'binding_dispatch_failure'
|
|
]::text[]) THEN 'failure'
|
|
ELSE 'success'
|
|
END AS outcome,
|
|
concat_ws(' ', kind, actor_id, actor_kind, repo, workflow, stage, task_id::text) AS search_text
|
|
FROM events
|
|
WHERE org_id = $11::text
|
|
AND ($12::timestamptz IS NULL OR at >= $12::timestamptz)
|
|
AND ($13::timestamptz IS NULL OR at < $13::timestamptz)
|
|
AND (
|
|
COALESCE(cardinality($1::text[]), 0) = 0
|
|
OR (CASE WHEN kind = ANY(ARRAY[
|
|
'binding_changed', 'binding_started', 'mapping_changed',
|
|
'curator_run', 'curator_action', 'curator_error',
|
|
'job_run', 'job_error',
|
|
'workflow_call_started', 'workflow_call_finished',
|
|
'turn_completed', 'work_request_submitted'
|
|
]::text[]) THEN 'automation' ELSE 'runtime' END) = ANY($1::text[])
|
|
)
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR kind = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR kind = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR actor_id = $4::text)
|
|
AND (
|
|
COALESCE(cardinality($5::text[]), 0) = 0
|
|
OR (CASE WHEN task_id > 0 THEN 'task' ELSE '' END) = ANY($5::text[])
|
|
)
|
|
AND (
|
|
COALESCE(cardinality($6::text[]), 0) = 0
|
|
OR (CASE WHEN task_id > 0 THEN task_id::text ELSE '' END) = ANY($6::text[])
|
|
)
|
|
AND (
|
|
COALESCE(cardinality($7::text[]), 0) = 0
|
|
OR (CASE
|
|
WHEN kind = ANY(ARRAY[
|
|
'task_dead', 'pr_rejected',
|
|
'operator_rejected', 'agent_rejected', 'task_rejected',
|
|
'task_abandoned', 'task_withdrawn', 'step_retried',
|
|
'curator_error', 'job_error', 'binding_dispatch_failure'
|
|
]::text[]) THEN 'error'
|
|
WHEN kind = ANY(ARRAY[
|
|
'parked', 'task_retried', 'task_cancelled', 'task_stopped',
|
|
'alert', 'update_report'
|
|
]::text[]) THEN 'warning'
|
|
ELSE 'info'
|
|
END) = ANY($7::text[])
|
|
)
|
|
AND (
|
|
COALESCE(cardinality($8::text[]), 0) = 0
|
|
OR (CASE
|
|
WHEN kind = ANY(ARRAY[
|
|
'task_dead', 'pr_rejected',
|
|
'operator_rejected', 'agent_rejected', 'task_rejected',
|
|
'task_abandoned', 'task_withdrawn', 'step_retried',
|
|
'curator_error', 'job_error', 'binding_dispatch_failure'
|
|
]::text[]) THEN 'failure'
|
|
ELSE 'success'
|
|
END) = ANY($8::text[])
|
|
)
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(concat_ws(' ', kind, actor_id, actor_kind, repo, workflow, stage, task_id::text))) > 0)
|
|
UNION ALL
|
|
SELECT
|
|
CASE
|
|
WHEN g.table_name IN ('memberships', 'org_agents') THEN 'access'
|
|
WHEN g.table_name IN ('bindings', 'mappings', 'event_types') THEN 'automation'
|
|
ELSE 'settings'
|
|
END AS category,
|
|
CASE
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_old_null THEN 'create'
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_new_null THEN 'delete'
|
|
ELSE 'update'
|
|
END AS action,
|
|
g.table_name AS kind,
|
|
g.actor,
|
|
g.table_name::text AS target_kind,
|
|
g.record_key::text AS target_id,
|
|
CASE
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_new_null
|
|
AND NOT g.all_old_null THEN 'warning'
|
|
ELSE 'info'
|
|
END AS severity,
|
|
'success'::text AS outcome,
|
|
concat_ws(' ', g.record_key, g.actor, g.source, g.field_names, g.table_name) AS search_text
|
|
FROM sys_changes g
|
|
WHERE g.table_name NOT IN ('resources', 'access_policies')
|
|
AND (
|
|
COALESCE(cardinality($1::text[]), 0) = 0
|
|
OR (CASE
|
|
WHEN g.table_name IN ('memberships', 'org_agents') THEN 'access'
|
|
WHEN g.table_name IN ('bindings', 'mappings', 'event_types') THEN 'automation'
|
|
ELSE 'settings'
|
|
END) = ANY($1::text[])
|
|
)
|
|
AND (
|
|
COALESCE(cardinality($2::text[]), 0) = 0
|
|
OR (CASE
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_old_null THEN 'create'
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_new_null THEN 'delete'
|
|
ELSE 'update'
|
|
END) = ANY($2::text[])
|
|
)
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR g.table_name = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR g.actor = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR g.table_name = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR g.record_key = ANY($6::text[]))
|
|
AND (
|
|
COALESCE(cardinality($7::text[]), 0) = 0
|
|
OR (CASE
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_new_null
|
|
AND NOT g.all_old_null THEN 'warning'
|
|
ELSE 'info'
|
|
END) = ANY($7::text[])
|
|
)
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR 'success' = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(concat_ws(' ', g.record_key, g.actor, g.source, g.field_names, g.table_name))) > 0)
|
|
) branches
|
|
`
|
|
|
|
type CountAuditParams struct {
|
|
Categories []string
|
|
Actions []string
|
|
Kinds []string
|
|
Actor pgtype.Text
|
|
TargetKinds []string
|
|
TargetIds []string
|
|
Severities []string
|
|
Outcomes []string
|
|
Q pgtype.Text
|
|
InstanceAdmin bool
|
|
OrgID string
|
|
FromAt pgtype.Timestamptz
|
|
ToAt pgtype.Timestamptz
|
|
}
|
|
|
|
// The export preflight: the same predicates and change-set grouping as
|
|
// ListAudit, without the cursor and page bound, so the number is exactly what
|
|
// an export of that filter would stream. Counting the merged change sets (not
|
|
// field rows) keeps the answer in the unit the feed pages in.
|
|
func (q *Queries) CountAudit(ctx context.Context, arg CountAuditParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countAudit,
|
|
arg.Categories,
|
|
arg.Actions,
|
|
arg.Kinds,
|
|
arg.Actor,
|
|
arg.TargetKinds,
|
|
arg.TargetIds,
|
|
arg.Severities,
|
|
arg.Outcomes,
|
|
arg.Q,
|
|
arg.InstanceAdmin,
|
|
arg.OrgID,
|
|
arg.FromAt,
|
|
arg.ToAt,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const listAudit = `-- name: ListAudit :many
|
|
|
|
|
|
WITH sys_changes AS (
|
|
SELECT
|
|
a.org_id,
|
|
a.table_name,
|
|
a.record_key,
|
|
a.request_id,
|
|
a.record_version,
|
|
a.at,
|
|
a.actor,
|
|
a.source,
|
|
max(a.id)::bigint AS source_id,
|
|
jsonb_object_agg(
|
|
a.field,
|
|
jsonb_build_object(
|
|
'old', CASE WHEN a.old_value IS NULL THEN 'null'::jsonb ELSE a.old_value END,
|
|
'new', CASE WHEN a.new_value IS NULL THEN 'null'::jsonb ELSE a.new_value END
|
|
)
|
|
) AS fields,
|
|
bool_and(a.old_value IS NULL) AS all_old_null,
|
|
bool_and(a.new_value IS NULL) AS all_new_null,
|
|
bool_or(a.field = 'reset') AS is_reset,
|
|
count(DISTINCT a.field)::int AS field_count,
|
|
bool_or(a.field IN (
|
|
'org', 'workspace', 'role', 'org_id',
|
|
'mapping', 'binding', 'source', 'event_type',
|
|
'install', 'remove', 'credential'
|
|
)) AS whole_record_field,
|
|
string_agg(DISTINCT a.field, ' ') AS field_names
|
|
FROM sys_audit a
|
|
WHERE a.org_id = $14::text
|
|
AND (
|
|
COALESCE(cardinality($1::text[]), 0) = 0
|
|
OR (a.table_name = 'resources' AND 'settings' = ANY($1::text[]))
|
|
OR (a.table_name = 'access_policies' AND 'access' = ANY($1::text[]))
|
|
OR (a.table_name IN ('memberships', 'org_agents') AND 'access' = ANY($1::text[]))
|
|
OR (a.table_name IN ('bindings', 'mappings', 'event_types') AND 'automation' = ANY($1::text[]))
|
|
OR (
|
|
a.table_name NOT IN (
|
|
'resources', 'access_policies',
|
|
'memberships', 'org_agents',
|
|
'bindings', 'mappings', 'event_types'
|
|
)
|
|
AND 'settings' = ANY($1::text[])
|
|
)
|
|
)
|
|
AND ($10::timestamptz IS NULL OR a.at <= $10::timestamptz)
|
|
AND ($16::timestamptz IS NULL OR a.at >= $16::timestamptz)
|
|
AND ($17::timestamptz IS NULL OR a.at < $17::timestamptz)
|
|
AND ($4::text IS NULL OR a.actor = $4::text)
|
|
GROUP BY a.org_id, a.table_name, a.record_key, a.request_id, a.record_version, a.at, a.actor, a.source
|
|
)
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT
|
|
t.org_id AS org_id,
|
|
CASE t.table_name WHEN 'access_policies' THEN 'access' ELSE 'settings' END AS category,
|
|
1 AS source_rank,
|
|
t.source_id,
|
|
t.at,
|
|
t.actor,
|
|
''::text AS actor_kind,
|
|
''::text AS principal_id,
|
|
CASE t.table_name
|
|
WHEN 'resources' THEN 'resource'
|
|
ELSE 'policy'
|
|
END AS target_kind,
|
|
t.target_id,
|
|
CASE t.table_name
|
|
WHEN 'resources' THEN t.target_id
|
|
ELSE 'access_policy'
|
|
END AS kind,
|
|
t.record_version,
|
|
t.request_id,
|
|
t.source,
|
|
t.fields,
|
|
CASE
|
|
WHEN t.table_name = 'access_policies' AND t.is_reset THEN 'reset'
|
|
WHEN t.table_name = 'access_policies' AND t.all_new_null AND t.record_version > 0 THEN 'delete'
|
|
WHEN t.table_name = 'access_policies' AND t.all_old_null THEN 'create'
|
|
WHEN t.table_name = 'resources' AND t.record_version = 1 AND t.all_old_null THEN 'create'
|
|
ELSE 'update'
|
|
END AS action,
|
|
CASE
|
|
WHEN t.table_name = 'access_policies' AND t.is_reset THEN 'warning'
|
|
WHEN t.table_name = 'access_policies' AND t.all_new_null AND t.record_version > 0 THEN 'warning'
|
|
ELSE 'info'
|
|
END AS severity,
|
|
'success'::text AS outcome,
|
|
''::text AS detail,
|
|
concat_ws(' ', t.record_key, t.actor, t.source, t.field_names, t.target_id) AS search_text,
|
|
CASE
|
|
WHEN t.table_name = 'access_policies'
|
|
AND split_part(t.record_key, '/', 1) IN ('workspace', 'object')
|
|
THEN split_part(t.target_id, '/', 1)
|
|
ELSE ''
|
|
END AS workspace_id,
|
|
0::bigint AS task_id,
|
|
''::text AS data_text
|
|
FROM (
|
|
-- The target is derived from the row's org_id, never from a
|
|
-- split of the key: an org id may contain '/', and the org is
|
|
-- already a column here. resources: <org>/<kind> unless the key
|
|
-- is the bare kind. access_policies:
|
|
-- <level>/<org>/<workspace>/<objectKind>/<objectID>/<policyID>.
|
|
SELECT
|
|
g.org_id, g.table_name, g.record_key, g.request_id,
|
|
g.record_version, g.at, g.actor, g.source, g.source_id,
|
|
g.fields, g.all_old_null, g.all_new_null, g.is_reset,
|
|
g.field_count, g.whole_record_field, g.field_names,
|
|
CASE g.table_name
|
|
WHEN 'resources' THEN
|
|
CASE
|
|
WHEN left(g.record_key, length(g.org_id) + 1) = g.org_id || '/'
|
|
THEN substr(g.record_key, length(g.org_id) + 2)
|
|
-- A key written before the default org was renamed
|
|
-- still carries that dead id, not the row's org_id.
|
|
-- The kind is the last segment; never the org.
|
|
WHEN position('/' IN g.record_key) > 0
|
|
THEN regexp_replace(g.record_key, '^.*/', '')
|
|
ELSE g.record_key
|
|
END
|
|
ELSE
|
|
CASE
|
|
WHEN left(
|
|
g.record_key,
|
|
length(split_part(g.record_key, '/', 1)) + length(g.org_id) + 2
|
|
) = split_part(g.record_key, '/', 1) || '/' || g.org_id || '/'
|
|
THEN ltrim(substr(
|
|
g.record_key,
|
|
length(split_part(g.record_key, '/', 1)) + length(g.org_id) + 3
|
|
), '/')
|
|
ELSE g.record_key
|
|
END
|
|
END::text AS target_id
|
|
FROM sys_changes g
|
|
WHERE g.table_name IN ('resources', 'access_policies')
|
|
) t
|
|
) s
|
|
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR s.category = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR s.action = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR s.kind = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR s.actor = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR s.target_kind = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR s.target_id = ANY($6::text[]))
|
|
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR s.severity = ANY($7::text[]))
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR s.outcome = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(s.search_text)) > 0)
|
|
AND (
|
|
$10::timestamptz IS NULL
|
|
OR s.at < $10::timestamptz
|
|
OR (s.at = $10::timestamptz AND s.source_rank < $11::int)
|
|
OR (s.at = $10::timestamptz AND s.source_rank = $11::int AND s.source_id < $12::bigint)
|
|
)
|
|
ORDER BY s.at DESC, s.source_rank DESC, s.source_id DESC
|
|
LIMIT $13::bigint
|
|
) b1
|
|
UNION ALL
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT
|
|
$14::text AS org_id,
|
|
'identity'::text AS category,
|
|
2 AS source_rank,
|
|
ie.id::bigint AS source_id,
|
|
ie.at,
|
|
ie.actor_id AS actor,
|
|
''::text AS actor_kind,
|
|
''::text AS principal_id,
|
|
'identity'::text AS target_kind,
|
|
ie.identity_id::text AS target_id,
|
|
ie.event_type AS kind,
|
|
0::bigint AS record_version,
|
|
ie.request_id,
|
|
ie.source,
|
|
'{}'::jsonb AS fields,
|
|
ie.event_type AS action,
|
|
CASE WHEN ie.event_type IN ('suspend', 'retire') THEN 'warning' ELSE 'info' END AS severity,
|
|
'success'::text AS outcome,
|
|
ie.from_lifecycle || ' → ' || ie.to_lifecycle AS detail,
|
|
concat_ws(' ', ie.identity_id, ie.event_type, ie.display_name, ie.actor_id, ie.source) AS search_text,
|
|
''::text AS workspace_id,
|
|
0::bigint AS task_id,
|
|
''::text AS data_text
|
|
FROM identity_events ie
|
|
WHERE ie.event_type IN ('create', 'rename', 'suspend', 'reactivate', 'retire')
|
|
AND ($15::boolean
|
|
OR (ie.org_id IS NOT NULL AND ie.org_id = $14::text))
|
|
AND ($16::timestamptz IS NULL OR ie.at >= $16::timestamptz)
|
|
AND ($17::timestamptz IS NULL OR ie.at < $17::timestamptz)
|
|
) si
|
|
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR si.category = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR si.action = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR si.kind = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR si.actor = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR si.target_kind = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR si.target_id = ANY($6::text[]))
|
|
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR si.severity = ANY($7::text[]))
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR si.outcome = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(si.search_text)) > 0)
|
|
AND (
|
|
$10::timestamptz IS NULL
|
|
OR si.at < $10::timestamptz
|
|
OR (si.at = $10::timestamptz AND si.source_rank < $11::int)
|
|
OR (si.at = $10::timestamptz AND si.source_rank = $11::int AND si.source_id < $12::bigint)
|
|
)
|
|
ORDER BY si.at DESC, si.source_rank DESC, si.source_id DESC
|
|
LIMIT $13::bigint
|
|
) b2
|
|
UNION ALL
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT
|
|
d.org_id,
|
|
'access'::text AS category,
|
|
3 AS source_rank,
|
|
d.id::bigint AS source_id,
|
|
d.minute_at AS at,
|
|
d.principal AS actor,
|
|
''::text AS actor_kind,
|
|
d.principal AS principal_id,
|
|
d.resource_kind AS target_kind,
|
|
d.resource_id::text AS target_id,
|
|
'access_denial'::text AS kind,
|
|
0::bigint AS record_version,
|
|
''::text AS request_id,
|
|
'access'::text AS source,
|
|
'{}'::jsonb AS fields,
|
|
'deny'::text AS action,
|
|
'warning'::text AS severity,
|
|
'denied'::text AS outcome,
|
|
CASE WHEN cardinality(d.policies) > 0 THEN array_to_string(d.policies, ', ') ELSE '' END AS detail,
|
|
concat_ws(' ', d.principal, d.action, d.resource_kind, d.resource_id, d.level, array_to_string(d.policies, ' ')) AS search_text,
|
|
''::text AS workspace_id,
|
|
0::bigint AS task_id,
|
|
jsonb_build_object('count', d.count, 'policies', d.policies)::text AS data_text
|
|
FROM access_denials d
|
|
WHERE d.org_id = $14::text
|
|
AND ($16::timestamptz IS NULL OR d.minute_at >= $16::timestamptz)
|
|
AND ($17::timestamptz IS NULL OR d.minute_at < $17::timestamptz)
|
|
) sd
|
|
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR sd.category = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR sd.action = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR sd.kind = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR sd.actor = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR sd.target_kind = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR sd.target_id = ANY($6::text[]))
|
|
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR sd.severity = ANY($7::text[]))
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR sd.outcome = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(sd.search_text)) > 0)
|
|
AND (
|
|
$10::timestamptz IS NULL
|
|
OR sd.at < $10::timestamptz
|
|
OR (sd.at = $10::timestamptz AND sd.source_rank < $11::int)
|
|
OR (sd.at = $10::timestamptz AND sd.source_rank = $11::int AND sd.source_id < $12::bigint)
|
|
)
|
|
ORDER BY sd.at DESC, sd.source_rank DESC, sd.source_id DESC
|
|
LIMIT $13::bigint
|
|
) b3
|
|
UNION ALL
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT
|
|
e.org_id,
|
|
CASE
|
|
WHEN e.kind = ANY(ARRAY[
|
|
'binding_changed', 'binding_started', 'mapping_changed',
|
|
'curator_run', 'curator_action', 'curator_error',
|
|
'job_run', 'job_error',
|
|
'workflow_call_started', 'workflow_call_finished',
|
|
'turn_completed', 'work_request_submitted'
|
|
]::text[]) THEN 'automation'
|
|
ELSE 'runtime'
|
|
END AS category,
|
|
4 AS source_rank,
|
|
e.id::bigint AS source_id,
|
|
e.at,
|
|
e.actor_id AS actor,
|
|
e.actor_kind,
|
|
e.principal_id,
|
|
CASE WHEN e.task_id > 0 THEN 'task' ELSE '' END AS target_kind,
|
|
(CASE WHEN e.task_id > 0 THEN e.task_id::text ELSE '' END)::text AS target_id,
|
|
e.kind,
|
|
0::bigint AS record_version,
|
|
''::text AS request_id,
|
|
''::text AS source,
|
|
'{}'::jsonb AS fields,
|
|
e.kind AS action,
|
|
CASE
|
|
WHEN e.kind = ANY(ARRAY[
|
|
'task_dead', 'pr_rejected',
|
|
'operator_rejected', 'agent_rejected', 'task_rejected',
|
|
'task_abandoned', 'task_withdrawn', 'step_retried',
|
|
'curator_error', 'job_error', 'binding_dispatch_failure'
|
|
]::text[]) THEN 'error'
|
|
WHEN e.kind = ANY(ARRAY[
|
|
'parked', 'task_retried', 'task_cancelled', 'task_stopped',
|
|
'alert', 'update_report'
|
|
]::text[]) THEN 'warning'
|
|
ELSE 'info'
|
|
END AS severity,
|
|
CASE
|
|
WHEN e.kind = ANY(ARRAY[
|
|
'task_dead', 'pr_rejected',
|
|
'operator_rejected', 'agent_rejected', 'task_rejected',
|
|
'task_abandoned', 'task_withdrawn', 'step_retried',
|
|
'curator_error', 'job_error', 'binding_dispatch_failure'
|
|
]::text[]) THEN 'failure'
|
|
ELSE 'success'
|
|
END AS outcome,
|
|
e.detail,
|
|
concat_ws(' ', e.kind, e.actor_id, e.actor_kind, e.repo, e.workflow, e.stage, e.task_id::text) AS search_text,
|
|
e.workspace_id,
|
|
e.task_id,
|
|
e.data AS data_text
|
|
FROM events e
|
|
WHERE e.org_id = $14::text
|
|
AND ($16::timestamptz IS NULL OR e.at >= $16::timestamptz)
|
|
AND ($17::timestamptz IS NULL OR e.at < $17::timestamptz)
|
|
) se
|
|
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR se.category = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR se.action = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR se.kind = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR se.actor = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR se.target_kind = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR se.target_id = ANY($6::text[]))
|
|
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR se.severity = ANY($7::text[]))
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR se.outcome = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(se.search_text)) > 0)
|
|
AND (
|
|
$10::timestamptz IS NULL
|
|
OR se.at < $10::timestamptz
|
|
OR (se.at = $10::timestamptz AND se.source_rank < $11::int)
|
|
OR (se.at = $10::timestamptz AND se.source_rank = $11::int AND se.source_id < $12::bigint)
|
|
)
|
|
ORDER BY se.at DESC, se.source_rank DESC, se.source_id DESC
|
|
LIMIT $13::bigint
|
|
) b4
|
|
UNION ALL
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT org_id, category, source_rank, source_id, at, actor, actor_kind, principal_id, target_kind, target_id, kind, record_version, request_id, source, fields, action, severity, outcome, detail, search_text, workspace_id, task_id, data_text FROM (
|
|
SELECT
|
|
g.org_id,
|
|
CASE
|
|
WHEN g.table_name IN ('memberships', 'org_agents') THEN 'access'
|
|
WHEN g.table_name IN ('bindings', 'mappings', 'event_types') THEN 'automation'
|
|
ELSE 'settings'
|
|
END AS category,
|
|
5 AS source_rank,
|
|
g.source_id,
|
|
g.at,
|
|
g.actor,
|
|
''::text AS actor_kind,
|
|
''::text AS principal_id,
|
|
g.table_name::text AS target_kind,
|
|
g.record_key::text AS target_id,
|
|
g.table_name AS kind,
|
|
g.record_version,
|
|
g.request_id,
|
|
g.source,
|
|
g.fields,
|
|
CASE
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_old_null THEN 'create'
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_new_null THEN 'delete'
|
|
ELSE 'update'
|
|
END AS action,
|
|
CASE
|
|
WHEN g.field_count = 1 AND g.whole_record_field AND g.all_new_null
|
|
AND NOT g.all_old_null THEN 'warning'
|
|
ELSE 'info'
|
|
END AS severity,
|
|
'success'::text AS outcome,
|
|
''::text AS detail,
|
|
concat_ws(' ', g.record_key, g.actor, g.source, g.field_names, g.table_name) AS search_text,
|
|
''::text AS workspace_id,
|
|
0::bigint AS task_id,
|
|
''::text AS data_text
|
|
FROM sys_changes g
|
|
WHERE g.table_name NOT IN ('resources', 'access_policies')
|
|
) sg
|
|
WHERE (COALESCE(cardinality($1::text[]), 0) = 0 OR sg.category = ANY($1::text[]))
|
|
AND (COALESCE(cardinality($2::text[]), 0) = 0 OR sg.action = ANY($2::text[]))
|
|
AND (COALESCE(cardinality($3::text[]), 0) = 0 OR sg.kind = ANY($3::text[]))
|
|
AND ($4::text IS NULL OR sg.actor = $4::text)
|
|
AND (COALESCE(cardinality($5::text[]), 0) = 0 OR sg.target_kind = ANY($5::text[]))
|
|
AND (COALESCE(cardinality($6::text[]), 0) = 0 OR sg.target_id = ANY($6::text[]))
|
|
AND (COALESCE(cardinality($7::text[]), 0) = 0 OR sg.severity = ANY($7::text[]))
|
|
AND (COALESCE(cardinality($8::text[]), 0) = 0 OR sg.outcome = ANY($8::text[]))
|
|
AND ($9::text IS NULL OR position(lower($9::text) IN lower(sg.search_text)) > 0)
|
|
AND (
|
|
$10::timestamptz IS NULL
|
|
OR sg.at < $10::timestamptz
|
|
OR (sg.at = $10::timestamptz AND sg.source_rank < $11::int)
|
|
OR (sg.at = $10::timestamptz AND sg.source_rank = $11::int AND sg.source_id < $12::bigint)
|
|
)
|
|
ORDER BY sg.at DESC, sg.source_rank DESC, sg.source_id DESC
|
|
LIMIT $13::bigint
|
|
) b5
|
|
) merged
|
|
ORDER BY merged.at DESC, merged.source_rank DESC, merged.source_id DESC
|
|
LIMIT $13::bigint
|
|
`
|
|
|
|
type ListAuditParams struct {
|
|
Categories []string
|
|
Actions []string
|
|
Kinds []string
|
|
Actor pgtype.Text
|
|
TargetKinds []string
|
|
TargetIds []string
|
|
Severities []string
|
|
Outcomes []string
|
|
Q pgtype.Text
|
|
CursorAt pgtype.Timestamptz
|
|
CursorRank int32
|
|
CursorID int64
|
|
PageLimit int64
|
|
OrgID string
|
|
InstanceAdmin bool
|
|
FromAt pgtype.Timestamptz
|
|
ToAt pgtype.Timestamptz
|
|
}
|
|
|
|
type ListAuditRow struct {
|
|
OrgID string
|
|
Category string
|
|
SourceRank int32
|
|
SourceID int64
|
|
At time.Time
|
|
Actor string
|
|
ActorKind string
|
|
PrincipalID string
|
|
TargetKind string
|
|
TargetID string
|
|
Kind string
|
|
RecordVersion int64
|
|
RequestID string
|
|
Source string
|
|
Fields []byte
|
|
Action string
|
|
Severity string
|
|
Outcome string
|
|
Detail string
|
|
SearchText string
|
|
WorkspaceID string
|
|
TaskID int64
|
|
DataText string
|
|
}
|
|
|
|
// The audit feed read model: one org-scoped timeline over every durable
|
|
// trail the State Store owns. It is a parameterised UNION ALL, not a view,
|
|
// because the filters and the keyset cursor must reach each source before
|
|
// that source's ORDER BY ... LIMIT; otherwise a page of the merged feed
|
|
// groups or scans the whole trail first.
|
|
//
|
|
// Each branch emits the same row shape. The outer query merges the per-branch
|
|
// top-K and takes the page. Ranks are fixed per origin and never reused:
|
|
//
|
|
// 1 sys_audit resources and access_policies, grouped into change sets
|
|
// 2 identity_events lifecycle events
|
|
// 3 access_denials, one aggregated denial
|
|
// 4 events
|
|
// 5 sys_audit coverage tables (orgs, memberships, sources, ...), grouped
|
|
//
|
|
// search_text is metadata only. It never contains a value, an event's data,
|
|
// or policy text: substring search over unredacted values would be a
|
|
// token-guessing oracle. The adapter redacts fields, data and detail before
|
|
// an entry leaves the process, and fail-closes on undecodable JSON.
|
|
//
|
|
// Identity lifecycle rows carry the org they happened in, so removing a
|
|
// member does not erase their earlier history from that org's feed. Only a
|
|
// principal with instance-wide authority sees every org's identity events;
|
|
// being confined to the system org is not that authority. A historical row
|
|
// with no defensible org stays NULL and is visible only to that authority.
|
|
//
|
|
// Coverage-table change sets are classified by their whole-record field, not
|
|
// by a version: a create is a whole-record field with a null old side, a
|
|
// delete the same field with a null new side, and everything else an update.
|
|
// A partial add or remove is never a create or delete.
|
|
func (q *Queries) ListAudit(ctx context.Context, arg ListAuditParams) ([]ListAuditRow, error) {
|
|
rows, err := q.db.Query(ctx, listAudit,
|
|
arg.Categories,
|
|
arg.Actions,
|
|
arg.Kinds,
|
|
arg.Actor,
|
|
arg.TargetKinds,
|
|
arg.TargetIds,
|
|
arg.Severities,
|
|
arg.Outcomes,
|
|
arg.Q,
|
|
arg.CursorAt,
|
|
arg.CursorRank,
|
|
arg.CursorID,
|
|
arg.PageLimit,
|
|
arg.OrgID,
|
|
arg.InstanceAdmin,
|
|
arg.FromAt,
|
|
arg.ToAt,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListAuditRow
|
|
for rows.Next() {
|
|
var i ListAuditRow
|
|
if err := rows.Scan(
|
|
&i.OrgID,
|
|
&i.Category,
|
|
&i.SourceRank,
|
|
&i.SourceID,
|
|
&i.At,
|
|
&i.Actor,
|
|
&i.ActorKind,
|
|
&i.PrincipalID,
|
|
&i.TargetKind,
|
|
&i.TargetID,
|
|
&i.Kind,
|
|
&i.RecordVersion,
|
|
&i.RequestID,
|
|
&i.Source,
|
|
&i.Fields,
|
|
&i.Action,
|
|
&i.Severity,
|
|
&i.Outcome,
|
|
&i.Detail,
|
|
&i.SearchText,
|
|
&i.WorkspaceID,
|
|
&i.TaskID,
|
|
&i.DataText,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|