refactor: remove unnecessary lists fold for `cerfile`

This commit is contained in:
JimMoen 2024-02-28 14:50:09 +08:00
parent 812e8ef314
commit 5f125047f5
No known key found for this signature in database
1 changed files with 15 additions and 23 deletions

View File

@ -830,8 +830,7 @@ cert_data(undefined) ->
cert_data(AllListeners) -> cert_data(AllListeners) ->
Points = lists:foldl( Points = lists:foldl(
fun(ListenerType, PointsAcc) -> fun(ListenerType, PointsAcc) ->
PointsAcc ++ lists:append(PointsAcc, points_of_listeners(ListenerType, AllListeners))
points_of_listeners(ListenerType, AllListeners)
end, end,
_PointsInitAcc = [], _PointsInitAcc = [],
?LISTENER_TYPES ?LISTENER_TYPES
@ -843,41 +842,34 @@ cert_data(AllListeners) ->
points_of_listeners(Type, AllListeners) -> points_of_listeners(Type, AllListeners) ->
do_points_of_listeners(Type, maps:get(Type, AllListeners, undefined)). do_points_of_listeners(Type, maps:get(Type, AllListeners, undefined)).
-define(CERT_TYPES, [certfile]). -spec do_points_of_listeners(Type, Listeners) ->
-spec do_points_of_listeners(Type, TypeOfListeners) ->
[_Point :: {[{LabelKey, LabelValue}], Epoch}] [_Point :: {[{LabelKey, LabelValue}], Epoch}]
when when
Type :: ssl | wss | quic, Type :: ssl | wss | quic,
TypeOfListeners :: #{ListenerName :: atom() => ListenerConf :: map()} | undefined, Listeners :: #{ListenerName :: atom() => ListenerConf :: map()} | undefined,
LabelKey :: atom(), LabelKey :: atom(),
LabelValue :: atom(), LabelValue :: atom(),
Epoch :: non_neg_integer(). Epoch :: non_neg_integer().
do_points_of_listeners(_, undefined) -> do_points_of_listeners(_, undefined) ->
[]; [];
do_points_of_listeners(ListenerType, TypeOfListeners) -> do_points_of_listeners(Type, Listeners) ->
lists:foldl( lists:foldl(
fun(Name, PointsAcc) -> fun(Name, PointsAcc) ->
lists:foldl(
fun(CertType, AccIn) ->
case case
emqx_utils_maps:deep_get( emqx_utils_maps:deep_get(
[Name, ssl_options, CertType], TypeOfListeners, undefined [Name, ssl_options, certfile], Listeners, undefined
) )
of of
undefined -> AccIn; undefined -> PointsAcc;
Path -> [gen_point(ListenerType, Name, Path) | AccIn] Path -> [gen_point_cert_expiry_at(Type, Name, Path) | PointsAcc]
end end
end, end,
[], [],
?CERT_TYPES %% listener names
) ++ PointsAcc maps:keys(Listeners)
end,
[],
maps:keys(TypeOfListeners)
). ).
gen_point(Type, Name, Path) -> gen_point_cert_expiry_at(Type, Name, Path) ->
{[{listener_type, Type}, {listener_name, Name}], cert_expiry_at_from_path(Path)}. {[{listener_type, Type}, {listener_name, Name}], cert_expiry_at_from_path(Path)}.
%% TODO: cert manager for more generic utils functions %% TODO: cert manager for more generic utils functions