|
@@ -36,6 +36,7 @@ roots() ->
|
|
|
array("rewrite", #{
|
|
array("rewrite", #{
|
|
|
desc => "List of topic rewrite rules.",
|
|
desc => "List of topic rewrite rules.",
|
|
|
importance => ?IMPORTANCE_HIDDEN,
|
|
importance => ?IMPORTANCE_HIDDEN,
|
|
|
|
|
+ validator => fun rewrite_validator/1,
|
|
|
default => []
|
|
default => []
|
|
|
}),
|
|
}),
|
|
|
array("topic_metrics", #{
|
|
array("topic_metrics", #{
|
|
@@ -45,6 +46,37 @@ roots() ->
|
|
|
})
|
|
})
|
|
|
].
|
|
].
|
|
|
|
|
|
|
|
|
|
+rewrite_validator(Rules) ->
|
|
|
|
|
+ case
|
|
|
|
|
+ lists:foldl(
|
|
|
|
|
+ fun
|
|
|
|
|
+ (#{<<"action">> := subscribe}, Acc) ->
|
|
|
|
|
+ Acc;
|
|
|
|
|
+ (#{<<"dest_topic">> := DestTopic}, InvalidAcc) ->
|
|
|
|
|
+ try
|
|
|
|
|
+ true = emqx_topic:validate(name, DestTopic),
|
|
|
|
|
+ InvalidAcc
|
|
|
|
|
+ catch
|
|
|
|
|
+ _:_ ->
|
|
|
|
|
+ [DestTopic | InvalidAcc]
|
|
|
|
|
+ end
|
|
|
|
|
+ end,
|
|
|
|
|
+ [],
|
|
|
|
|
+ Rules
|
|
|
|
|
+ )
|
|
|
|
|
+ of
|
|
|
|
|
+ [] ->
|
|
|
|
|
+ ok;
|
|
|
|
|
+ InvalidTopics ->
|
|
|
|
|
+ {
|
|
|
|
|
+ error,
|
|
|
|
|
+ #{
|
|
|
|
|
+ msg => "cannot_use_wildcard_for_destination_topic",
|
|
|
|
|
+ invalid_topics => InvalidTopics
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ end.
|
|
|
|
|
+
|
|
|
fields("delayed") ->
|
|
fields("delayed") ->
|
|
|
[
|
|
[
|
|
|
{enable, ?HOCON(boolean(), #{default => true, desc => ?DESC(enable)})},
|
|
{enable, ?HOCON(boolean(), #{default => true, desc => ?DESC(enable)})},
|