Просмотр исходного кода

fix: deny creating metrics for empty topics (#5650)

* fix: deny null topic create metrics
DDDHuang 4 лет назад
Родитель
Сommit
f5bfa4cd43
1 измененных файлов с 3 добавлено и 1 удалено
  1. 3 1
      apps/emqx_modules/src/emqx_topic_metrics_api.erl

+ 3 - 1
apps/emqx_modules/src/emqx_topic_metrics_api.erl

@@ -94,7 +94,7 @@ topic_metrics_api() ->
             responses => #{
             responses => #{
                 <<"200">> => schema(<<"Create topic metrics success">>),
                 <<"200">> => schema(<<"Create topic metrics success">>),
                 <<"409">> => error_schema(<<"Topic metrics max limit">>, [?EXCEED_LIMIT]),
                 <<"409">> => error_schema(<<"Topic metrics max limit">>, [?EXCEED_LIMIT]),
-                <<"400">> => error_schema(<<"Topic metrics already exist">>, [?BAD_REQUEST])
+                <<"400">> => error_schema(<<"Topic metrics already exist or bad topic">>, [?BAD_REQUEST])
             }
             }
         }
         }
     },
     },
@@ -137,6 +137,8 @@ topic_metrics(put, #{body := #{<<"topic">> := Topic, <<"action">> := <<"reset">>
     reset(Topic);
     reset(Topic);
 topic_metrics(put, #{body := #{<<"action">> := <<"reset">>}}) ->
 topic_metrics(put, #{body := #{<<"action">> := <<"reset">>}}) ->
     reset();
     reset();
+topic_metrics(post, #{body := #{<<"topic">> := <<>>}}) ->
+    {400, 'BAD_REQUEST', <<"Topic can not be empty">>};
 topic_metrics(post, #{body := #{<<"topic">> := Topic}}) ->
 topic_metrics(post, #{body := #{<<"topic">> := Topic}}) ->
     register(Topic).
     register(Topic).