feat(emqx.erl): Add a help function to load debug secret
This commit is contained in:
parent
beac1f5f59
commit
8201e4c820
27
src/emqx.erl
27
src/emqx.erl
|
@ -63,12 +63,39 @@
|
|||
, reboot/0
|
||||
]).
|
||||
|
||||
%% Troubleshooting
|
||||
-export([ set_debug_secret/1
|
||||
]).
|
||||
|
||||
-define(APP, ?MODULE).
|
||||
|
||||
-define(COPYRIGHT, "Copyright (c) 2020 EMQ Technologies Co., Ltd").
|
||||
|
||||
-define(LICENSE_MESSAGE, "Licensed under the Apache License, Version 2.0").
|
||||
|
||||
%% @hidden Path to the file which has debug_info encryption secret in it.
|
||||
%% Evaluate this function if there is a need to access encrypted debug_info.
|
||||
%% NOTE: Do not change the API to accept the secret text because it may
|
||||
%% get logged everywhere.
|
||||
set_debug_secret(PathToSecretFile) ->
|
||||
SecretText =
|
||||
case file:read_file(PathToSecretFile) of
|
||||
{ok, Secret} ->
|
||||
try string:trim(binary_to_list(Secret))
|
||||
catch _ : _ -> error({badfile, PathToSecretFile})
|
||||
end;
|
||||
{error, Reason} ->
|
||||
io:format("Failed to read debug_info encryption key file ~s: ~p~n",
|
||||
[PathToSecretFile, Reason]),
|
||||
error(Reason)
|
||||
end,
|
||||
F = fun(init) -> ok;
|
||||
(clear) -> ok;
|
||||
({debug_info, _Mode, _Module, _Filename}) -> SecretText
|
||||
end,
|
||||
_ = beam_lib:clear_crypto_key_fun(),
|
||||
ok = beam_lib:crypto_key_fun(F).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Bootstrap, is_running...
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue