fix(backup): fix data import/export problem
This commit is contained in:
parent
72c1ee264c
commit
109b2f4e90
|
@ -17,6 +17,7 @@
|
||||||
-module(emqx_mgmt_data_backup).
|
-module(emqx_mgmt_data_backup).
|
||||||
|
|
||||||
-include("emqx_mgmt.hrl").
|
-include("emqx_mgmt.hrl").
|
||||||
|
-include_lib("emqx_rule_engine/include/rule_engine.hrl").
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-include_lib("kernel/include/file.hrl").
|
-include_lib("kernel/include/file.hrl").
|
||||||
|
|
||||||
|
@ -59,7 +60,11 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
export_rules() ->
|
export_rules() ->
|
||||||
lists:map(fun({_, RuleId, _, RawSQL, _, _, _, _, _, _, Actions, Enabled, Desc}) ->
|
lists:map(fun(#rule{id = RuleId,
|
||||||
|
rawsql = RawSQL,
|
||||||
|
actions = Actions,
|
||||||
|
enabled = Enabled,
|
||||||
|
description = Desc}) ->
|
||||||
[{id, RuleId},
|
[{id, RuleId},
|
||||||
{rawsql, RawSQL},
|
{rawsql, RawSQL},
|
||||||
{actions, actions_to_prop_list(Actions)},
|
{actions, actions_to_prop_list(Actions)},
|
||||||
|
@ -68,7 +73,11 @@ export_rules() ->
|
||||||
end, emqx_rule_registry:get_rules()).
|
end, emqx_rule_registry:get_rules()).
|
||||||
|
|
||||||
export_resources() ->
|
export_resources() ->
|
||||||
lists:map(fun({_, Id, Type, Config, CreatedAt, Desc}) ->
|
lists:map(fun(#resource{id = Id,
|
||||||
|
type = Type,
|
||||||
|
config = Config,
|
||||||
|
created_at = CreatedAt,
|
||||||
|
description = Desc}) ->
|
||||||
NCreatedAt = case CreatedAt of
|
NCreatedAt = case CreatedAt of
|
||||||
undefined -> null;
|
undefined -> null;
|
||||||
_ -> CreatedAt
|
_ -> CreatedAt
|
||||||
|
@ -236,18 +245,25 @@ import_resources_and_rules(Resources, Rules, FromVersion)
|
||||||
when FromVersion =:= "4.0" orelse FromVersion =:= "4.1" orelse FromVersion =:= "4.2" ->
|
when FromVersion =:= "4.0" orelse FromVersion =:= "4.1" orelse FromVersion =:= "4.2" ->
|
||||||
Configs = lists:foldl(fun(#{<<"id">> := ID,
|
Configs = lists:foldl(fun(#{<<"id">> := ID,
|
||||||
<<"type">> := <<"web_hook">>,
|
<<"type">> := <<"web_hook">>,
|
||||||
<<"config">> := #{<<"content_type">> := ContentType,
|
<<"config">> := #{<<"connect_timeout">> := ConnectTimeout,
|
||||||
|
<<"content_type">> := ContentType,
|
||||||
<<"headers">> := Headers,
|
<<"headers">> := Headers,
|
||||||
<<"method">> := Method,
|
<<"method">> := Method,
|
||||||
|
<<"pool_size">> := PoolSize,
|
||||||
|
<<"request_timeout">> := RequestTimeout,
|
||||||
<<"url">> := URL}} = Resource, Acc) ->
|
<<"url">> := URL}} = Resource, Acc) ->
|
||||||
NConfig = #{<<"connect_timeout">> => 5,
|
CovertFun = fun(Int) ->
|
||||||
<<"request_timeout">> => 5,
|
list_to_binary(integer_to_list(Int) ++ "s")
|
||||||
|
end,
|
||||||
|
NConfig = #{<<"connect_timeout">> => CovertFun(ConnectTimeout),
|
||||||
|
<<"method">> => Method,
|
||||||
|
<<"pool_size">> => PoolSize,
|
||||||
|
<<"request_timeout">> => CovertFun(RequestTimeout),
|
||||||
<<"cacertfile">> => <<>>,
|
<<"cacertfile">> => <<>>,
|
||||||
<<"certfile">> => <<>>,
|
<<"certfile">> => <<>>,
|
||||||
<<"keyfile">> => <<>>,
|
<<"keyfile">> => <<>>,
|
||||||
<<"pool_size">> => 8,
|
<<"verify">> => true,
|
||||||
<<"url">> => URL,
|
<<"url">> => URL},
|
||||||
<<"verify">> => true},
|
|
||||||
NResource = Resource#{<<"config">> := NConfig},
|
NResource = Resource#{<<"config">> := NConfig},
|
||||||
{ok, _Resource} = import_resource(NResource),
|
{ok, _Resource} = import_resource(NResource),
|
||||||
NHeaders = maps:put(<<"content-type">>, ContentType, Headers),
|
NHeaders = maps:put(<<"content-type">>, ContentType, Headers),
|
||||||
|
@ -284,7 +300,18 @@ apply_new_config([Action = #{<<"name">> := <<"data_to_webserver">>,
|
||||||
<<"method">> => Method,
|
<<"method">> => Method,
|
||||||
<<"path">> => Path},
|
<<"path">> => Path},
|
||||||
apply_new_config(More, Configs, [Action#{<<"args">> := Args} | Acc])
|
apply_new_config(More, Configs, [Action#{<<"args">> := Args} | Acc])
|
||||||
end.
|
end;
|
||||||
|
|
||||||
|
apply_new_config([Action = #{<<"args">> := #{<<"$resource">> := ResourceId,
|
||||||
|
<<"forward_topic">> := ForwardTopic,
|
||||||
|
<<"payload_tmpl">> := PayloadTmpl},
|
||||||
|
<<"fallbacks">> := _Fallbacks,
|
||||||
|
<<"id">> := _Id,
|
||||||
|
<<"name">> := <<"data_to_mqtt_broker">>} | More], Configs, Acc) ->
|
||||||
|
Args = #{<<"$resource">> => ResourceId,
|
||||||
|
<<"payload_tmpl">> => PayloadTmpl,
|
||||||
|
<<"forward_topic">> => ForwardTopic},
|
||||||
|
apply_new_config(More, Configs, [Action#{<<"args">> := Args} | Acc]).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue