Merge pull request #4282 from zmstone/fix-typo-in-macro

fix(mgmt): typo in ifdef macro
This commit is contained in:
Zaiming Shi 2021-03-03 20:42:36 +01:00 committed by GitHub
commit 06cf1736c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 18 deletions

View File

@ -20,7 +20,7 @@
-include_lib("emqx/include/emqx.hrl"). -include_lib("emqx/include/emqx.hrl").
-include_lib("kernel/include/file.hrl"). -include_lib("kernel/include/file.hrl").
-ifdef(EMQX_ENTERPISE). -ifdef(EMQX_ENTERPRISE).
-export([ export_modules/0 -export([ export_modules/0
, export_schemas/0 , export_schemas/0
, export_confs/0 , export_confs/0
@ -123,7 +123,7 @@ export_acl_mnesia() ->
end, ets:tab2list(emqx_acl)) end, ets:tab2list(emqx_acl))
end. end.
-ifdef(EMQX_ENTERPISE). -ifdef(EMQX_ENTERPRISE).
export_modules() -> export_modules() ->
case ets:info(emqx_modules) of case ets:info(emqx_modules) of
undefined -> []; undefined -> [];
@ -174,12 +174,8 @@ export_confs() ->
confs_to_binary(Confs) -> confs_to_binary(Confs) ->
[{list_to_binary(Key), list_to_binary(Val)} || {Key, Val} <-Confs]. [{list_to_binary(Key), list_to_binary(Val)} || {Key, Val} <-Confs].
-endif. -else.
import_rules(Rules) ->
lists:foreach(fun(Resource) ->
import_resource(Resource)
end, Rules).
import_rule(#{<<"id">> := RuleId, import_rule(#{<<"id">> := RuleId,
<<"rawsql">> := RawSQL, <<"rawsql">> := RawSQL,
<<"actions">> := Actions, <<"actions">> := Actions,
@ -195,6 +191,22 @@ import_rule(#{<<"id">> := RuleId,
emqx_rule_engine:create_rule(Rule#{enabled => false}) emqx_rule_engine:create_rule(Rule#{enabled => false})
end. end.
map_to_actions(Maps) ->
[map_to_action(M) || M <- Maps].
map_to_action(Map = #{<<"id">> := ActionInstId, <<"name">> := Name, <<"args">> := Args}) ->
#{id => ActionInstId,
name => any_to_atom(Name),
args => Args,
fallbacks => map_to_actions(maps:get(<<"fallbacks">>, Map, []))}.
-endif.
import_rules(Rules) ->
lists:foreach(fun(Resource) ->
import_resource(Resource)
end, Rules).
import_resources(Reources) -> import_resources(Reources) ->
lists:foreach(fun(Resource) -> lists:foreach(fun(Resource) ->
import_resource(Resource) import_resource(Resource)
@ -274,6 +286,8 @@ apply_new_config([Action = #{<<"name">> := <<"data_to_webserver">>,
apply_new_config(More, Configs, [Action#{<<"args">> := Args} | Acc]) apply_new_config(More, Configs, [Action#{<<"args">> := Args} | Acc])
end. end.
-endif.
actions_to_prop_list(Actions) -> actions_to_prop_list(Actions) ->
[action_to_prop_list(Act) || Act <- Actions]. [action_to_prop_list(Act) || Act <- Actions].
@ -282,7 +296,6 @@ action_to_prop_list({action_instance, ActionInstId, Name, FallbackActions, Args}
{name, Name}, {name, Name},
{fallbacks, actions_to_prop_list(FallbackActions)}, {fallbacks, actions_to_prop_list(FallbackActions)},
{args, Args}]. {args, Args}].
-endif.
import_blacklist(Blacklist) -> import_blacklist(Blacklist) ->
lists:foreach(fun(#{<<"who">> := Who, lists:foreach(fun(#{<<"who">> := Who,
@ -460,15 +473,6 @@ any_to_atom(L) when is_list(L) -> list_to_atom(L);
any_to_atom(B) when is_binary(B) -> binary_to_atom(B, utf8); any_to_atom(B) when is_binary(B) -> binary_to_atom(B, utf8);
any_to_atom(A) when is_atom(A) -> A. any_to_atom(A) when is_atom(A) -> A.
map_to_actions(Maps) ->
[map_to_action(M) || M <- Maps].
map_to_action(Map = #{<<"id">> := ActionInstId, <<"name">> := Name, <<"args">> := Args}) ->
#{id => ActionInstId,
name => any_to_atom(Name),
args => Args,
fallbacks => map_to_actions(maps:get(<<"fallbacks">>, Map, []))}.
to_version(Version) when is_integer(Version) -> to_version(Version) when is_integer(Version) ->
integer_to_list(Version); integer_to_list(Version);
to_version(Version) when is_binary(Version) -> to_version(Version) when is_binary(Version) ->
@ -556,7 +560,7 @@ do_import_data(Data, Version) ->
import_acl_mnesia(maps:get(<<"acl_mnesia">>, Data, []), Version). import_acl_mnesia(maps:get(<<"acl_mnesia">>, Data, []), Version).
-ifdef(EMQX_ENTERPRISE). -ifdef(EMQX_ENTERPRISE).
do_import_extra_data(Data, Version) -> do_import_extra_data(Data, _Version) ->
import_confs(maps:get(<<"configs">>, Data, []), maps:get(<<"listeners_state">>, Data, [])), import_confs(maps:get(<<"configs">>, Data, []), maps:get(<<"listeners_state">>, Data, [])),
import_modules(maps:get(<<"modules">>, Data, [])), import_modules(maps:get(<<"modules">>, Data, [])),
import_schemas(maps:get(<<"schemas">>, Data, [])), import_schemas(maps:get(<<"schemas">>, Data, [])),