Merge pull request #8470 from DDDHuang/tpm_check

fix(api): topic metrics check exist before create
This commit is contained in:
DDDHuang 2022-07-13 15:26:47 +08:00 committed by GitHub
commit 88ca8ff503
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_modules, [
{description, "EMQX Modules"},
{vsn, "5.0.1"},
{vsn, "5.0.2"},
{modules, []},
{applications, [kernel, stdlib, emqx]},
{mod, {emqx_modules_app, []}},

View File

@ -296,11 +296,16 @@ topic_metrics(put, #{body := #{<<"action">> := <<"reset">>}}) ->
topic_metrics(post, #{body := #{<<"topic">> := <<>>}}) ->
{400, 'BAD_REQUEST', <<"Topic can not be empty">>};
topic_metrics(post, #{body := #{<<"topic">> := Topic}}) ->
case emqx_modules_conf:add_topic_metrics(Topic) of
{ok, Topic} ->
get_cluster_response([Topic]);
{error, Reason} ->
reason2httpresp(Reason)
case lists:member(Topic, emqx_modules_conf:topic_metrics()) of
false ->
case emqx_modules_conf:add_topic_metrics(Topic) of
{ok, Topic} ->
get_cluster_response([Topic]);
{error, Reason} ->
reason2httpresp(Reason)
end;
true ->
reason2httpresp(already_existed)
end.
operate_topic_metrics(get, #{bindings := #{topic := Topic}}) ->