store http request in audit log

This commit is contained in:
Michael Hoennig 2022-08-30 13:38:12 +02:00
parent 8af93603d5
commit 7f6e363c8f
2 changed files with 32 additions and 7 deletions

View File

@ -69,12 +69,36 @@ begin
if (currentTask is null or currentTask = '') then
raise exception '[401] currentTask must be defined, please call `defineContext(...)`';
end if;
raise debug 'currentTask: %', currentTask;
return currentTask;
end; $$;
--//
-- ============================================================================
--changeset context-CURRENT-REQUEST:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/*
Returns the current http request as set via `defineContext(...)`.
Raises exception if not set.
*/
create or replace function currentRequest()
returns varchar(512)
stable leakproof
language plpgsql as $$
declare
currentRequest varchar(512);
begin
begin
currentRequest := current_setting('hsadminng.currentRequest');
exception
when others then
currentRequest := null;
end;
return currentRequest;
end; $$;
--//
-- ============================================================================
--changeset context-CURRENT-USER:1 endDelimiter:--//
-- ----------------------------------------------------------------------------

View File

@ -23,11 +23,12 @@ do $$
*/
create table tx_context
(
txId bigint primary key not null,
txTimestamp timestamp not null,
currentUser varchar(63) not null, -- not the uuid, because users can be deleted
assumedRoles varchar not null, -- not the uuids, because roles can be deleted
currentTask varchar not null
txId bigint primary key not null,
txTimestamp timestamp not null,
currentUser varchar(63) not null, -- not the uuid, because users can be deleted
assumedRoles varchar not null, -- not the uuids, because roles can be deleted
currentTask varchar(96) not null,
currentRequest varchar(512) not null
);
create index on tx_context using brin (txTimestamp);
@ -65,7 +66,7 @@ begin
insert
into tx_context
values (txid_current(), now(),
currentUser(), assumedRoles(), currentTask())
currentUser(), assumedRoles(), currentTask(), currentRequest())
on conflict do nothing;
case tg_op