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 if (currentTask is null or currentTask = '') then
raise exception '[401] currentTask must be defined, please call `defineContext(...)`'; raise exception '[401] currentTask must be defined, please call `defineContext(...)`';
end if; end if;
raise debug 'currentTask: %', currentTask;
return currentTask; return currentTask;
end; $$; 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:--// --changeset context-CURRENT-USER:1 endDelimiter:--//
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------

View File

@ -27,7 +27,8 @@ create table tx_context
txTimestamp timestamp not null, txTimestamp timestamp not null,
currentUser varchar(63) not null, -- not the uuid, because users can be deleted 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 assumedRoles varchar not null, -- not the uuids, because roles can be deleted
currentTask varchar not null currentTask varchar(96) not null,
currentRequest varchar(512) not null
); );
create index on tx_context using brin (txTimestamp); create index on tx_context using brin (txTimestamp);
@ -65,7 +66,7 @@ begin
insert insert
into tx_context into tx_context
values (txid_current(), now(), values (txid_current(), now(),
currentUser(), assumedRoles(), currentTask()) currentUser(), assumedRoles(), currentTask(), currentRequest())
on conflict do nothing; on conflict do nothing;
case tg_op case tg_op