|
@@ -596,6 +596,26 @@ do_export_extra_data() ->
|
|
|
do_export_extra_data() -> [].
|
|
do_export_extra_data() -> [].
|
|
|
-endif.
|
|
-endif.
|
|
|
|
|
|
|
|
|
|
+-ifdef(EMQX_ENTERPRISE).
|
|
|
|
|
+import(Filename, OverridesJson) ->
|
|
|
|
|
+ case file:read_file(Filename) of
|
|
|
|
|
+ {ok, Json} ->
|
|
|
|
|
+ Imported = emqx_json:decode(Json, [return_maps]),
|
|
|
|
|
+ Overrides = emqx_json:decode(OverridesJson, [return_maps]),
|
|
|
|
|
+ Data = maps:merge(Imported, Overrides),
|
|
|
|
|
+ Version = to_version(maps:get(<<"version">>, Data)),
|
|
|
|
|
+ read_global_auth_type(Data),
|
|
|
|
|
+ try
|
|
|
|
|
+ do_import_data(Data, Version),
|
|
|
|
|
+ logger:debug("The emqx data has been imported successfully"),
|
|
|
|
|
+ ok
|
|
|
|
|
+ catch Class:Reason:Stack ->
|
|
|
|
|
+ logger:error("The emqx data import failed: ~0p", [{Class, Reason, Stack}]),
|
|
|
|
|
+ {error, import_failed}
|
|
|
|
|
+ end;
|
|
|
|
|
+ Error -> Error
|
|
|
|
|
+ end.
|
|
|
|
|
+-else.
|
|
|
import(Filename, OverridesJson) ->
|
|
import(Filename, OverridesJson) ->
|
|
|
case file:read_file(Filename) of
|
|
case file:read_file(Filename) of
|
|
|
{ok, Json} ->
|
|
{ok, Json} ->
|
|
@@ -620,6 +640,7 @@ import(Filename, OverridesJson) ->
|
|
|
end;
|
|
end;
|
|
|
Error -> Error
|
|
Error -> Error
|
|
|
end.
|
|
end.
|
|
|
|
|
+-endif.
|
|
|
|
|
|
|
|
do_import_data(Data, Version) ->
|
|
do_import_data(Data, Version) ->
|
|
|
do_import_extra_data(Data, Version),
|
|
do_import_extra_data(Data, Version),
|
|
@@ -651,6 +672,7 @@ flag_to_boolean(<<"off">>) -> false;
|
|
|
flag_to_boolean(Other) -> Other.
|
|
flag_to_boolean(Other) -> Other.
|
|
|
-endif.
|
|
-endif.
|
|
|
|
|
|
|
|
|
|
+-ifndef(EMQX_ENTERPRISE).
|
|
|
is_version_supported(Data, Version) ->
|
|
is_version_supported(Data, Version) ->
|
|
|
case { maps:get(<<"auth_clientid">>, Data, [])
|
|
case { maps:get(<<"auth_clientid">>, Data, [])
|
|
|
, maps:get(<<"auth_username">>, Data, [])
|
|
, maps:get(<<"auth_username">>, Data, [])
|
|
@@ -662,7 +684,7 @@ is_version_supported(Data, Version) ->
|
|
|
is_version_supported2("4.1") ->
|
|
is_version_supported2("4.1") ->
|
|
|
true;
|
|
true;
|
|
|
is_version_supported2("4.3") ->
|
|
is_version_supported2("4.3") ->
|
|
|
- true;
|
|
|
|
|
|
|
+ true;
|
|
|
is_version_supported2(Version) ->
|
|
is_version_supported2(Version) ->
|
|
|
case re:run(Version, "^4.[02].\\d+$", [{capture, none}]) of
|
|
case re:run(Version, "^4.[02].\\d+$", [{capture, none}]) of
|
|
|
match ->
|
|
match ->
|
|
@@ -670,12 +692,13 @@ is_version_supported2(Version) ->
|
|
|
[4, 2, N] -> N >= 11;
|
|
[4, 2, N] -> N >= 11;
|
|
|
[4, 0, N] -> N >= 13;
|
|
[4, 0, N] -> N >= 13;
|
|
|
_ -> false
|
|
_ -> false
|
|
|
- catch
|
|
|
|
|
|
|
+ catch
|
|
|
_ : _ -> false
|
|
_ : _ -> false
|
|
|
end;
|
|
end;
|
|
|
nomatch ->
|
|
nomatch ->
|
|
|
false
|
|
false
|
|
|
end.
|
|
end.
|
|
|
|
|
+-endif.
|
|
|
|
|
|
|
|
read_global_auth_type(Data) ->
|
|
read_global_auth_type(Data) ->
|
|
|
case {maps:get(<<"auth_mnesia">>, Data, []), maps:get(<<"acl_mnesia">>, Data, [])} of
|
|
case {maps:get(<<"auth_mnesia">>, Data, []), maps:get(<<"acl_mnesia">>, Data, [])} of
|
|
@@ -686,6 +709,18 @@ read_global_auth_type(Data) ->
|
|
|
do_read_global_auth_type(Data)
|
|
do_read_global_auth_type(Data)
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
|
|
+-ifdef(EMQX_ENTERPRISE).
|
|
|
|
|
+do_read_global_auth_type(Data) ->
|
|
|
|
|
+ case Data of
|
|
|
|
|
+ #{<<"auth.mnesia.as">> := <<"username">>} ->
|
|
|
|
|
+ application:set_env(emqx_auth_mnesia, as, username);
|
|
|
|
|
+ #{<<"auth.mnesia.as">> := <<"clientid">>} ->
|
|
|
|
|
+ application:set_env(emqx_auth_mnesia, as, clientid);
|
|
|
|
|
+ _ ->
|
|
|
|
|
+ ok
|
|
|
|
|
+ end.
|
|
|
|
|
+
|
|
|
|
|
+-else.
|
|
|
do_read_global_auth_type(Data) ->
|
|
do_read_global_auth_type(Data) ->
|
|
|
case Data of
|
|
case Data of
|
|
|
#{<<"auth.mnesia.as">> := <<"username">>} ->
|
|
#{<<"auth.mnesia.as">> := <<"username">>} ->
|
|
@@ -703,6 +738,7 @@ do_read_global_auth_type(Data) ->
|
|
|
[]),
|
|
[]),
|
|
|
error(import_failed)
|
|
error(import_failed)
|
|
|
end.
|
|
end.
|
|
|
|
|
+-endif.
|
|
|
|
|
|
|
|
get_old_type() ->
|
|
get_old_type() ->
|
|
|
{ok, Type} = application:get_env(emqx_auth_mnesia, as),
|
|
{ok, Type} = application:get_env(emqx_auth_mnesia, as),
|