chore: remove config_path() function
This commit is contained in:
parent
2e5401f3cb
commit
367a0e312a
|
@ -363,10 +363,7 @@ authorize(
|
||||||
emqx_metrics:inc(?METRIC_SUPERUSER),
|
emqx_metrics:inc(?METRIC_SUPERUSER),
|
||||||
{stop, #{result => allow, from => superuser}};
|
{stop, #{result => allow, from => superuser}};
|
||||||
false ->
|
false ->
|
||||||
X = authorize_non_superuser(Client, PubSub, Topic, DefaultResult, Sources),
|
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
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
authorize_non_superuser(
|
authorize_non_superuser(
|
||||||
|
|
|
@ -121,3 +121,6 @@
|
||||||
false
|
false
|
||||||
end)
|
end)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
-define(KEY_PATH, [rule_engine, rules]).
|
||||||
|
-define(RULE_PATH(RULE), [rule_engine, rules, RULE]).
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
-export([start_link/0]).
|
-export([start_link/0]).
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
post_config_update/5,
|
post_config_update/5
|
||||||
config_key_path/0
|
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% Rule Management
|
%% Rule Management
|
||||||
|
@ -99,14 +98,9 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(RATE_METRICS, ['matched']).
|
-define(RATE_METRICS, ['matched']).
|
||||||
-define(KEY_PATH, [rule_engine, rules]).
|
|
||||||
-define(RULE_PATH(RULE), [rule_engine, rules, RULE]).
|
|
||||||
|
|
||||||
-type action_name() :: binary() | #{function := binary()}.
|
-type action_name() :: binary() | #{function := binary()}.
|
||||||
|
|
||||||
config_key_path() ->
|
|
||||||
?KEY_PATH.
|
|
||||||
|
|
||||||
-spec start_link() -> {ok, pid()} | ignore | {error, Reason :: term()}.
|
-spec start_link() -> {ok, pid()} | ignore | {error, Reason :: term()}.
|
||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link({local, ?RULE_ENGINE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?RULE_ENGINE}, ?MODULE, [], []).
|
||||||
|
@ -258,7 +252,7 @@ ensure_action_removed(RuleId, ActionName) ->
|
||||||
#{<<"actions">> := Acts} = Conf ->
|
#{<<"actions">> := Acts} = Conf ->
|
||||||
NewActs = [AName || AName <- Acts, FilterFunc(AName, ActionName)],
|
NewActs = [AName || AName <- Acts, FilterFunc(AName, ActionName)],
|
||||||
{ok, _} = emqx_conf:update(
|
{ok, _} = emqx_conf:update(
|
||||||
emqx_rule_engine:config_key_path() ++ [RuleId],
|
?RULE_PATH(RuleId),
|
||||||
Conf#{<<"actions">> => NewActs},
|
Conf#{<<"actions">> => NewActs},
|
||||||
#{override_to => cluster}
|
#{override_to => cluster}
|
||||||
),
|
),
|
||||||
|
|
|
@ -351,11 +351,11 @@ param_path_id() ->
|
||||||
{400, #{code => 'BAD_REQUEST', message => <<"empty rule id is not allowed">>}};
|
{400, #{code => 'BAD_REQUEST', message => <<"empty rule id is not allowed">>}};
|
||||||
Id ->
|
Id ->
|
||||||
Params = filter_out_request_body(add_metadata(Params0)),
|
Params = filter_out_request_body(add_metadata(Params0)),
|
||||||
ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
|
|
||||||
case emqx_rule_engine:get_rule(Id) of
|
case emqx_rule_engine:get_rule(Id) of
|
||||||
{ok, _Rule} ->
|
{ok, _Rule} ->
|
||||||
{400, #{code => 'BAD_REQUEST', message => <<"rule id already exists">>}};
|
{400, #{code => 'BAD_REQUEST', message => <<"rule id already exists">>}};
|
||||||
not_found ->
|
not_found ->
|
||||||
|
ConfPath = ?RULE_PATH(Id),
|
||||||
case emqx_conf:update(ConfPath, Params, #{override_to => cluster}) of
|
case emqx_conf:update(ConfPath, Params, #{override_to => cluster}) of
|
||||||
{ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
|
{ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
|
||||||
{201, format_rule_info_resp(Rule)};
|
{201, format_rule_info_resp(Rule)};
|
||||||
|
@ -395,7 +395,7 @@ param_path_id() ->
|
||||||
end;
|
end;
|
||||||
'/rules/:id'(put, #{bindings := #{id := Id}, body := Params0}) ->
|
'/rules/:id'(put, #{bindings := #{id := Id}, body := Params0}) ->
|
||||||
Params = filter_out_request_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
|
case emqx_conf:update(ConfPath, Params, #{override_to => cluster}) of
|
||||||
{ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
|
{ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
|
||||||
{200, format_rule_info_resp(Rule)};
|
{200, format_rule_info_resp(Rule)};
|
||||||
|
@ -410,7 +410,7 @@ param_path_id() ->
|
||||||
'/rules/:id'(delete, #{bindings := #{id := Id}}) ->
|
'/rules/:id'(delete, #{bindings := #{id := Id}}) ->
|
||||||
case emqx_rule_engine:get_rule(Id) of
|
case emqx_rule_engine:get_rule(Id) of
|
||||||
{ok, _Rule} ->
|
{ok, _Rule} ->
|
||||||
ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
|
ConfPath = ?RULE_PATH(Id),
|
||||||
case emqx_conf:remove(ConfPath, #{override_to => cluster}) of
|
case emqx_conf:remove(ConfPath, #{override_to => cluster}) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
{204};
|
{204};
|
||||||
|
|
|
@ -29,7 +29,7 @@ start(_Type, _Args) ->
|
||||||
ok = emqx_rule_events:reload(),
|
ok = emqx_rule_events:reload(),
|
||||||
SupRet = emqx_rule_engine_sup:start_link(),
|
SupRet = emqx_rule_engine_sup:start_link(),
|
||||||
ok = emqx_rule_engine:load_rules(),
|
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(RulePath ++ ['?'], emqx_rule_engine),
|
||||||
emqx_conf:add_handler([RuleEngine], emqx_rule_engine),
|
emqx_conf:add_handler([RuleEngine], emqx_rule_engine),
|
||||||
emqx_rule_engine_cli:load(),
|
emqx_rule_engine_cli:load(),
|
||||||
|
@ -37,7 +37,7 @@ start(_Type, _Args) ->
|
||||||
|
|
||||||
stop(_State) ->
|
stop(_State) ->
|
||||||
emqx_rule_engine_cli:unload(),
|
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(RulePath ++ ['?']),
|
||||||
emqx_conf:remove_handler([RuleEngine]),
|
emqx_conf:remove_handler([RuleEngine]),
|
||||||
ok = emqx_rule_events:unload().
|
ok = emqx_rule_events:unload().
|
||||||
|
|
|
@ -472,19 +472,17 @@ t_ensure_action_removed(_) ->
|
||||||
Id = <<"t_ensure_action_removed">>,
|
Id = <<"t_ensure_action_removed">>,
|
||||||
GetSelectedData = <<"emqx_rule_sqltester:get_selected_data">>,
|
GetSelectedData = <<"emqx_rule_sqltester:get_selected_data">>,
|
||||||
emqx:update_config(
|
emqx:update_config(
|
||||||
[rule_engine, rules],
|
[rule_engine, rules, Id],
|
||||||
#{
|
#{
|
||||||
Id => #{
|
<<"actions">> => [
|
||||||
<<"actions">> => [
|
#{<<"function">> => GetSelectedData},
|
||||||
#{<<"function">> => GetSelectedData},
|
#{<<"function">> => <<"console">>},
|
||||||
#{<<"function">> => <<"console">>},
|
#{<<"function">> => <<"republish">>},
|
||||||
#{<<"function">> => <<"republish">>},
|
<<"mysql:foo">>,
|
||||||
<<"mysql:foo">>,
|
<<"mqtt:bar">>
|
||||||
<<"mqtt:bar">>
|
],
|
||||||
],
|
<<"description">> => <<"">>,
|
||||||
<<"description">> => <<"">>,
|
<<"sql">> => <<"SELECT * FROM \"t/#\"">>
|
||||||
<<"sql">> => <<"SELECT * FROM \"t/#\"">>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
|
|
Loading…
Reference in New Issue