fix(export): emqx_auth_mnesia import failed after 4.3.x
This commit is contained in:
parent
85d568be60
commit
27f5e765b5
|
|
@ -73,7 +73,6 @@ set_default(ClientId, UserName, Pwd, HashType) ->
|
||||||
application:set_env(emqx_auth_mnesia, clientid_list, [{ClientId, Pwd}]),
|
application:set_env(emqx_auth_mnesia, clientid_list, [{ClientId, Pwd}]),
|
||||||
application:set_env(emqx_auth_mnesia, username_list, [{UserName, Pwd}]),
|
application:set_env(emqx_auth_mnesia, username_list, [{UserName, Pwd}]),
|
||||||
application:set_env(emqx_auth_mnesia, password_hash, HashType),
|
application:set_env(emqx_auth_mnesia, password_hash, HashType),
|
||||||
application:set_env(emqx_auth_mnesia, password_hash, HashType),
|
|
||||||
ok.
|
ok.
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Testcases
|
%% Testcases
|
||||||
|
|
|
||||||
|
|
@ -602,7 +602,7 @@ import(Filename, OverridesJson) ->
|
||||||
Overrides = emqx_json:decode(OverridesJson, [return_maps]),
|
Overrides = emqx_json:decode(OverridesJson, [return_maps]),
|
||||||
Data = maps:merge(Imported, Overrides),
|
Data = maps:merge(Imported, Overrides),
|
||||||
Version = to_version(maps:get(<<"version">>, Data)),
|
Version = to_version(maps:get(<<"version">>, Data)),
|
||||||
read_global_auth_type(Data),
|
read_global_auth_type(Data, Version),
|
||||||
try
|
try
|
||||||
do_import_data(Data, Version),
|
do_import_data(Data, Version),
|
||||||
logger:debug("The emqx data has been imported successfully"),
|
logger:debug("The emqx data has been imported successfully"),
|
||||||
|
|
@ -621,7 +621,7 @@ import(Filename, OverridesJson) ->
|
||||||
Overrides = emqx_json:decode(OverridesJson, [return_maps]),
|
Overrides = emqx_json:decode(OverridesJson, [return_maps]),
|
||||||
Data = maps:merge(Imported, Overrides),
|
Data = maps:merge(Imported, Overrides),
|
||||||
Version = to_version(maps:get(<<"version">>, Data)),
|
Version = to_version(maps:get(<<"version">>, Data)),
|
||||||
read_global_auth_type(Data),
|
read_global_auth_type(Data, Version),
|
||||||
case is_version_supported(Data, Version) of
|
case is_version_supported(Data, Version) of
|
||||||
true ->
|
true ->
|
||||||
try
|
try
|
||||||
|
|
@ -696,17 +696,17 @@ is_version_supported2(Version) ->
|
||||||
end.
|
end.
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
read_global_auth_type(Data) ->
|
read_global_auth_type(Data, Version) ->
|
||||||
case {maps:get(<<"auth_mnesia">>, Data, []), maps:get(<<"acl_mnesia">>, Data, [])} of
|
case {maps:get(<<"auth_mnesia">>, Data, []), maps:get(<<"acl_mnesia">>, Data, [])} of
|
||||||
{[], []} ->
|
{[], []} ->
|
||||||
%% Auth mnesia plugin is not used:
|
%% Auth mnesia plugin is not used:
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
do_read_global_auth_type(Data)
|
do_read_global_auth_type(Data, Version)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-ifdef(EMQX_ENTERPRISE).
|
-ifdef(EMQX_ENTERPRISE).
|
||||||
do_read_global_auth_type(Data) ->
|
do_read_global_auth_type(Data, _Version) ->
|
||||||
case Data of
|
case Data of
|
||||||
#{<<"auth.mnesia.as">> := <<"username">>} ->
|
#{<<"auth.mnesia.as">> := <<"username">>} ->
|
||||||
application:set_env(emqx_auth_mnesia, as, username);
|
application:set_env(emqx_auth_mnesia, as, username);
|
||||||
|
|
@ -717,13 +717,15 @@ do_read_global_auth_type(Data) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-else.
|
-else.
|
||||||
do_read_global_auth_type(Data) ->
|
do_read_global_auth_type(Data, FromVersion) ->
|
||||||
case Data of
|
case Data of
|
||||||
#{<<"auth.mnesia.as">> := <<"username">>} ->
|
#{<<"auth.mnesia.as">> := <<"username">>} ->
|
||||||
application:set_env(emqx_auth_mnesia, as, username);
|
application:set_env(emqx_auth_mnesia, as, username);
|
||||||
#{<<"auth.mnesia.as">> := <<"clientid">>} ->
|
#{<<"auth.mnesia.as">> := <<"clientid">>} ->
|
||||||
application:set_env(emqx_auth_mnesia, as, clientid);
|
application:set_env(emqx_auth_mnesia, as, clientid);
|
||||||
_ ->
|
_ when FromVersion =:= "4.0" orelse
|
||||||
|
FromVersion =:= "4.1" orelse
|
||||||
|
FromVersion =:= "4.2"->
|
||||||
logger:error("While importing data from EMQX versions prior to 4.3 "
|
logger:error("While importing data from EMQX versions prior to 4.3 "
|
||||||
"it is necessary to specify the value of \"auth.mnesia.as\" parameter "
|
"it is necessary to specify the value of \"auth.mnesia.as\" parameter "
|
||||||
"as it was configured in etc/plugins/emqx_auth_mnesia.conf.\n"
|
"as it was configured in etc/plugins/emqx_auth_mnesia.conf.\n"
|
||||||
|
|
@ -732,7 +734,9 @@ do_read_global_auth_type(Data) ->
|
||||||
"or\n"
|
"or\n"
|
||||||
" $ emqx_ctl data import <filename> --env '{\"auth.mnesia.as\":\"clientid\"}'",
|
" $ emqx_ctl data import <filename> --env '{\"auth.mnesia.as\":\"clientid\"}'",
|
||||||
[]),
|
[]),
|
||||||
error(import_failed)
|
error(import_failed);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
end.
|
end.
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue