fix(schema): fix authn/z's schema time unit
This commit is contained in:
parent
e31e175e47
commit
6e3ec6c9db
|
@ -55,7 +55,7 @@
|
|||
|
||||
% workaround: prevent being recognized as unused functions
|
||||
-export([to_duration/1, to_duration_s/1, to_duration_ms/1,
|
||||
to_bytesize/1, to_wordsize/1,
|
||||
mk_duration/2, to_bytesize/1, to_wordsize/1,
|
||||
to_percent/1, to_comma_separated_list/1,
|
||||
to_bar_separated_list/1, to_ip_port/1,
|
||||
to_erl_cipher_suite/1,
|
||||
|
@ -1210,6 +1210,15 @@ ref(Field) -> hoconsc:ref(?MODULE, Field).
|
|||
|
||||
ref(Module, Field) -> hoconsc:ref(Module, Field).
|
||||
|
||||
mk_duration(Desc, OverrideMeta) ->
|
||||
DefaultMeta = #{desc => Desc ++ " Time span. A text string with number followed by time units:
|
||||
`ms` for milli-seconds,
|
||||
`s` for seconds,
|
||||
`m` for minutes,
|
||||
`h` for hours;
|
||||
or combined representation like `1h5m0s`"},
|
||||
hoconsc:mk(typerefl:alias("string", duration()), maps:merge(DefaultMeta, OverrideMeta)).
|
||||
|
||||
to_duration(Str) ->
|
||||
case hocon_postprocess:duration(Str) of
|
||||
I when is_integer(I) -> {ok, I};
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
enable => true})).
|
||||
|
||||
-define(INSTANCE_EXAMPLE_2, maps:merge(?EXAMPLE_2, #{id => <<"password-based:http-server">>,
|
||||
connect_timeout => 5000,
|
||||
connect_timeout => "5s",
|
||||
enable_pipelining => true,
|
||||
headers => #{
|
||||
<<"accept">> => <<"application/json">>,
|
||||
|
@ -102,8 +102,8 @@
|
|||
},
|
||||
max_retries => 5,
|
||||
pool_size => 8,
|
||||
request_timeout => 5000,
|
||||
retry_interval => 1000,
|
||||
request_timeout => "5s",
|
||||
retry_interval => "1s",
|
||||
enable => true})).
|
||||
|
||||
-define(INSTANCE_EXAMPLE_3, maps:merge(?EXAMPLE_3, #{id => <<"jwt">>,
|
||||
|
@ -1259,9 +1259,9 @@ definitions() ->
|
|||
example => <<"SELECT password_hash FROM mqtt_user WHERE username = ${mqtt-username}">>
|
||||
},
|
||||
query_timeout => #{
|
||||
type => integer,
|
||||
description => <<"Query timeout, Unit: Milliseconds">>,
|
||||
default => 5000
|
||||
type => string,
|
||||
description => <<"Query timeout">>,
|
||||
default => "5s"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1528,16 +1528,16 @@ definitions() ->
|
|||
type => object
|
||||
},
|
||||
connect_timeout => #{
|
||||
type => integer,
|
||||
default => 5000
|
||||
type => string,
|
||||
default => <<"5s">>
|
||||
},
|
||||
max_retries => #{
|
||||
type => integer,
|
||||
default => 5
|
||||
},
|
||||
retry_interval => #{
|
||||
type => integer,
|
||||
default => 1000
|
||||
type => string,
|
||||
default => <<"1s">>
|
||||
},
|
||||
request_timout => #{
|
||||
type => integer,
|
||||
|
|
|
@ -100,8 +100,8 @@ body(type) -> map();
|
|||
body(validator) -> [fun check_body/1];
|
||||
body(_) -> undefined.
|
||||
|
||||
request_timeout(type) -> non_neg_integer();
|
||||
request_timeout(default) -> 5000;
|
||||
request_timeout(type) -> emqx_schema:duration_ms();
|
||||
request_timeout(default) -> "5s";
|
||||
request_timeout(_) -> undefined.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -65,8 +65,8 @@ salt_position(_) -> undefined.
|
|||
query(type) -> string();
|
||||
query(_) -> undefined.
|
||||
|
||||
query_timeout(type) -> integer();
|
||||
query_timeout(default) -> 5000;
|
||||
query_timeout(type) -> emqx_schema:duration_ms();
|
||||
query_timeout(default) -> "5s";
|
||||
query_timeout(_) -> undefined.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -79,9 +79,9 @@ definitions() ->
|
|||
},
|
||||
headers => #{type => object},
|
||||
body => #{type => object},
|
||||
connect_timeout => #{type => integer},
|
||||
connect_timeout => #{type => string},
|
||||
max_retries => #{type => integer},
|
||||
retry_interval => #{type => integer},
|
||||
retry_interval => #{type => string},
|
||||
pool_type => #{
|
||||
type => string,
|
||||
enum => [<<"random">>, <<"hash">>],
|
||||
|
@ -133,8 +133,8 @@ definitions() ->
|
|||
properties => #{
|
||||
pool_size => #{type => integer},
|
||||
max_overflow => #{type => integer},
|
||||
overflow_ttl => #{type => integer},
|
||||
overflow_check_period => #{type => integer},
|
||||
overflow_ttl => #{type => string},
|
||||
overflow_check_period => #{type => string},
|
||||
local_threshold_ms => #{type => integer},
|
||||
connect_timeout_ms => #{type => integer},
|
||||
socket_timeout_ms => #{type => integer},
|
||||
|
@ -191,8 +191,8 @@ definitions() ->
|
|||
properties => #{
|
||||
pool_size => #{type => integer},
|
||||
max_overflow => #{type => integer},
|
||||
overflow_ttl => #{type => integer},
|
||||
overflow_check_period => #{type => integer},
|
||||
overflow_ttl => #{type => string},
|
||||
overflow_check_period => #{type => string},
|
||||
local_threshold_ms => #{type => integer},
|
||||
connect_timeout_ms => #{type => integer},
|
||||
socket_timeout_ms => #{type => integer},
|
||||
|
@ -247,8 +247,8 @@ definitions() ->
|
|||
properties => #{
|
||||
pool_size => #{type => integer},
|
||||
max_overflow => #{type => integer},
|
||||
overflow_ttl => #{type => integer},
|
||||
overflow_check_period => #{type => integer},
|
||||
overflow_ttl => #{type => string},
|
||||
overflow_check_period => #{type => string},
|
||||
local_threshold_ms => #{type => integer},
|
||||
connect_timeout_ms => #{type => integer},
|
||||
socket_timeout_ms => #{type => integer},
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
, fields/1
|
||||
]).
|
||||
|
||||
-import(emqx_schema, [mk_duration/2]).
|
||||
|
||||
namespace() -> authz.
|
||||
|
||||
%% @doc authorization schema is not exported
|
||||
|
@ -77,7 +79,7 @@ fields(http_get) ->
|
|||
end
|
||||
}
|
||||
}
|
||||
, {request_timeout, #{type => timeout(), default => 30000 }}
|
||||
, {request_timeout, mk_duration("request timeout", #{default => "30s"})}
|
||||
] ++ proplists:delete(base_url, emqx_connector_http:fields(config));
|
||||
fields(http_post) ->
|
||||
[ {type, #{type => http}}
|
||||
|
@ -107,7 +109,7 @@ fields(http_post) ->
|
|||
end
|
||||
}
|
||||
}
|
||||
, {request_timeout, #{type => timeout(), default => 30000 }}
|
||||
, {request_timeout, mk_duration("request timeout", #{default => "30s"})}
|
||||
, {body, #{type => map(),
|
||||
nullable => true
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<<"url">> => <<"https://fake.com:443/">>,
|
||||
<<"headers">> => #{},
|
||||
<<"method">> => <<"get">>,
|
||||
<<"request_timeout">> => 5000
|
||||
<<"request_timeout">> => <<"5s">>
|
||||
}).
|
||||
-define(SOURCE2, #{<<"type">> => <<"mongodb">>,
|
||||
<<"enable">> => true,
|
||||
|
|
|
@ -71,16 +71,16 @@ base_url(validator) -> fun(#{query := _Query}) ->
|
|||
end;
|
||||
base_url(_) -> undefined.
|
||||
|
||||
connect_timeout(type) -> connect_timeout();
|
||||
connect_timeout(default) -> 5000;
|
||||
connect_timeout(type) -> emqx_schema:duration_ms();
|
||||
connect_timeout(default) -> "5s";
|
||||
connect_timeout(_) -> undefined.
|
||||
|
||||
max_retries(type) -> non_neg_integer();
|
||||
max_retries(default) -> 5;
|
||||
max_retries(_) -> undefined.
|
||||
|
||||
retry_interval(type) -> non_neg_integer();
|
||||
retry_interval(default) -> 1000;
|
||||
retry_interval(type) -> emqx_schema:duration_ms();
|
||||
retry_interval(default) -> "1s";
|
||||
retry_interval(_) -> undefined.
|
||||
|
||||
pool_type(type) -> pool_type();
|
||||
|
|
|
@ -23,19 +23,21 @@
|
|||
-export([ roots/0
|
||||
, fields/1]).
|
||||
|
||||
-import(emqx_schema, [mk_duration/2]).
|
||||
|
||||
roots() ->
|
||||
[{config, #{type => hoconsc:ref(?MODULE, "config")}}].
|
||||
|
||||
fields("config") ->
|
||||
[ {server, hoconsc:mk(emqx_schema:ip_port(), #{default => "127.0.0.1:1883"})}
|
||||
, {reconnect_interval, hoconsc:mk(emqx_schema:duration_ms(), #{default => "30s"})}
|
||||
, {reconnect_interval, mk_duration("reconnect interval", #{default => "30s"})}
|
||||
, {proto_ver, fun proto_ver/1}
|
||||
, {bridge_mode, hoconsc:mk(boolean(), #{default => true})}
|
||||
, {username, hoconsc:mk(string())}
|
||||
, {password, hoconsc:mk(string())}
|
||||
, {clean_start, hoconsc:mk(boolean(), #{default => true})}
|
||||
, {keepalive, hoconsc:mk(emqx_schema:duration_s(), #{default => "300s"})}
|
||||
, {retry_interval, hoconsc:mk(emqx_schema:duration_ms(), #{default => "30s"})}
|
||||
, {keepalive, mk_duration("keepalive", #{default => "300s"})}
|
||||
, {retry_interval, mk_duration("retry interval", #{default => "30s"})}
|
||||
, {max_inflight, hoconsc:mk(integer(), #{default => 32})}
|
||||
, {replayq, hoconsc:mk(hoconsc:ref(?MODULE, "replayq"))}
|
||||
, {ingress_channels, hoconsc:mk(hoconsc:map(id, hoconsc:ref(?MODULE, "ingress_channels")), #{default => []})}
|
||||
|
|
Loading…
Reference in New Issue