Merge pull request #8707 from lafirest/fix/bootstrap_user

fix(dashboard): add bootstrap user tag && return error when adding bo…
This commit is contained in:
Xinyu Liu 2022-08-12 18:18:57 +08:00 committed by GitHub
commit 43ed926d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -56,6 +56,7 @@
]). ]).
-type emqx_admin() :: #?ADMIN{}. -type emqx_admin() :: #?ADMIN{}.
-define(BOOTSTRAP_USER_TAG, <<"bootstrap user">>).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Mnesia bootstrap %% Mnesia bootstrap
@ -314,7 +315,7 @@ add_default_user(Username, Password) ->
add_bootstrap_user(File) -> add_bootstrap_user(File) ->
case file:open(File, [read]) of case file:open(File, [read]) of
{ok, Dev} -> {ok, Dev} ->
{ok, MP} = re:compile(<<"(\.+):(\.+)">>), {ok, MP} = re:compile(<<"(\.+):(\.+$)">>, [ungreedy]),
try try
load_bootstrap_user(Dev, MP) load_bootstrap_user(Dev, MP)
catch catch
@ -331,13 +332,16 @@ load_bootstrap_user(Dev, MP) ->
case file:read_line(Dev) of case file:read_line(Dev) of
{ok, Line} -> {ok, Line} ->
case re:run(Line, MP, [global, {capture, all_but_first, binary}]) of case re:run(Line, MP, [global, {capture, all_but_first, binary}]) of
{match, Captured} -> {match, [[Username, Password]]} ->
_ = [add_user(Username, Password, <<>>) || [Username, Password] <- Captured], case add_user(Username, Password, ?BOOTSTRAP_USER_TAG) of
ok; {ok, _} ->
load_bootstrap_user(Dev, MP);
Error ->
Error
end;
_ -> _ ->
ok load_bootstrap_user(Dev, MP)
end, end;
load_bootstrap_user(Dev, MP);
eof -> eof ->
ok; ok;
Error -> Error ->