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) -> handle_info(_Msg, State) ->
{noreply, State}. {noreply, State}.
format_status(State) -> format_status(Status = #{state := State}) ->
censor_secrets(State). Status#{state => censor_secrets(State)}.
format_status(_Opt, [_PDict, State0]) -> format_status(_Opt, [_PDict, State0]) ->
State = censor_secrets(State0), State = censor_secrets(State0),
@ -222,16 +222,13 @@ ensure_timer(State) ->
State. State.
-spec censor_secrets(state()) -> map(). -spec censor_secrets(state()) -> map().
censor_secrets(State) -> censor_secrets(State = #{jwt := JWT, jwk := JWK}) ->
maps:map( State#{
fun jwt := censor_secret(JWT),
(Key, _Value) when jwk := censor_secret(JWK)
Key =:= jwt; }.
Key =:= jwk
-> censor_secret(undefined) ->
"******"; undefined;
(_Key, Value) -> censor_secret(_Secret) ->
Value "******".
end,
State
).