Merge pull request #8470 from DDDHuang/tpm_check
fix(api): topic metrics check exist before create
This commit is contained in:
commit
88ca8ff503
|
@ -1,7 +1,7 @@
|
||||||
%% -*- mode: erlang -*-
|
%% -*- mode: erlang -*-
|
||||||
{application, emqx_modules, [
|
{application, emqx_modules, [
|
||||||
{description, "EMQX Modules"},
|
{description, "EMQX Modules"},
|
||||||
{vsn, "5.0.1"},
|
{vsn, "5.0.2"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{applications, [kernel, stdlib, emqx]},
|
{applications, [kernel, stdlib, emqx]},
|
||||||
{mod, {emqx_modules_app, []}},
|
{mod, {emqx_modules_app, []}},
|
||||||
|
|
|
@ -296,11 +296,16 @@ topic_metrics(put, #{body := #{<<"action">> := <<"reset">>}}) ->
|
||||||
topic_metrics(post, #{body := #{<<"topic">> := <<>>}}) ->
|
topic_metrics(post, #{body := #{<<"topic">> := <<>>}}) ->
|
||||||
{400, 'BAD_REQUEST', <<"Topic can not be empty">>};
|
{400, 'BAD_REQUEST', <<"Topic can not be empty">>};
|
||||||
topic_metrics(post, #{body := #{<<"topic">> := Topic}}) ->
|
topic_metrics(post, #{body := #{<<"topic">> := Topic}}) ->
|
||||||
|
case lists:member(Topic, emqx_modules_conf:topic_metrics()) of
|
||||||
|
false ->
|
||||||
case emqx_modules_conf:add_topic_metrics(Topic) of
|
case emqx_modules_conf:add_topic_metrics(Topic) of
|
||||||
{ok, Topic} ->
|
{ok, Topic} ->
|
||||||
get_cluster_response([Topic]);
|
get_cluster_response([Topic]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
reason2httpresp(Reason)
|
reason2httpresp(Reason)
|
||||||
|
end;
|
||||||
|
true ->
|
||||||
|
reason2httpresp(already_existed)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
operate_topic_metrics(get, #{bindings := #{topic := Topic}}) ->
|
operate_topic_metrics(get, #{bindings := #{topic := Topic}}) ->
|
||||||
|
|
Loading…
Reference in New Issue