Explorar el Código

chore: remove config_path() function

某文 hace 2 años
padre
commit
367a0e312a

+ 1 - 4
apps/emqx_authz/src/emqx_authz.erl

@@ -363,10 +363,7 @@ authorize(
             emqx_metrics:inc(?METRIC_SUPERUSER),
             {stop, #{result => allow, from => superuser}};
         false ->
-            X = authorize_non_superuser(Client, PubSub, Topic, DefaultResult, Sources),
-            io:format("www:~p~n", [{Client, PubSub, Topic, DefaultResult, Sources}]),
-            io:format("res:~p~n", [X]),
-            X
+            authorize_non_superuser(Client, PubSub, Topic, DefaultResult, Sources)
     end.
 
 authorize_non_superuser(

+ 3 - 0
apps/emqx_rule_engine/include/rule_engine.hrl

@@ -121,3 +121,6 @@
             false
     end)
 ).
+
+-define(KEY_PATH, [rule_engine, rules]).
+-define(RULE_PATH(RULE), [rule_engine, rules, RULE]).

+ 2 - 8
apps/emqx_rule_engine/src/emqx_rule_engine.erl

@@ -26,8 +26,7 @@
 -export([start_link/0]).
 
 -export([
-    post_config_update/5,
-    config_key_path/0
+    post_config_update/5
 ]).
 
 %% Rule Management
@@ -99,14 +98,9 @@
 ]).
 
 -define(RATE_METRICS, ['matched']).
--define(KEY_PATH, [rule_engine, rules]).
--define(RULE_PATH(RULE), [rule_engine, rules, RULE]).
 
 -type action_name() :: binary() | #{function := binary()}.
 
-config_key_path() ->
-    ?KEY_PATH.
-
 -spec start_link() -> {ok, pid()} | ignore | {error, Reason :: term()}.
 start_link() ->
     gen_server:start_link({local, ?RULE_ENGINE}, ?MODULE, [], []).
@@ -258,7 +252,7 @@ ensure_action_removed(RuleId, ActionName) ->
         #{<<"actions">> := Acts} = Conf ->
             NewActs = [AName || AName <- Acts, FilterFunc(AName, ActionName)],
             {ok, _} = emqx_conf:update(
-                emqx_rule_engine:config_key_path() ++ [RuleId],
+                ?RULE_PATH(RuleId),
                 Conf#{<<"actions">> => NewActs},
                 #{override_to => cluster}
             ),

+ 3 - 3
apps/emqx_rule_engine/src/emqx_rule_engine_api.erl

@@ -351,11 +351,11 @@ param_path_id() ->
             {400, #{code => 'BAD_REQUEST', message => <<"empty rule id is not allowed">>}};
         Id ->
             Params = filter_out_request_body(add_metadata(Params0)),
-            ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
             case emqx_rule_engine:get_rule(Id) of
                 {ok, _Rule} ->
                     {400, #{code => 'BAD_REQUEST', message => <<"rule id already exists">>}};
                 not_found ->
+                    ConfPath = ?RULE_PATH(Id),
                     case emqx_conf:update(ConfPath, Params, #{override_to => cluster}) of
                         {ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
                             {201, format_rule_info_resp(Rule)};
@@ -395,7 +395,7 @@ param_path_id() ->
     end;
 '/rules/:id'(put, #{bindings := #{id := Id}, body := Params0}) ->
     Params = filter_out_request_body(Params0),
-    ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
+    ConfPath = ?RULE_PATH(Id),
     case emqx_conf:update(ConfPath, Params, #{override_to => cluster}) of
         {ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
             {200, format_rule_info_resp(Rule)};
@@ -410,7 +410,7 @@ param_path_id() ->
 '/rules/:id'(delete, #{bindings := #{id := Id}}) ->
     case emqx_rule_engine:get_rule(Id) of
         {ok, _Rule} ->
-            ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
+            ConfPath = ?RULE_PATH(Id),
             case emqx_conf:remove(ConfPath, #{override_to => cluster}) of
                 {ok, _} ->
                     {204};

+ 2 - 2
apps/emqx_rule_engine/src/emqx_rule_engine_app.erl

@@ -29,7 +29,7 @@ start(_Type, _Args) ->
     ok = emqx_rule_events:reload(),
     SupRet = emqx_rule_engine_sup:start_link(),
     ok = emqx_rule_engine:load_rules(),
-    RulePath = [RuleEngine | _] = emqx_rule_engine:config_key_path(),
+    RulePath = [RuleEngine | _] = ?KEY_PATH,
     emqx_conf:add_handler(RulePath ++ ['?'], emqx_rule_engine),
     emqx_conf:add_handler([RuleEngine], emqx_rule_engine),
     emqx_rule_engine_cli:load(),
@@ -37,7 +37,7 @@ start(_Type, _Args) ->
 
 stop(_State) ->
     emqx_rule_engine_cli:unload(),
-    RulePath = [RuleEngine | _] = emqx_rule_engine:config_key_path(),
+    RulePath = [RuleEngine | _] = ?KEY_PATH,
     emqx_conf:remove_handler(RulePath ++ ['?']),
     emqx_conf:remove_handler([RuleEngine]),
     ok = emqx_rule_events:unload().

+ 10 - 12
apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl

@@ -472,19 +472,17 @@ t_ensure_action_removed(_) ->
     Id = <<"t_ensure_action_removed">>,
     GetSelectedData = <<"emqx_rule_sqltester:get_selected_data">>,
     emqx:update_config(
-        [rule_engine, rules],
+        [rule_engine, rules, Id],
         #{
-            Id => #{
-                <<"actions">> => [
-                    #{<<"function">> => GetSelectedData},
-                    #{<<"function">> => <<"console">>},
-                    #{<<"function">> => <<"republish">>},
-                    <<"mysql:foo">>,
-                    <<"mqtt:bar">>
-                ],
-                <<"description">> => <<"">>,
-                <<"sql">> => <<"SELECT * FROM \"t/#\"">>
-            }
+            <<"actions">> => [
+                #{<<"function">> => GetSelectedData},
+                #{<<"function">> => <<"console">>},
+                #{<<"function">> => <<"republish">>},
+                <<"mysql:foo">>,
+                <<"mqtt:bar">>
+            ],
+            <<"description">> => <<"">>,
+            <<"sql">> => <<"SELECT * FROM \"t/#\"">>
         }
     ),
     ?assertMatch(