chore(audit): distinguish requests from rest_api or dashboard

This commit is contained in:
JianBo He 2023-09-27 20:21:10 +08:00
parent dd9938114c
commit 71acf121ba
2 changed files with 5 additions and 8 deletions

View File

@ -25,22 +25,19 @@ log(Meta0) ->
Duration = erlang:convert_time_unit(ReqEnd - ReqStart, native, millisecond),
Level = level(Method, Code, Duration),
Username = maps:get(username, Meta0, <<"">>),
From = from(maps:get(auth_type, Meta0, "")),
Meta1 = maps:without([req_start, req_end], Meta0),
Meta2 = Meta1#{time => logger:timestamp(), duration_ms => Duration},
Meta = emqx_utils:redact(Meta2),
?AUDIT(
Level,
rest_api,
Meta#{
from => from(maps:get(auth_type, Meta0, "")),
username => binary_to_list(Username),
node => node()
}
From,
Meta#{username => binary_to_list(Username), node => node()}
),
ok.
from(jwt_token) -> "dashboard";
from(api_key) -> "aip_key";
from(api_key) -> "rest_api";
from(_) -> "unauthorized".
level(get, _Code, _) -> debug;

View File

@ -112,7 +112,7 @@ max_heap_size_warning(MF, Args) ->
log(_, {?MODULE, prompt_func}, [[{history, _}]]) ->
ok;
log(IsAllow, MF, Args) ->
?AUDIT(warning, remote_console, #{
?AUDIT(warning, shell, #{
time => logger:timestamp(),
function => MF,
args => pp_args(Args),