refactor(ssl): Move data dir for ssl certs upload down to lib module

This commit is contained in:
Zaiming Shi 2021-03-22 16:33:57 +01:00 committed by Zaiming (Stone) Shi
parent 8a41a4ee00
commit 71559dd001
3 changed files with 13 additions and 5 deletions

View File

@ -567,8 +567,7 @@ options(Options, PoolName, ResId) ->
maybe_ssl(_Options, false, _ResId) ->
[];
maybe_ssl(Options, true, ResId) ->
Dir = filename:join([emqx:get_env(data_dir), "rules", ResId]),
[{ssl, true}, {ssl_opts, emqx_plugin_libs_ssl:save_files_return_opts(Options, Dir)}].
[{ssl, true}, {ssl_opts, emqx_plugin_libs_ssl:save_files_return_opts(Options, "rules", ResId)}].
mqtt_ver(ProtoVer) ->
case ProtoVer of

View File

@ -16,7 +16,9 @@
-module(emqx_plugin_libs_ssl).
-export([save_files_return_opts/2]).
-export([save_files_return_opts/2,
save_files_return_opts/3
]).
-type file_input_key() :: binary(). %% <<"file">> | <<"filename">>
-type file_input() :: #{file_input_key() => binary()}.
@ -36,6 +38,14 @@
-type opt_value() :: term().
-type opts() :: [{opt_key(), opt_value()}].
%% @doc Parse ssl options input.
%% If the input contains file content, save the files in the given dir.
%% Returns ssl options for Erlang's ssl application.
-spec save_files_return_opts(opts_input(), string(), string() | binary()) -> opts().
save_files_return_opts(Options, SubDir, ResId) ->
Dir = filename:join([emqx:get_env(data_dir), SubDir, ResId]),
save_files_return_opts(Options, Dir).
%% @doc Parse ssl options input.
%% If the input contains file content, save the files in the given dir.
%% Returns ssl options for Erlang's ssl application.

View File

@ -346,8 +346,7 @@ pool_name(ResId) ->
list_to_atom("webhook:" ++ str(ResId)).
get_ssl_opts(Opts, ResId) ->
Dir = filename:join([emqx:get_env(data_dir), "rules", ResId]),
[{ssl, true}, {ssl_opts, emqx_plugin_libs_ssl:save_files_return_opts(Opts, Dir)}].
[{ssl, true}, {ssl_opts, emqx_plugin_libs_ssl:save_files_return_opts(Opts, "rules", ResId)}].
parse_host(Host) ->
case inet:parse_address(Host) of