Skip to content

Commit

Permalink
Add hook for file:consult/1 for TLS replication
Browse files Browse the repository at this point in the history
file:consult/1 is OK to parse a configuration file with some
TLS settings, but it does not support parsing "complex"
settings like a function to validate the hostname.

This commit introduces a hook so that the calling application
can provide a custom function instead of the default file:consult/1
and this way easily support parsing the app settings.

Fixes #78
  • Loading branch information
acogoluegnes committed Jun 7, 2022
1 parent 43edcd2 commit 123d629
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/osiris_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
lists_find/2,
hostname_from_node/0,
get_replication_configuration_from_tls_dist/0,
get_replication_configuration_from_tls_dist/1,
get_replication_configuration_from_tls_dist/2,
partition_parallel/3
]).

%% For testing
-export([inet_tls_enabled/1,
replication_over_tls_configuration/2]).
replication_over_tls_configuration/3]).

-define(BASE64_URI_CHARS,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01"
Expand Down Expand Up @@ -79,7 +79,8 @@ hostname_from_node() ->
end.

get_replication_configuration_from_tls_dist() ->
get_replication_configuration_from_tls_dist(fun (debug, Fmt, Args) ->
get_replication_configuration_from_tls_dist(fun file:consult/1,
fun (debug, Fmt, Args) ->
?DEBUG(Fmt, Args);
(warn, Fmt, Args) ->
?WARN(Fmt, Args);
Expand All @@ -89,21 +90,21 @@ get_replication_configuration_from_tls_dist() ->
?INFO(Fmt, Args)
end).

get_replication_configuration_from_tls_dist(LogFun) ->
get_replication_configuration_from_tls_dist(FileConsultFun, LogFun) ->
InitArguments = init:get_arguments(),
case inet_tls_enabled(InitArguments) of
true ->
LogFun(debug,
"Inter-node TLS enabled, "
++ "configuring stream replication over TLS",
[]),
replication_over_tls_configuration(InitArguments, LogFun);
replication_over_tls_configuration(InitArguments, FileConsultFun, LogFun);
false ->
LogFun(debug, "Inter-node TLS not enabled", []),
[]
end.

replication_over_tls_configuration(InitArgs, LogFun) ->
replication_over_tls_configuration(InitArgs, FileConsultFun, LogFun) ->
case proplists:lookup(ssl_dist_optfile, InitArgs) of
none ->
LogFun(debug,
Expand All @@ -121,7 +122,7 @@ replication_over_tls_configuration(InitArgs, LogFun) ->
"Using ssl_dist_optfile to configure "
++ "stream replication over TLS",
[]),
case file:consult(OptFile) of
case FileConsultFun(OptFile) of
{ok, [TlsDist]} ->
SslServerOptions = proplists:get_value(server, TlsDist, []),
SslClientOptions = proplists:get_value(client, TlsDist, []),
Expand Down
1 change: 1 addition & 0 deletions test/osiris_util_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ replication_over_tls_configuration_with_opt(_) ->

replication_over_tls_configuration(Args) ->
osiris_util:replication_over_tls_configuration(Args,
fun file:consult/1,
fun tls_replication_log/3).

tls_replication_log(_Level, Fmt, Args) ->
Expand Down

0 comments on commit 123d629

Please sign in to comment.