feat(connector): allow delegate `pre_config_update` to impls
This commit is contained in:
parent
257435799d
commit
c17c788438
|
@ -126,19 +126,28 @@ pre_config_update([?ROOT_KEY, _Type, _Name], Oper, OldConfig) when
|
||||||
->
|
->
|
||||||
%% to save the 'enable' to the config files
|
%% to save the 'enable' to the config files
|
||||||
{ok, OldConfig#{<<"enable">> => operation_to_enable(Oper)}};
|
{ok, OldConfig#{<<"enable">> => operation_to_enable(Oper)}};
|
||||||
pre_config_update([?ROOT_KEY, _Type, Name] = Path, Conf = #{}, _OldConfig) ->
|
pre_config_update([?ROOT_KEY, _Type, Name] = Path, Conf = #{}, ConfOld) ->
|
||||||
case validate_connector_name(Name) of
|
case validate_connector_name(Name) of
|
||||||
ok ->
|
ok ->
|
||||||
case emqx_connector_ssl:convert_certs(filename:join(Path), Conf) of
|
case emqx_connector_ssl:convert_certs(filename:join(Path), Conf) of
|
||||||
{error, Reason} ->
|
|
||||||
{error, Reason};
|
|
||||||
{ok, ConfNew} ->
|
{ok, ConfNew} ->
|
||||||
{ok, ConfNew}
|
connector_pre_config_update(Path, ConfNew, ConfOld);
|
||||||
|
{error, Reason} ->
|
||||||
|
{error, Reason}
|
||||||
end;
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
connector_pre_config_update([?ROOT_KEY, Type, Name] = Path, ConfNew, ConfOld) ->
|
||||||
|
Mod = emqx_connector_info:config_transform_module(Type),
|
||||||
|
case Mod =/= undefined andalso erlang:function_exported(Mod, pre_config_update, 4) of
|
||||||
|
true ->
|
||||||
|
apply(Mod, pre_config_update, [Path, Name, ConfNew, ConfOld]);
|
||||||
|
false ->
|
||||||
|
{ok, ConfNew}
|
||||||
|
end.
|
||||||
|
|
||||||
operation_to_enable(disable) -> false;
|
operation_to_enable(disable) -> false;
|
||||||
operation_to_enable(enable) -> true.
|
operation_to_enable(enable) -> true.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue