fix: define ssl SNI field as a non-empty-string

This commit is contained in:
Shawn 2022-04-27 14:17:22 +08:00
parent 46550d5a6f
commit 0635918d16
2 changed files with 11 additions and 11 deletions

View File

@ -57,6 +57,7 @@
validate_heap_size/1, validate_heap_size/1,
parse_user_lookup_fun/1, parse_user_lookup_fun/1,
validate_alarm_actions/1, validate_alarm_actions/1,
non_empty_string/1,
validations/0 validations/0
]). ]).
@ -1898,6 +1899,7 @@ client_ssl_opts_schema(Defaults1) ->
hoconsc:union([disable, string()]), hoconsc:union([disable, string()]),
#{ #{
required => false, required => false,
validator => fun emqx_schema:non_empty_string/1,
desc => ?DESC(client_ssl_opts_schema_server_name_indication) desc => ?DESC(client_ssl_opts_schema_server_name_indication)
} }
)} )}
@ -2177,3 +2179,8 @@ authentication(Type) ->
-spec qos() -> typerefl:type(). -spec qos() -> typerefl:type().
qos() -> qos() ->
typerefl:alias("qos", typerefl:union([0, 1, 2])). typerefl:alias("qos", typerefl:union([0, 1, 2])).
non_empty_string(<<>>) -> {error, empty_string_not_allowed};
non_empty_string("") -> {error, empty_string_not_allowed};
non_empty_string(S) when is_binary(S); is_list(S) -> ok;
non_empty_string(_) -> {error, invalid_string}.

View File

@ -31,8 +31,6 @@
, egress_desc/0 , egress_desc/0
]). ]).
-export([non_empty_string/1]).
-import(emqx_schema, [mk_duration/2]). -import(emqx_schema, [mk_duration/2]).
namespace() -> "connector-mqtt". namespace() -> "connector-mqtt".
@ -98,7 +96,7 @@ fields("ingress") ->
[ {remote_topic, [ {remote_topic,
sc(binary(), sc(binary(),
#{ required => true #{ required => true
, validator => fun ?MODULE:non_empty_string/1 , validator => fun emqx_schema:non_empty_string/1
, desc => ?DESC("ingress_remote_topic") , desc => ?DESC("ingress_remote_topic")
})} })}
, {remote_qos, , {remote_qos,
@ -108,7 +106,7 @@ fields("ingress") ->
})} })}
, {local_topic, , {local_topic,
sc(binary(), sc(binary(),
#{ validator => fun ?MODULE:non_empty_string/1 #{ validator => fun emqx_schema:non_empty_string/1
, desc => ?DESC("ingress_local_topic") , desc => ?DESC("ingress_local_topic")
})} })}
, {local_qos, , {local_qos,
@ -140,12 +138,12 @@ fields("egress") ->
[ {local_topic, [ {local_topic,
sc(binary(), sc(binary(),
#{ desc => ?DESC("egress_local_topic") #{ desc => ?DESC("egress_local_topic")
, validator => fun ?MODULE:non_empty_string/1 , validator => fun emqx_schema:non_empty_string/1
})} })}
, {remote_topic, , {remote_topic,
sc(binary(), sc(binary(),
#{ required => true #{ required => true
, validator => fun ?MODULE:non_empty_string/1 , validator => fun emqx_schema:non_empty_string/1
, desc => ?DESC("egress_remote_topic") , desc => ?DESC("egress_remote_topic")
})} })}
, {remote_qos, , {remote_qos,
@ -228,10 +226,5 @@ local_topic will be forwarded.
qos() -> qos() ->
hoconsc:union([emqx_schema:qos(), binary()]). hoconsc:union([emqx_schema:qos(), binary()]).
non_empty_string(<<>>) -> {error, empty_string_not_allowed};
non_empty_string("") -> {error, empty_string_not_allowed};
non_empty_string(S) when is_binary(S); is_list(S) -> ok;
non_empty_string(_) -> {error, invalid_string}.
sc(Type, Meta) -> hoconsc:mk(Type, Meta). sc(Type, Meta) -> hoconsc:mk(Type, Meta).
ref(Field) -> hoconsc:ref(?MODULE, Field). ref(Field) -> hoconsc:ref(?MODULE, Field).