refactor: remove unnecessary lists fold for `cerfile`
This commit is contained in:
parent
812e8ef314
commit
5f125047f5
|
@ -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(
|
case
|
||||||
fun(CertType, AccIn) ->
|
emqx_utils_maps:deep_get(
|
||||||
case
|
[Name, ssl_options, certfile], Listeners, undefined
|
||||||
emqx_utils_maps:deep_get(
|
)
|
||||||
[Name, ssl_options, CertType], TypeOfListeners, undefined
|
of
|
||||||
)
|
undefined -> PointsAcc;
|
||||||
of
|
Path -> [gen_point_cert_expiry_at(Type, Name, Path) | PointsAcc]
|
||||||
undefined -> AccIn;
|
end
|
||||||
Path -> [gen_point(ListenerType, Name, Path) | AccIn]
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
[],
|
|
||||||
?CERT_TYPES
|
|
||||||
) ++ PointsAcc
|
|
||||||
end,
|
end,
|
||||||
[],
|
[],
|
||||||
maps:keys(TypeOfListeners)
|
%% listener names
|
||||||
|
maps:keys(Listeners)
|
||||||
).
|
).
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue