瀏覽代碼

fix(config): do not allow default values for configs in zones

Shawn 4 年之前
父節點
當前提交
005332d45d
共有 2 個文件被更改,包括 23 次插入9 次删除
  1. 3 0
      apps/emqx/etc/emqx.conf
  2. 20 9
      apps/emqx/src/emqx_schema.erl

+ 3 - 0
apps/emqx/etc/emqx.conf

@@ -979,6 +979,9 @@ quota {
 ##   - `flapping_detect.*`
 ##   - `force_shutdown.*`
 ##   - `conn_congestion.*`
+##   - `rate_limit.*`
+##   - `quota.*`
+##   - `force_gc.*`
 ##
 ## syntax: zones.<zone-name>
 ## example: zones.my_zone

+ 20 - 9
apps/emqx/src/emqx_schema.erl

@@ -126,19 +126,14 @@ fields("zones") ->
     [ {"$name", ref("zone_settings")}];
 
 fields("zone_settings") ->
-    [ {"mqtt", ref("mqtt")}
-    , {"stats", ref("stats")}
-    , {"flapping_detect", ref("flapping_detect")}
-    , {"force_shutdown", ref("force_shutdown")}
-    , {"conn_congestion", ref("conn_congestion")}
-    , {"force_gc", ref("force_gc")}
-    ];
+    Fields = ["mqtt", "stats", "authorization", "flapping_detect", "force_shutdown",
+              "conn_congestion", "rate_limit", "quota", "force_gc"],
+    [{F, ref("strip_default:" ++ F)} || F <- Fields];
 
 fields("rate_limit") ->
     [ {"max_conn_rate", maybe_infinity(integer(), 1000)}
     , {"conn_messages_in", maybe_infinity(comma_separated_list())}
     , {"conn_bytes_in", maybe_infinity(comma_separated_list())}
-    , {"quota", ref("quota")}
     ];
 
 fields("quota") ->
@@ -334,7 +329,10 @@ fields("alarm") ->
     [ {"actions", t(hoconsc:array(atom()), undefined, [log, publish])}
     , {"size_limit", t(integer(), undefined, 1000)}
     , {"validity_period", t(duration(), undefined, "24h")}
-    ].
+    ];
+
+fields("strip_default:" ++ Name) ->
+    strip_default(fields(Name)).
 
 mqtt_listener() ->
     base_listener() ++
@@ -547,6 +545,19 @@ to_erl_cipher_suite(Str) ->
         Cipher -> Cipher
     end.
 
+strip_default(Fields) ->
+    [do_strip_default(F) || F <- Fields].
+
+do_strip_default({Name, #{type := {ref, Ref}}}) ->
+    {Name, nullable_no_def(ref("strip_default:" ++ Ref))};
+do_strip_default({Name, #{type := {ref, _Mod, Ref}}}) ->
+    {Name, nullable_no_def(ref("strip_default:" ++ Ref))};
+do_strip_default({Name, Type}) ->
+    {Name, nullable_no_def(Type)}.
+
+nullable_no_def(Type) when is_map(Type) ->
+    Type#{default => undefined, nullable => true}.
+
 to_atom(Atom) when is_atom(Atom) ->
     Atom;
 to_atom(Str) when is_list(Str) ->