Skip to content

Commit

Permalink
Merge pull request #3516 from esl/s2s_config_map
Browse files Browse the repository at this point in the history
  • Loading branch information
gustawlippa authored Jan 27, 2022
2 parents 18eebd6 + 8369f6f commit a3b5ce9
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 188 deletions.
2 changes: 1 addition & 1 deletion doc/configuration/s2s.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Specifies the order of IP address families to try when establishing an outgoing
* **Default:** `10_000`
* **Example:** `outgoing.connection_timeout = 5000`

Timeout (in seconds) for establishing an outgoing S2S connection.
Timeout (in milliseconds) for establishing an outgoing S2S connection.

### `s2s.dns.timeout`
* **Scope:** local
Expand Down
108 changes: 61 additions & 47 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
process_riak_credentials/1,
process_iqdisc/1,
process_acl_condition/1,
process_s2s_address_family/1,
process_s2s_host_policy/1,
process_s2s_address/1,
process_domain_cert/1]).
Expand Down Expand Up @@ -149,7 +148,7 @@ host_config() ->
<<"modules">> => modules(),
<<"acl">> => acl(),
<<"access">> => access(),
<<"s2s">> => s2s()
<<"s2s">> => host_s2s()
},
wrap = none
}.
Expand Down Expand Up @@ -873,66 +872,86 @@ access_rule_item() ->
format_items = map
}.

%% path: (host_config[].)s2s
%% path: s2s
s2s() ->
#section{
items = #{<<"dns">> => s2s_dns(),
<<"outgoing">> => s2s_outgoing(),
<<"use_starttls">> => #option{type = atom,
validate = {enum, [false, optional, required,
required_trusted]},
wrap = {global_config, s2s_use_starttls}},
<<"certfile">> => #option{type = string,
validate = non_empty,
wrap = {global_config, s2s_certfile}},
<<"default_policy">> => #option{type = atom,
validate = {enum, [allow, deny]},
wrap = {host_config, s2s_default_policy}},
<<"host_policy">> => #list{items = s2s_host_policy(),
format_items = map,
wrap = {host_config, s2s_host_policy}},
<<"address">> => #list{items = s2s_address(),
format_items = map,
wrap = {global_config, s2s_address}},
<<"ciphers">> => #option{type = string,
wrap = {global_config, s2s_ciphers}},
<<"shared">> => #option{type = binary,
validate = non_empty,
wrap = {host_config, s2s_shared}},
<<"max_retry_delay">> => #option{type = integer,
validate = positive,
wrap = {host_config, s2s_max_retry_delay}}
},
items = maps:merge(s2s_global_items(), s2s_host_items()),
defaults = #{<<"address">> => #{}},
include = always,
wrap = none
}.

%% path: host_config[].s2s
host_s2s() ->
#section{
items = s2s_host_items(),
wrap = none
}.

s2s_host_items() ->
#{<<"default_policy">> => #option{type = atom,
validate = {enum, [allow, deny]},
wrap = {host_config, s2s_default_policy}},
<<"host_policy">> => #list{items = s2s_host_policy(),
format_items = map,
wrap = {host_config, s2s_host_policy}},
<<"shared">> => #option{type = binary,
validate = non_empty,
wrap = {host_config, s2s_shared}},
<<"max_retry_delay">> => #option{type = integer,
validate = positive,
wrap = {host_config, s2s_max_retry_delay}}
}.

s2s_global_items() ->
#{<<"dns">> => s2s_dns(),
<<"outgoing">> => s2s_outgoing(),
<<"use_starttls">> => #option{type = atom,
validate = {enum, [false, optional, required,
required_trusted]},
wrap = {global_config, s2s_use_starttls}},
<<"certfile">> => #option{type = string,
validate = non_empty,
wrap = {global_config, s2s_certfile}},
<<"address">> => #list{items = s2s_address(),
format_items = map,
wrap = {global_config, s2s_address}},
<<"ciphers">> => #option{type = string,
wrap = {global_config, s2s_ciphers}}
}.

%% path: (host_config[].)s2s.dns
s2s_dns() ->
#section{
items = #{<<"timeout">> => #option{type = integer,
validate = positive},
<<"retries">> => #option{type = integer,
validate = positive}},
wrap = {global_config, s2s_dns_options}
format_items = map,
include = always,
defaults = #{<<"timeout">> => 10,
<<"retries">> => 2},
wrap = {global_config, s2s_dns}
}.

%% path: (host_config[].)s2s.outgoing
s2s_outgoing() ->
#section{
items = #{<<"port">> => #option{type = integer,
validate = port,
wrap = {global_config, outgoing_s2s_port}},
validate = port},
<<"ip_versions">> =>
#list{items = #option{type = integer,
validate = {enum, [4, 6]},
process = fun ?MODULE:process_s2s_address_family/1},
validate = unique_non_empty,
wrap = {global_config, outgoing_s2s_families}},
validate = {enum, [4, 6]}},
validate = unique_non_empty},
<<"connection_timeout">> => #option{type = int_or_infinity,
validate = positive,
wrap = {global_config, outgoing_s2s_timeout}}
validate = positive}
},
wrap = none
format_items = map,
include = always,
defaults = #{<<"port">> => 5269,
<<"ip_versions">> => [4, 6],
<<"connection_timeout">> => 10000},
wrap = {global_config, s2s_outgoing}
}.

%% path: (host_config[].)s2s.host_policy[]
Expand Down Expand Up @@ -1249,16 +1268,11 @@ process_acl_condition(Value) ->
Node -> Node
end.

process_s2s_address_family(4) -> ipv4;
process_s2s_address_family(6) -> ipv6.

process_s2s_host_policy(#{host := S2SHost, policy := Policy}) ->
{S2SHost, Policy}.

process_s2s_address(#{host := S2SHost, ip_address := IPAddr, port := Port}) ->
{S2SHost, {IPAddr, Port}};
process_s2s_address(#{host := S2SHost, ip_address := IPAddr}) ->
{S2SHost, IPAddr}.
process_s2s_address(M) ->
maps:take(host, M).

process_domain_cert(#{domain := Domain, certfile := Certfile}) ->
{Domain, Certfile}.
Loading

0 comments on commit a3b5ce9

Please sign in to comment.