|
@@ -38,15 +38,7 @@
|
|
|
|
|
|
|
|
-define(RESOURCE_TYPE_WEBHOOK, 'web_hook').
|
|
-define(RESOURCE_TYPE_WEBHOOK, 'web_hook').
|
|
|
-define(RESOURCE_CONFIG_SPEC, #{
|
|
-define(RESOURCE_CONFIG_SPEC, #{
|
|
|
- method => #{order => 1,
|
|
|
|
|
- type => string,
|
|
|
|
|
- enum => [<<"PUT">>,<<"POST">>],
|
|
|
|
|
- default => <<"POST">>,
|
|
|
|
|
- title => #{en => <<"Request Method">>,
|
|
|
|
|
- zh => <<"请求方法"/utf8>>},
|
|
|
|
|
- description => #{en => <<"Request Method">>,
|
|
|
|
|
- zh => <<"请求方法"/utf8>>}},
|
|
|
|
|
- url => #{order => 2,
|
|
|
|
|
|
|
+ url => #{order => 1,
|
|
|
type => string,
|
|
type => string,
|
|
|
format => url,
|
|
format => url,
|
|
|
required => true,
|
|
required => true,
|
|
@@ -54,57 +46,49 @@
|
|
|
zh => <<"请求 URL"/utf8>>},
|
|
zh => <<"请求 URL"/utf8>>},
|
|
|
description => #{en => <<"The URL of the server that will receive the Webhook requests.">>,
|
|
description => #{en => <<"The URL of the server that will receive the Webhook requests.">>,
|
|
|
zh => <<"用于接收 Webhook 请求的服务器的 URL。"/utf8>>}},
|
|
zh => <<"用于接收 Webhook 请求的服务器的 URL。"/utf8>>}},
|
|
|
- headers => #{order => 3,
|
|
|
|
|
- type => object,
|
|
|
|
|
- schema => #{},
|
|
|
|
|
- default => #{},
|
|
|
|
|
- title => #{en => <<"Request Header">>,
|
|
|
|
|
- zh => <<"请求头"/utf8>>},
|
|
|
|
|
- description => #{en => <<"Request Header">>,
|
|
|
|
|
- zh => <<"请求头"/utf8>>}},
|
|
|
|
|
- connect_timeout => #{order => 4,
|
|
|
|
|
|
|
+ connect_timeout => #{order => 2,
|
|
|
type => string,
|
|
type => string,
|
|
|
default => <<"5s">>,
|
|
default => <<"5s">>,
|
|
|
title => #{en => <<"Connect Timeout">>,
|
|
title => #{en => <<"Connect Timeout">>,
|
|
|
zh => <<"连接超时时间"/utf8>>},
|
|
zh => <<"连接超时时间"/utf8>>},
|
|
|
description => #{en => <<"Connect Timeout In Seconds">>,
|
|
description => #{en => <<"Connect Timeout In Seconds">>,
|
|
|
zh => <<"连接超时时间"/utf8>>}},
|
|
zh => <<"连接超时时间"/utf8>>}},
|
|
|
- request_timeout => #{order => 5,
|
|
|
|
|
|
|
+ request_timeout => #{order => 3,
|
|
|
type => string,
|
|
type => string,
|
|
|
default => <<"5s">>,
|
|
default => <<"5s">>,
|
|
|
title => #{en => <<"Request Timeout">>,
|
|
title => #{en => <<"Request Timeout">>,
|
|
|
zh => <<"请求超时时间时间"/utf8>>},
|
|
zh => <<"请求超时时间时间"/utf8>>},
|
|
|
description => #{en => <<"Request Timeout In Seconds">>,
|
|
description => #{en => <<"Request Timeout In Seconds">>,
|
|
|
zh => <<"请求超时时间"/utf8>>}},
|
|
zh => <<"请求超时时间"/utf8>>}},
|
|
|
- pool_size => #{order => 6,
|
|
|
|
|
|
|
+ pool_size => #{order => 4,
|
|
|
type => number,
|
|
type => number,
|
|
|
default => 8,
|
|
default => 8,
|
|
|
title => #{en => <<"Pool Size">>, zh => <<"连接池大小"/utf8>>},
|
|
title => #{en => <<"Pool Size">>, zh => <<"连接池大小"/utf8>>},
|
|
|
description => #{en => <<"Connection Pool">>,
|
|
description => #{en => <<"Connection Pool">>,
|
|
|
zh => <<"连接池大小"/utf8>>}
|
|
zh => <<"连接池大小"/utf8>>}
|
|
|
},
|
|
},
|
|
|
- cacertfile => #{order => 7,
|
|
|
|
|
|
|
+ cacertfile => #{order => 5,
|
|
|
type => file,
|
|
type => file,
|
|
|
default => <<"">>,
|
|
default => <<"">>,
|
|
|
title => #{en => <<"CA Certificate File">>,
|
|
title => #{en => <<"CA Certificate File">>,
|
|
|
zh => <<"CA 证书文件"/utf8>>},
|
|
zh => <<"CA 证书文件"/utf8>>},
|
|
|
description => #{en => <<"CA Certificate file">>,
|
|
description => #{en => <<"CA Certificate file">>,
|
|
|
zh => <<"CA 证书文件"/utf8>>}},
|
|
zh => <<"CA 证书文件"/utf8>>}},
|
|
|
- keyfile => #{order => 8,
|
|
|
|
|
|
|
+ keyfile => #{order => 6,
|
|
|
type => file,
|
|
type => file,
|
|
|
default => <<"">>,
|
|
default => <<"">>,
|
|
|
title =>#{en => <<"SSL Key">>,
|
|
title =>#{en => <<"SSL Key">>,
|
|
|
zh => <<"SSL Key"/utf8>>},
|
|
zh => <<"SSL Key"/utf8>>},
|
|
|
description => #{en => <<"Your ssl keyfile">>,
|
|
description => #{en => <<"Your ssl keyfile">>,
|
|
|
zh => <<"SSL 私钥"/utf8>>}},
|
|
zh => <<"SSL 私钥"/utf8>>}},
|
|
|
- certfile => #{order => 9,
|
|
|
|
|
|
|
+ certfile => #{order => 7,
|
|
|
type => file,
|
|
type => file,
|
|
|
default => <<"">>,
|
|
default => <<"">>,
|
|
|
title =>#{en => <<"SSL Cert">>,
|
|
title =>#{en => <<"SSL Cert">>,
|
|
|
zh => <<"SSL Cert"/utf8>>},
|
|
zh => <<"SSL Cert"/utf8>>},
|
|
|
description => #{en => <<"Your ssl certfile">>,
|
|
description => #{en => <<"Your ssl certfile">>,
|
|
|
zh => <<"SSL 证书"/utf8>>}},
|
|
zh => <<"SSL 证书"/utf8>>}},
|
|
|
- verify => #{order => 10,
|
|
|
|
|
|
|
+ verify => #{order => 8,
|
|
|
type => boolean,
|
|
type => boolean,
|
|
|
default => false,
|
|
default => false,
|
|
|
title =>#{en => <<"Verify Server Certfile">>,
|
|
title =>#{en => <<"Verify Server Certfile">>,
|
|
@@ -156,7 +140,7 @@
|
|
|
description => #{en => <<"HTTP headers.">>,
|
|
description => #{en => <<"HTTP headers.">>,
|
|
|
zh => <<"HTTP headers。"/utf8>>}},
|
|
zh => <<"HTTP headers。"/utf8>>}},
|
|
|
body => #{
|
|
body => #{
|
|
|
- order => 5,
|
|
|
|
|
|
|
+ order => 4,
|
|
|
type => string,
|
|
type => string,
|
|
|
input => textarea,
|
|
input => textarea,
|
|
|
required => false,
|
|
required => false,
|
|
@@ -350,24 +334,27 @@ pool_opts(Params = #{<<"url">> := URL}, ResId) ->
|
|
|
PoolSize = maps:get(<<"pool_size">>, Params, 32),
|
|
PoolSize = maps:get(<<"pool_size">>, Params, 32),
|
|
|
ConnectTimeout = cuttlefish_duration:parse(str(maps:get(<<"connect_timeout">>, Params, <<"5s">>))),
|
|
ConnectTimeout = cuttlefish_duration:parse(str(maps:get(<<"connect_timeout">>, Params, <<"5s">>))),
|
|
|
{Inet, Host} = parse_host(Host0),
|
|
{Inet, Host} = parse_host(Host0),
|
|
|
|
|
+ SslOpts0 = maybe_ssl(Params, ResId, add_default_scheme(URL)),
|
|
|
|
|
+ TranOpts = lists:keyfind(transport_opts, 1, SslOpts0),
|
|
|
|
|
+ SslOpts = lists:keyreplace(transport_opts, 1,
|
|
|
|
|
+ {transport_opts, [Inet | TranOpts]}, SslOpts0),
|
|
|
[{host, Host},
|
|
[{host, Host},
|
|
|
{port, Port},
|
|
{port, Port},
|
|
|
{pool_size, PoolSize},
|
|
{pool_size, PoolSize},
|
|
|
{pool_type, hash},
|
|
{pool_type, hash},
|
|
|
{connect_timeout, ConnectTimeout},
|
|
{connect_timeout, ConnectTimeout},
|
|
|
{retry, 5},
|
|
{retry, 5},
|
|
|
- {retry_timeout, 1000}
|
|
|
|
|
- | maybe_ssl(Params, ResId, add_default_scheme(URL), Inet)].
|
|
|
|
|
|
|
+ {retry_timeout, 1000} | SslOpts].
|
|
|
|
|
|
|
|
pool_name(ResId) ->
|
|
pool_name(ResId) ->
|
|
|
list_to_atom("webhook:" ++ str(ResId)).
|
|
list_to_atom("webhook:" ++ str(ResId)).
|
|
|
|
|
|
|
|
-maybe_ssl(Config, ResId, <<"https://", _URL/binary>>, Inet) ->
|
|
|
|
|
|
|
+maybe_ssl(Config, ResId, <<"https://", _URL/binary>>) ->
|
|
|
[{transport, ssl},
|
|
[{transport, ssl},
|
|
|
- {transport_opts, [Inet | get_ssl_opts(Config, ResId)]}
|
|
|
|
|
|
|
+ {transport_opts, get_ssl_opts(Config, ResId)}
|
|
|
];
|
|
];
|
|
|
-maybe_ssl(_Config, _ResId, _URL, Inet) ->
|
|
|
|
|
- [{transport_opts, [Inet]}].
|
|
|
|
|
|
|
+maybe_ssl(_Config, _ResId, _URL) ->
|
|
|
|
|
+ [{transport_opts, []}].
|
|
|
|
|
|
|
|
get_ssl_opts(Opts, ResId) ->
|
|
get_ssl_opts(Opts, ResId) ->
|
|
|
Dir = filename:join([emqx:get_env(data_dir), "rule", ResId]),
|
|
Dir = filename:join([emqx:get_env(data_dir), "rule", ResId]),
|