fix(dashboard): add bootstrap user tag && return error when adding bootstrap user fails
This commit is contained in:
parent
10755e8b3d
commit
d4bf658e38
|
@ -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 ->
|
||||||
|
|
Loading…
Reference in New Issue