refactor: delete unused connector field 'base_url'

This commit is contained in:
Zaiming (Stone) Shi 2023-04-21 16:15:45 +02:00
parent b3e35dac1c
commit 7566c25199
9 changed files with 10 additions and 60 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_authn, [ {application, emqx_authn, [
{description, "EMQX Authentication"}, {description, "EMQX Authentication"},
{vsn, "0.1.18"}, {vsn, "0.1.19"},
{modules, []}, {modules, []},
{registered, [emqx_authn_sup, emqx_authn_registry]}, {registered, [emqx_authn_sup, emqx_authn_registry]},
{applications, [kernel, stdlib, emqx_resource, emqx_connector, ehttpc, epgsql, mysql, jose]}, {applications, [kernel, stdlib, emqx_resource, emqx_connector, ehttpc, epgsql, mysql, jose]},

View File

@ -100,7 +100,6 @@ common_fields() ->
maps:to_list( maps:to_list(
maps:without( maps:without(
[ [
base_url,
pool_type pool_type
], ],
maps:from_list(emqx_connector_http:fields(config)) maps:from_list(emqx_connector_http:fields(config))

View File

@ -114,7 +114,6 @@ authz_http_common_fields() ->
maps:to_list( maps:to_list(
maps:without( maps:without(
[ [
base_url,
pool_type pool_type
], ],
maps:from_list(emqx_connector_http:fields(config)) maps:from_list(emqx_connector_http:fields(config))

View File

@ -230,7 +230,6 @@ http_common_fields() ->
maps:to_list( maps:to_list(
maps:without( maps:without(
[ [
base_url,
pool_type pool_type
], ],
maps:from_list(connector_fields(http)) maps:from_list(connector_fields(http))

View File

@ -68,7 +68,7 @@ basic_config() ->
)} )}
] ++ webhook_creation_opts() ++ ] ++ webhook_creation_opts() ++
proplists:delete( proplists:delete(
max_retries, proplists:delete(base_url, emqx_connector_http:fields(config)) max_retries, emqx_connector_http:fields(config)
). ).
request_config() -> request_config() ->

View File

@ -35,19 +35,14 @@
reply_delegator/2 reply_delegator/2
]). ]).
-type url() :: emqx_http_lib:uri_map().
-reflect_type([url/0]).
-typerefl_from_string({url/0, emqx_http_lib, uri_parse}).
-export([ -export([
roots/0, roots/0,
fields/1, fields/1,
desc/1, desc/1,
validations/0,
namespace/0 namespace/0
]). ]).
-export([check_ssl_opts/2, validate_method/1, join_paths/2]). -export([validate_method/1, join_paths/2]).
-type connect_timeout() :: emqx_schema:duration() | infinity. -type connect_timeout() :: emqx_schema:duration() | infinity.
-type pool_type() :: random | hash. -type pool_type() :: random | hash.
@ -69,20 +64,6 @@ roots() ->
fields(config) -> fields(config) ->
[ [
{base_url,
sc(
url(),
#{
required => true,
validator => fun
(#{query := _Query}) ->
{error, "There must be no query in the base_url"};
(_) ->
ok
end,
desc => ?DESC("base_url")
}
)},
{connect_timeout, {connect_timeout,
sc( sc(
emqx_schema:duration_ms(), emqx_schema:duration_ms(),
@ -171,9 +152,6 @@ desc("request") ->
desc(_) -> desc(_) ->
undefined. undefined.
validations() ->
[{check_ssl_opts, fun check_ssl_opts/1}].
validate_method(M) when M =:= <<"post">>; M =:= <<"put">>; M =:= <<"get">>; M =:= <<"delete">> -> validate_method(M) when M =:= <<"post">>; M =:= <<"put">>; M =:= <<"get">>; M =:= <<"delete">> ->
ok; ok;
validate_method(M) -> validate_method(M) ->
@ -578,18 +556,6 @@ make_method(M) when M == <<"PUT">>; M == <<"put">> -> put;
make_method(M) when M == <<"GET">>; M == <<"get">> -> get; make_method(M) when M == <<"GET">>; M == <<"get">> -> get;
make_method(M) when M == <<"DELETE">>; M == <<"delete">> -> delete. make_method(M) when M == <<"DELETE">>; M == <<"delete">> -> delete.
check_ssl_opts(Conf) ->
check_ssl_opts("base_url", Conf).
check_ssl_opts(URLFrom, Conf) ->
#{scheme := Scheme} = hocon_maps:get(URLFrom, Conf),
SSL = hocon_maps:get("ssl", Conf),
case {Scheme, maps:get(enable, SSL, false)} of
{http, false} -> true;
{https, true} -> true;
{_, _} -> false
end.
formalize_request(Method, BasePath, {Path, Headers, _Body}) when formalize_request(Method, BasePath, {Path, Headers, _Body}) when
Method =:= get; Method =:= delete Method =:= get; Method =:= delete
-> ->

View File

@ -29,6 +29,10 @@
-compile(nowarn_export_all). -compile(nowarn_export_all).
-compile(export_all). -compile(export_all).
-type url() :: emqx_http_lib:uri_map().
-reflect_type([url/0]).
-typerefl_from_string({url/0, emqx_http_lib, uri_parse}).
all() -> emqx_common_test_helpers:all(?MODULE). all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
@ -314,7 +318,7 @@ t_sub_fields(_Config) ->
ok. ok.
t_complicated_type(_Config) -> t_complicated_type(_Config) ->
Path = "/ref/complicated_type", Path = "/ref/complex_type",
Object = #{ Object = #{
<<"content">> => #{ <<"content">> => #{
<<"application/json">> => <<"application/json">> =>
@ -633,14 +637,14 @@ schema("/error") ->
} }
} }
}; };
schema("/ref/complicated_type") -> schema("/ref/complex_type") ->
#{ #{
operationId => test, operationId => test,
post => #{ post => #{
responses => #{ responses => #{
200 => [ 200 => [
{no_neg_integer, hoconsc:mk(non_neg_integer(), #{})}, {no_neg_integer, hoconsc:mk(non_neg_integer(), #{})},
{url, hoconsc:mk(emqx_connector_http:url(), #{})}, {url, hoconsc:mk(url(), #{})},
{server, hoconsc:mk(emqx_schema:ip_port(), #{})}, {server, hoconsc:mk(emqx_schema:ip_port(), #{})},
{connect_timeout, hoconsc:mk(emqx_connector_http:connect_timeout(), #{})}, {connect_timeout, hoconsc:mk(emqx_connector_http:connect_timeout(), #{})},
{pool_type, hoconsc:mk(emqx_connector_http:pool_type(), #{})}, {pool_type, hoconsc:mk(emqx_connector_http:pool_type(), #{})},

View File

@ -1,14 +1,5 @@
emqx_connector_http { emqx_connector_http {
base_url.desc:
"""The base URL is the URL includes only the scheme, host and port.<br/>
When send an HTTP request, the real URL to be used is the concatenation of the base URL and the
path parameter<br/>
For example: `http://localhost:9901/`"""
base_url.label:
"""Base Url"""
body.desc: body.desc:
"""HTTP request body.""" """HTTP request body."""

View File

@ -1,13 +1,5 @@
emqx_connector_http { emqx_connector_http {
base_url.desc:
"""base URL 只包含host和port。<br/>
发送HTTP请求时真实的URL是由base URL 和 path parameter连接而成。<br/>
示例:`http://localhost:9901/`"""
base_url.label:
"""Base Url"""
body.desc: body.desc:
"""HTTP请求报文主体。""" """HTTP请求报文主体。"""