Skip to content

AMQP 1.0 client connection: implement format_status/1 (backport #9763) #9764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions deps/amqp10_client/src/amqp10_client_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
opened/3,
close_sent/3]).

-export([format_status/1]).

-type amqp10_socket() :: {tcp, gen_tcp:socket()} | {ssl, ssl:sslsocket()}.

-type milliseconds() :: non_neg_integer().
Expand Down Expand Up @@ -328,10 +330,45 @@ terminate(Reason, _StateName, #state{connection_sup = Sup,
code_change(_OldVsn, StateName, State, _Extra) ->
{ok, StateName, State}.

format_status(Context = #{data := ProcState}) ->
%% Note: Context.state here refers to the gen_statem state name,
%% so we need to use Context.data to get #state{}
Obfuscated = obfuscate_state(ProcState),
Context#{data => Obfuscated}.


%% -------------------------------------------------------------------
%% Internal functions.
%% -------------------------------------------------------------------

obfuscate_state(State = #state{config = Cfg0}) ->
Cfg1 = obfuscate_state_config_sasl(Cfg0),
Cfg2 = obfuscate_state_config_tls_opts(Cfg1),
State#state{config = Cfg2}.

-spec obfuscate_state_config_sasl(connection_config()) -> connection_config().
obfuscate_state_config_sasl(Cfg) ->
Sasl0 = maps:get(sasl, Cfg, none),
Sasl = case Sasl0 of
{plain, Username, _Password} ->
{plain, Username, <<"[redacted]">>};
Other ->
Other
end,
Cfg#{sasl => Sasl}.

-spec obfuscate_state_config_tls_opts(connection_config()) -> connection_config().
obfuscate_state_config_tls_opts(Cfg) ->
TlsOpts0 = maps:get(tls_opts, Cfg, undefined),
TlsOpts = case TlsOpts0 of
{secure_port, PropL0} ->
Obfuscated = proplists:delete(password, PropL0),
{secure_port, Obfuscated};
_ ->
TlsOpts0
end,
Cfg#{tls_opts => TlsOpts}.

handle_begin_session({FromPid, _Ref},
#state{sessions_sup = Sup, reader = Reader,
next_channel = Channel,
Expand Down