fix: handle status in `format_status/1` callback

Which is expected argument type for this callback. Also try to
make sure that random maps won't pass through this callback unnoticed.
This commit is contained in:
Andrew Mayorov 2022-12-14 19:31:52 +03:00
parent aece9fb96f
commit ed2d5aa48a
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
1 changed files with 12 additions and 15 deletions

View File

@ -154,8 +154,8 @@ handle_info({timeout, TRef, ?refresh_jwt}, State0 = #{refresh_timer := TRef}) ->
handle_info(_Msg, State) ->
{noreply, State}.
format_status(State) ->
censor_secrets(State).
format_status(Status = #{state := State}) ->
Status#{state => censor_secrets(State)}.
format_status(_Opt, [_PDict, State0]) ->
State = censor_secrets(State0),
@ -222,16 +222,13 @@ ensure_timer(State) ->
State.
-spec censor_secrets(state()) -> map().
censor_secrets(State) ->
maps:map(
fun
(Key, _Value) when
Key =:= jwt;
Key =:= jwk
->
"******";
(_Key, Value) ->
Value
end,
State
).
censor_secrets(State = #{jwt := JWT, jwk := JWK}) ->
State#{
jwt := censor_secret(JWT),
jwk := censor_secret(JWK)
}.
censor_secret(undefined) ->
undefined;
censor_secret(_Secret) ->
"******".