fix: add push_gateway_server's validator
This commit is contained in:
parent
42dfaf3ef2
commit
53488b4377
|
@ -26,7 +26,8 @@
|
||||||
fields/1,
|
fields/1,
|
||||||
desc/1,
|
desc/1,
|
||||||
translation/1,
|
translation/1,
|
||||||
convert_headers/1
|
convert_headers/1,
|
||||||
|
validate_push_gateway_server/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
namespace() -> "prometheus".
|
namespace() -> "prometheus".
|
||||||
|
@ -41,6 +42,7 @@ fields("prometheus") ->
|
||||||
#{
|
#{
|
||||||
default => "http://127.0.0.1:9091",
|
default => "http://127.0.0.1:9091",
|
||||||
required => true,
|
required => true,
|
||||||
|
validator => fun ?MODULE:validate_push_gateway_server/1,
|
||||||
desc => ?DESC(push_gateway_server)
|
desc => ?DESC(push_gateway_server)
|
||||||
}
|
}
|
||||||
)},
|
)},
|
||||||
|
@ -158,6 +160,12 @@ convert_headers(Headers) when is_map(Headers) ->
|
||||||
convert_headers(Headers) when is_list(Headers) ->
|
convert_headers(Headers) when is_list(Headers) ->
|
||||||
Headers.
|
Headers.
|
||||||
|
|
||||||
|
validate_push_gateway_server(Url) ->
|
||||||
|
case uri_string:parse(Url) of
|
||||||
|
#{scheme := S} when S =:= "https" orelse S =:= "http" -> ok;
|
||||||
|
_ -> {error, "Invalid url"}
|
||||||
|
end.
|
||||||
|
|
||||||
%% for CI test, CI don't load the whole emqx_conf_schema.
|
%% for CI test, CI don't load the whole emqx_conf_schema.
|
||||||
translation(Name) ->
|
translation(Name) ->
|
||||||
emqx_conf_schema:translation(Name).
|
emqx_conf_schema:translation(Name).
|
||||||
|
|
|
@ -92,6 +92,12 @@ t_prometheus_api(_) ->
|
||||||
NewConf1 = Conf#{<<"enable">> => (not Enable)},
|
NewConf1 = Conf#{<<"enable">> => (not Enable)},
|
||||||
{ok, _Response3} = emqx_mgmt_api_test_util:request_api(put, Path, "", Auth, NewConf1),
|
{ok, _Response3} = emqx_mgmt_api_test_util:request_api(put, Path, "", Auth, NewConf1),
|
||||||
?assertEqual((not Enable), undefined =/= erlang:whereis(emqx_prometheus)),
|
?assertEqual((not Enable), undefined =/= erlang:whereis(emqx_prometheus)),
|
||||||
|
|
||||||
|
ConfWithoutScheme = Conf#{<<"push_gateway_server">> => "127.0.0.1:8081"},
|
||||||
|
?assertMatch(
|
||||||
|
{error, {"HTTP/1.1", 400, _}},
|
||||||
|
emqx_mgmt_api_test_util:request_api(put, Path, "", Auth, ConfWithoutScheme)
|
||||||
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_stats_api(_) ->
|
t_stats_api(_) ->
|
||||||
|
|
Loading…
Reference in New Issue