From db9721bf719fe379e3d624fecd53e24192a80c4c Mon Sep 17 00:00:00 2001 From: Andrew Mayorov Date: Thu, 4 Feb 2021 15:47:19 +0300 Subject: [PATCH] Don't audit-log 'undefined' when no restrictions (#17) --- src/bouncer_audit_log.erl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/bouncer_audit_log.erl b/src/bouncer_audit_log.erl index 32064e7..8cbeb11 100644 --- a/src/bouncer_audit_log.erl +++ b/src/bouncer_audit_log.erl @@ -214,12 +214,11 @@ get_beat_metadata({judgement, Event}) -> event => started }; {completed, {Resolution, Assertions}} -> - #{ + encode_restrictions(Resolution, #{ event => completed, resolution => encode_resolution(Resolution), - assertions => lists:map(fun encode_assertion/1, Assertions), - restrictions => encode_restrictions(Resolution) - }; + assertions => lists:map(fun encode_assertion/1, Assertions) + }); {failed, Error} -> #{ event => failed, @@ -234,10 +233,10 @@ encode_resolution({restricted, _Restrictions}) -> <<"restricted">>. %% NOTE %% I judged adding restrictions parsing to be not worth it for audit log -encode_restrictions({restricted, Restrictions}) -> - Restrictions; -encode_restrictions(_) -> - undefined. +encode_restrictions({restricted, Restrictions}, Acc) -> + Acc#{restrictions => Restrictions}; +encode_restrictions(_, Acc) -> + Acc. encode_assertion({Code, Details}) -> #{code => Code, details => Details}.