refactor: introduce emqx_const_v1 for immutable anonymous funs
This commit is contained in:
parent
ce282797be
commit
32a8753e9d
|
@ -313,7 +313,7 @@ do_merge_update_actions(App, {New0, Changed0, Deleted0}, OldActions) ->
|
|||
true ->
|
||||
[];
|
||||
false ->
|
||||
[{load_module, M, brutal_purge, soft_purge, []} || M <- Changed, not is_secret_module(M)] ++
|
||||
[{load_module, M, brutal_purge, soft_purge, []} || M <- Changed, not is_const_module(M)] ++
|
||||
[{add_module, M} || M <- New]
|
||||
end,
|
||||
{OldActionsWithStop, OldActionsAfterStop} =
|
||||
|
@ -325,14 +325,17 @@ do_merge_update_actions(App, {New0, Changed0, Deleted0}, OldActions) ->
|
|||
true ->
|
||||
[];
|
||||
false ->
|
||||
[{delete_module, M} || M <- Deleted, not is_secret_module(M)]
|
||||
[{delete_module, M} || M <- Deleted, not is_const_module(M)]
|
||||
end ++
|
||||
AppSpecific.
|
||||
|
||||
%% Do not reload or delet _secret modules
|
||||
is_secret_module(Module) ->
|
||||
is_const_module(Module) when is_atom(Module) ->
|
||||
is_const_module(atom_to_list(Module));
|
||||
is_const_module("emqx_const_" ++ _) ->
|
||||
true;
|
||||
is_const_module(Module) ->
|
||||
Suffix = "_secret",
|
||||
case string:right(atom_to_list(Module), length(Suffix)) of
|
||||
case string:right(Module, length(Suffix)) of
|
||||
Suffix -> true;
|
||||
_ -> false
|
||||
end.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
[{"4.4.10",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_access_rule,brutal_purge,soft_purge,[]},
|
||||
|
@ -19,6 +20,7 @@
|
|||
{"4.4.9",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -41,6 +43,7 @@
|
|||
{"4.4.8",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -64,6 +67,7 @@
|
|||
{"4.4.7",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -87,6 +91,7 @@
|
|||
{"4.4.6",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -110,6 +115,7 @@
|
|||
{"4.4.5",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -135,6 +141,7 @@
|
|||
{"4.4.4",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -167,6 +174,7 @@
|
|||
{"4.4.3",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -206,6 +214,7 @@
|
|||
{"4.4.2",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_listeners,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
|
@ -246,6 +255,7 @@
|
|||
{"4.4.1",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_router_helper,brutal_purge,soft_purge,[]},
|
||||
|
@ -291,6 +301,7 @@
|
|||
{"4.4.0",
|
||||
[{add_module,emqx_ocsp_cache},
|
||||
{add_module,emqx_crl_cache},
|
||||
{add_module,emqx_const_v1},
|
||||
{add_module,emqx_secret},
|
||||
{load_module,emqx_kernel_sup,brutal_purge,soft_purge,[]},
|
||||
{load_module,emqx_router_helper,brutal_purge,soft_purge,[]},
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2022 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%
|
||||
%% @doc Never update this module, create a v2 instead.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(emqx_const_v1).
|
||||
|
||||
-export([make_sni_fun/1]).
|
||||
|
||||
make_sni_fun(ListenerID) ->
|
||||
fun(SN) -> emqx_ocsp_cache:sni_fun(SN, ListenerID) end.
|
|
@ -103,7 +103,7 @@ inject_sni_fun(ListenerID, Options0) ->
|
|||
Options0;
|
||||
true ->
|
||||
SSLOpts0 = proplists:get_value(ssl_options, Options0, []),
|
||||
SNIFun = fun(SN) -> emqx_ocsp_cache:sni_fun(SN, ListenerID) end,
|
||||
SNIFun = emqx_const_v1:make_sni_fun(ListenerID),
|
||||
Options1 = proplists:delete(ssl_options, Options0),
|
||||
Options = [{ssl_options, [{sni_fun, SNIFun} | SSLOpts0]} | Options1],
|
||||
%% save to env
|
||||
|
@ -177,25 +177,6 @@ handle_info(_Info, State) ->
|
|||
{noreply, State}.
|
||||
|
||||
code_change(_Vsn, State, _Extra) ->
|
||||
%% we need to re-create the `sni_fun' lambda that the SSL
|
||||
%% listeners are holding onto to avoid them becoming `badfun''s.
|
||||
ListenersToPatch =
|
||||
lists:filter(
|
||||
fun(#{opts := Opts}) ->
|
||||
OCSPOpts = proplists:get_value(ocsp_options, Opts),
|
||||
undefined =/= proplists:get_value(ocsp_responder_url, OCSPOpts, undefined) andalso
|
||||
false =/= proplists:get_bool(ocsp_stapling_enabled, OCSPOpts)
|
||||
end,
|
||||
emqx:get_env(listeners, [])),
|
||||
PatchedListeners = [L#{opts => ?MODULE:inject_sni_fun(
|
||||
emqx_listeners:identifier(L),
|
||||
Opts)}
|
||||
|| L = #{opts := Opts} <- ListenersToPatch],
|
||||
lists:foreach(
|
||||
fun(L) ->
|
||||
emqx_listeners:update_listeners_env(update, L)
|
||||
end,
|
||||
PatchedListeners),
|
||||
{ok, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue