refactor: rename emqx_map_lib to emqx_utils_maps

This commit is contained in:
Stefan Strigler 2023-04-13 15:02:41 +02:00
parent 6e8665365b
commit 062ce5f819
61 changed files with 256 additions and 241 deletions

View File

@ -164,29 +164,29 @@ run_hook(HookPoint, Args) ->
run_fold_hook(HookPoint, Args, Acc) ->
emqx_hooks:run_fold(HookPoint, Args, Acc).
-spec get_config(emqx_map_lib:config_key_path()) -> term().
-spec get_config(emqx_utils_maps:config_key_path()) -> term().
get_config(KeyPath) ->
emqx_config:get(KeyPath).
-spec get_config(emqx_map_lib:config_key_path(), term()) -> term().
-spec get_config(emqx_utils_maps:config_key_path(), term()) -> term().
get_config(KeyPath, Default) ->
emqx_config:get(KeyPath, Default).
-spec get_raw_config(emqx_map_lib:config_key_path()) -> term().
-spec get_raw_config(emqx_utils_maps:config_key_path()) -> term().
get_raw_config(KeyPath) ->
emqx_config:get_raw(KeyPath).
-spec get_raw_config(emqx_map_lib:config_key_path(), term()) -> term().
-spec get_raw_config(emqx_utils_maps:config_key_path(), term()) -> term().
get_raw_config(KeyPath, Default) ->
emqx_config:get_raw(KeyPath, Default).
-spec update_config(emqx_map_lib:config_key_path(), emqx_config:update_request()) ->
-spec update_config(emqx_utils_maps:config_key_path(), emqx_config:update_request()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
update_config(KeyPath, UpdateReq) ->
update_config(KeyPath, UpdateReq, #{}).
-spec update_config(
emqx_map_lib:config_key_path(),
emqx_utils_maps:config_key_path(),
emqx_config:update_request(),
emqx_config:update_opts()
) ->
@ -198,12 +198,12 @@ update_config([RootName | _] = KeyPath, UpdateReq, Opts) ->
{{update, UpdateReq}, Opts}
).
-spec remove_config(emqx_map_lib:config_key_path()) ->
-spec remove_config(emqx_utils_maps:config_key_path()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
remove_config(KeyPath) ->
remove_config(KeyPath, #{}).
-spec remove_config(emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
-spec remove_config(emqx_utils_maps:config_key_path(), emqx_config:update_opts()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
remove_config([RootName | _] = KeyPath, Opts) ->
emqx_config_handler:update_config(
@ -212,7 +212,7 @@ remove_config([RootName | _] = KeyPath, Opts) ->
{remove, Opts}
).
-spec reset_config(emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
-spec reset_config(emqx_utils_maps:config_key_path(), emqx_config:update_opts()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
reset_config([RootName | _] = KeyPath, Opts) ->
case emqx_config:get_default_value(KeyPath) of

View File

@ -142,7 +142,7 @@
-type app_envs() :: [proplists:property()].
%% @doc For the given path, get root value enclosed in a single-key map.
-spec get_root(emqx_map_lib:config_key_path()) -> map().
-spec get_root(emqx_utils_maps:config_key_path()) -> map().
get_root([RootName | _]) ->
#{RootName => do_get(?CONF, [RootName], #{})}.
@ -153,14 +153,14 @@ get_root_raw([RootName | _]) ->
%% @doc Get a config value for the given path.
%% The path should at least include root config name.
-spec get(emqx_map_lib:config_key_path()) -> term().
-spec get(emqx_utils_maps:config_key_path()) -> term().
get(KeyPath) -> do_get(?CONF, KeyPath).
-spec get(emqx_map_lib:config_key_path(), term()) -> term().
-spec get(emqx_utils_maps:config_key_path(), term()) -> term().
get(KeyPath, Default) -> do_get(?CONF, KeyPath, Default).
-spec find(emqx_map_lib:config_key_path()) ->
{ok, term()} | {not_found, emqx_map_lib:config_key_path(), term()}.
-spec find(emqx_utils_maps:config_key_path()) ->
{ok, term()} | {not_found, emqx_utils_maps:config_key_path(), term()}.
find([]) ->
Ref = make_ref(),
case do_get(?CONF, [], Ref) of
@ -170,12 +170,12 @@ find([]) ->
find(KeyPath) ->
atom_conf_path(
KeyPath,
fun(AtomKeyPath) -> emqx_map_lib:deep_find(AtomKeyPath, get_root(KeyPath)) end,
fun(AtomKeyPath) -> emqx_utils_maps:deep_find(AtomKeyPath, get_root(KeyPath)) end,
{return, {not_found, KeyPath}}
).
-spec find_raw(emqx_map_lib:config_key_path()) ->
{ok, term()} | {not_found, emqx_map_lib:config_key_path(), term()}.
-spec find_raw(emqx_utils_maps:config_key_path()) ->
{ok, term()} | {not_found, emqx_utils_maps:config_key_path(), term()}.
find_raw([]) ->
Ref = make_ref(),
case do_get_raw([], Ref) of
@ -183,9 +183,9 @@ find_raw([]) ->
Res -> {ok, Res}
end;
find_raw(KeyPath) ->
emqx_map_lib:deep_find([bin(Key) || Key <- KeyPath], get_root_raw(KeyPath)).
emqx_utils_maps:deep_find([bin(Key) || Key <- KeyPath], get_root_raw(KeyPath)).
-spec get_zone_conf(atom(), emqx_map_lib:config_key_path()) -> term().
-spec get_zone_conf(atom(), emqx_utils_maps:config_key_path()) -> term().
get_zone_conf(Zone, KeyPath) ->
case find(?ZONE_CONF_PATH(Zone, KeyPath)) of
%% not found in zones, try to find the global config
@ -195,7 +195,7 @@ get_zone_conf(Zone, KeyPath) ->
Value
end.
-spec get_zone_conf(atom(), emqx_map_lib:config_key_path(), term()) -> term().
-spec get_zone_conf(atom(), emqx_utils_maps:config_key_path(), term()) -> term().
get_zone_conf(Zone, KeyPath, Default) ->
case find(?ZONE_CONF_PATH(Zone, KeyPath)) of
%% not found in zones, try to find the global config
@ -205,24 +205,24 @@ get_zone_conf(Zone, KeyPath, Default) ->
Value
end.
-spec put_zone_conf(atom(), emqx_map_lib:config_key_path(), term()) -> ok.
-spec put_zone_conf(atom(), emqx_utils_maps:config_key_path(), term()) -> ok.
put_zone_conf(Zone, KeyPath, Conf) ->
?MODULE:put(?ZONE_CONF_PATH(Zone, KeyPath), Conf).
-spec get_listener_conf(atom(), atom(), emqx_map_lib:config_key_path()) -> term().
-spec get_listener_conf(atom(), atom(), emqx_utils_maps:config_key_path()) -> term().
get_listener_conf(Type, Listener, KeyPath) ->
?MODULE:get(?LISTENER_CONF_PATH(Type, Listener, KeyPath)).
-spec get_listener_conf(atom(), atom(), emqx_map_lib:config_key_path(), term()) -> term().
-spec get_listener_conf(atom(), atom(), emqx_utils_maps:config_key_path(), term()) -> term().
get_listener_conf(Type, Listener, KeyPath, Default) ->
?MODULE:get(?LISTENER_CONF_PATH(Type, Listener, KeyPath), Default).
-spec put_listener_conf(atom(), atom(), emqx_map_lib:config_key_path(), term()) -> ok.
-spec put_listener_conf(atom(), atom(), emqx_utils_maps:config_key_path(), term()) -> ok.
put_listener_conf(Type, Listener, KeyPath, Conf) ->
?MODULE:put(?LISTENER_CONF_PATH(Type, Listener, KeyPath), Conf).
-spec find_listener_conf(atom(), atom(), emqx_map_lib:config_key_path()) ->
{ok, term()} | {not_found, emqx_map_lib:config_key_path(), term()}.
-spec find_listener_conf(atom(), atom(), emqx_utils_maps:config_key_path()) ->
{ok, term()} | {not_found, emqx_utils_maps:config_key_path(), term()}.
find_listener_conf(Type, Listener, KeyPath) ->
find(?LISTENER_CONF_PATH(Type, Listener, KeyPath)).
@ -241,20 +241,20 @@ erase(RootName) ->
persistent_term:erase(?PERSIS_KEY(?RAW_CONF, bin(RootName))),
ok.
-spec put(emqx_map_lib:config_key_path(), term()) -> ok.
-spec put(emqx_utils_maps:config_key_path(), term()) -> ok.
put(KeyPath, Config) ->
Putter = fun(Path, Map, Value) ->
emqx_map_lib:deep_put(Path, Map, Value)
emqx_utils_maps:deep_put(Path, Map, Value)
end,
do_put(?CONF, Putter, KeyPath, Config).
%% Puts value into configuration even if path doesn't exist
%% For paths of non-existing atoms use force_put(KeyPath, Config, unsafe)
-spec force_put(emqx_map_lib:config_key_path(), term()) -> ok.
-spec force_put(emqx_utils_maps:config_key_path(), term()) -> ok.
force_put(KeyPath, Config) ->
force_put(KeyPath, Config, safe).
-spec force_put(emqx_map_lib:config_key_path(), term(), safe | unsafe) -> ok.
-spec force_put(emqx_utils_maps:config_key_path(), term(), safe | unsafe) -> ok.
force_put(KeyPath0, Config, Safety) ->
KeyPath =
case Safety of
@ -262,19 +262,19 @@ force_put(KeyPath0, Config, Safety) ->
unsafe -> [unsafe_atom(Key) || Key <- KeyPath0]
end,
Putter = fun(Path, Map, Value) ->
emqx_map_lib:deep_force_put(Path, Map, Value)
emqx_utils_maps:deep_force_put(Path, Map, Value)
end,
do_put(?CONF, Putter, KeyPath, Config).
-spec get_default_value(emqx_map_lib:config_key_path()) -> {ok, term()} | {error, term()}.
-spec get_default_value(emqx_utils_maps:config_key_path()) -> {ok, term()} | {error, term()}.
get_default_value([RootName | _] = KeyPath) ->
BinKeyPath = [bin(Key) || Key <- KeyPath],
case find_raw([RootName]) of
{ok, RawConf} ->
RawConf1 = emqx_map_lib:deep_remove(BinKeyPath, #{bin(RootName) => RawConf}),
RawConf1 = emqx_utils_maps:deep_remove(BinKeyPath, #{bin(RootName) => RawConf}),
try fill_defaults(get_schema_mod(RootName), RawConf1, #{}) of
FullConf ->
case emqx_map_lib:deep_find(BinKeyPath, FullConf) of
case emqx_utils_maps:deep_find(BinKeyPath, FullConf) of
{not_found, _, _} -> {error, no_default_value};
{ok, Val} -> {ok, Val}
end
@ -285,10 +285,10 @@ get_default_value([RootName | _] = KeyPath) ->
{error, {rootname_not_found, RootName}}
end.
-spec get_raw(emqx_map_lib:config_key_path()) -> term().
-spec get_raw(emqx_utils_maps:config_key_path()) -> term().
get_raw(KeyPath) -> do_get_raw(KeyPath).
-spec get_raw(emqx_map_lib:config_key_path(), term()) -> term().
-spec get_raw(emqx_utils_maps:config_key_path(), term()) -> term().
get_raw(KeyPath, Default) -> do_get_raw(KeyPath, Default).
-spec put_raw(map()) -> ok.
@ -301,10 +301,10 @@ put_raw(Config) ->
hocon_maps:ensure_plain(Config)
).
-spec put_raw(emqx_map_lib:config_key_path(), term()) -> ok.
-spec put_raw(emqx_utils_maps:config_key_path(), term()) -> ok.
put_raw(KeyPath, Config) ->
Putter = fun(Path, Map, Value) ->
emqx_map_lib:deep_force_put(Path, Map, Value)
emqx_utils_maps:deep_force_put(Path, Map, Value)
end,
do_put(?RAW_CONF, Putter, KeyPath, Config).
@ -430,7 +430,7 @@ do_check_config(SchemaMod, RawConf, Opts0) ->
Opts = maps:merge(Opts0, Opts1),
{AppEnvs, CheckedConf} =
hocon_tconf:map_translate(SchemaMod, RawConf, Opts),
{AppEnvs, emqx_map_lib:unsafe_atom_key_map(CheckedConf)}.
{AppEnvs, emqx_utils_maps:unsafe_atom_key_map(CheckedConf)}.
fill_defaults(RawConf) ->
fill_defaults(RawConf, #{}).
@ -645,11 +645,11 @@ do_put(Type, Putter, [RootName | KeyPath], DeepValue) ->
do_deep_get(?CONF, KeyPath, Map, Default) ->
atom_conf_path(
KeyPath,
fun(AtomKeyPath) -> emqx_map_lib:deep_get(AtomKeyPath, Map, Default) end,
fun(AtomKeyPath) -> emqx_utils_maps:deep_get(AtomKeyPath, Map, Default) end,
{return, Default}
);
do_deep_get(?RAW_CONF, KeyPath, Map, Default) ->
emqx_map_lib:deep_get([bin(Key) || Key <- KeyPath], Map, Default).
emqx_utils_maps:deep_get([bin(Key) || Key <- KeyPath], Map, Default).
do_deep_put(?CONF, Putter, KeyPath, Map, Value) ->
atom_conf_path(

View File

@ -232,7 +232,7 @@ process_update_request(ConfKeyPath, _Handlers, {remove, Opts}) ->
BinKeyPath = bin_path(ConfKeyPath),
case check_permissions(remove, BinKeyPath, OldRawConf, Opts) of
allow ->
NewRawConf = emqx_map_lib:deep_remove(BinKeyPath, OldRawConf),
NewRawConf = emqx_utils_maps:deep_remove(BinKeyPath, OldRawConf),
OverrideConf = remove_from_override_config(BinKeyPath, Opts),
{ok, NewRawConf, OverrideConf, Opts};
{deny, Reason} ->
@ -445,7 +445,7 @@ remove_from_override_config(_BinKeyPath, #{persistent := false}) ->
undefined;
remove_from_override_config(BinKeyPath, Opts) ->
OldConf = emqx_config:read_override_conf(Opts),
emqx_map_lib:deep_remove(BinKeyPath, OldConf).
emqx_utils_maps:deep_remove(BinKeyPath, OldConf).
%% apply new config on top of override config
merge_to_override_config(_RawConf, #{persistent := false}) ->
@ -467,7 +467,7 @@ return_change_result(_ConfKeyPath, {remove, _Opts}) ->
return_rawconf(ConfKeyPath, #{rawconf_with_defaults := true}) ->
FullRawConf = emqx_config:fill_defaults(emqx_config:get_raw([])),
emqx_map_lib:deep_get(bin_path(ConfKeyPath), FullRawConf);
emqx_utils_maps:deep_get(bin_path(ConfKeyPath), FullRawConf);
return_rawconf(ConfKeyPath, _) ->
emqx_config:get_raw(ConfKeyPath).
@ -485,16 +485,16 @@ atom(Atom) when is_atom(Atom) ->
-dialyzer({nowarn_function, do_remove_handler/2}).
do_remove_handler(ConfKeyPath, Handlers) ->
NewHandlers = emqx_map_lib:deep_remove(ConfKeyPath ++ [?MOD], Handlers),
NewHandlers = emqx_utils_maps:deep_remove(ConfKeyPath ++ [?MOD], Handlers),
remove_empty_leaf(ConfKeyPath, NewHandlers).
remove_empty_leaf([], Handlers) ->
Handlers;
remove_empty_leaf(KeyPath, Handlers) ->
case emqx_map_lib:deep_find(KeyPath, Handlers) =:= {ok, #{}} of
case emqx_utils_maps:deep_find(KeyPath, Handlers) =:= {ok, #{}} of
%% empty leaf
true ->
Handlers1 = emqx_map_lib:deep_remove(KeyPath, Handlers),
Handlers1 = emqx_utils_maps:deep_remove(KeyPath, Handlers),
SubKeyPath = lists:sublist(KeyPath, length(KeyPath) - 1),
remove_empty_leaf(SubKeyPath, Handlers1);
false ->
@ -511,7 +511,7 @@ assert_callback_function(Mod) ->
end,
ok.
-spec schema(module(), emqx_map_lib:config_key_path()) -> hocon_schema:schema().
-spec schema(module(), emqx_utils_maps:config_key_path()) -> hocon_schema:schema().
schema(SchemaModule, [RootKey | _]) ->
Roots = hocon_schema:roots(SchemaModule),
{Field, Translations} =
@ -550,10 +550,10 @@ save_handlers(Handlers) ->
check_permissions(_Action, _ConfKeyPath, _NewRawConf, #{override_to := local}) ->
allow;
check_permissions(Action, ConfKeyPath, NewRawConf, _Opts) ->
case emqx_map_lib:deep_find(ConfKeyPath, NewRawConf) of
case emqx_utils_maps:deep_find(ConfKeyPath, NewRawConf) of
{ok, NewRaw} ->
LocalOverride = emqx_config:read_override_conf(#{override_to => local}),
case emqx_map_lib:deep_find(ConfKeyPath, LocalOverride) of
case emqx_utils_maps:deep_find(ConfKeyPath, LocalOverride) of
{ok, LocalRaw} ->
case is_mutable(Action, NewRaw, LocalRaw) of
ok ->

View File

@ -572,7 +572,7 @@ find_limiter_cfg(Type, #{rate := _} = Cfg) ->
find_limiter_cfg(Type, Cfg) ->
{
maps:get(Type, Cfg, undefined),
find_client_cfg(Type, emqx_map_lib:deep_get([client, Type], Cfg, undefined))
find_client_cfg(Type, emqx_utils_maps:deep_get([client, Type], Cfg, undefined))
}.
find_client_cfg(Type, BucketCfg) ->

View File

@ -427,12 +427,12 @@ pre_config_update([listeners, _Type, _Name], {create, _NewConf}, _RawConf) ->
pre_config_update([listeners, _Type, _Name], {update, _Request}, undefined) ->
{error, not_found};
pre_config_update([listeners, Type, Name], {update, Request}, RawConf) ->
NewConfT = emqx_map_lib:deep_merge(RawConf, Request),
NewConfT = emqx_utils_maps:deep_merge(RawConf, Request),
NewConf = ensure_override_limiter_conf(NewConfT, Request),
CertsDir = certs_dir(Type, Name),
{ok, convert_certs(CertsDir, NewConf)};
pre_config_update([listeners, _Type, _Name], {action, _Action, Updated}, RawConf) ->
NewConf = emqx_map_lib:deep_merge(RawConf, Updated),
NewConf = emqx_utils_maps:deep_merge(RawConf, Updated),
{ok, NewConf};
pre_config_update(_Path, _Request, RawConf) ->
{ok, RawConf}.
@ -500,7 +500,7 @@ esockd_opts(ListenerId, Type, Opts0) ->
ws_opts(Type, ListenerName, Opts) ->
WsPaths = [
{emqx_map_lib:deep_get([websocket, mqtt_path], Opts, "/mqtt"), emqx_ws_connection, #{
{emqx_utils_maps:deep_get([websocket, mqtt_path], Opts, "/mqtt"), emqx_ws_connection, #{
zone => zone(Opts),
listener => {Type, ListenerName},
limiter => limiter(Opts),

View File

@ -110,7 +110,7 @@ register_listener(ListenerID, Opts) ->
-spec inject_sni_fun(emqx_listeners:listener_id(), map()) -> map().
inject_sni_fun(ListenerID, Conf0) ->
SNIFun = emqx_const_v1:make_sni_fun(ListenerID),
Conf = emqx_map_lib:deep_merge(Conf0, #{ssl_options => #{sni_fun => SNIFun}}),
Conf = emqx_utils_maps:deep_merge(Conf0, #{ssl_options => #{sni_fun => SNIFun}}),
ok = ?MODULE:register_listener(ListenerID, Conf),
Conf.
@ -149,7 +149,7 @@ handle_call({register_listener, ListenerID, Conf}, _From, State0) ->
msg => "registering_ocsp_cache",
listener_id => ListenerID
}),
RefreshInterval0 = emqx_map_lib:deep_get([ssl_options, ocsp, refresh_interval], Conf),
RefreshInterval0 = emqx_utils_maps:deep_get([ssl_options, ocsp, refresh_interval], Conf),
RefreshInterval = max(RefreshInterval0, ?MIN_REFRESH_INTERVAL),
State = State0#{{refresh_interval, ListenerID} => RefreshInterval},
%% we need to pass the config along because this might be called

View File

@ -2348,7 +2348,7 @@ ocsp_outer_validator(_Conf) ->
ok.
ocsp_inner_validator(#{enable_ocsp_stapling := _} = Conf) ->
ocsp_inner_validator(emqx_map_lib:binary_key_map(Conf));
ocsp_inner_validator(emqx_utils_maps:binary_key_map(Conf));
ocsp_inner_validator(#{<<"enable_ocsp_stapling">> := false} = _Conf) ->
ok;
ocsp_inner_validator(#{<<"enable_ocsp_stapling">> := true} = Conf) ->

View File

@ -317,7 +317,9 @@ ensure_ssl_files(Dir, SSL, Opts) ->
ensure_ssl_files(_Dir, SSL, [], _Opts) ->
{ok, SSL};
ensure_ssl_files(Dir, SSL, [KeyPath | KeyPaths], Opts) ->
case ensure_ssl_file(Dir, KeyPath, SSL, emqx_map_lib:deep_get(KeyPath, SSL, undefined), Opts) of
case
ensure_ssl_file(Dir, KeyPath, SSL, emqx_utils_maps:deep_get(KeyPath, SSL, undefined), Opts)
of
{ok, NewSSL} ->
ensure_ssl_files(Dir, NewSSL, KeyPaths, Opts);
{error, Reason} ->
@ -332,7 +334,7 @@ delete_ssl_files(Dir, NewOpts0, OldOpts0) ->
{ok, OldOpts} = ensure_ssl_files(Dir, OldOpts0, #{dry_run => DryRun}),
Get = fun
(_KP, undefined) -> undefined;
(KP, Opts) -> emqx_map_lib:deep_get(KP, Opts, undefined)
(KP, Opts) -> emqx_utils_maps:deep_get(KP, Opts, undefined)
end,
lists:foreach(
fun(KeyPath) -> delete_old_file(Get(KeyPath, NewOpts), Get(KeyPath, OldOpts)) end,
@ -372,7 +374,7 @@ do_ensure_ssl_file(Dir, KeyPath, SSL, MaybePem, DryRun) ->
true ->
case save_pem_file(Dir, KeyPath, MaybePem, DryRun) of
{ok, Path} ->
NewSSL = emqx_map_lib:deep_put(KeyPath, SSL, Path),
NewSSL = emqx_utils_maps:deep_put(KeyPath, SSL, Path),
{ok, NewSSL};
{error, Reason} ->
{error, Reason}
@ -482,9 +484,9 @@ is_valid_pem_file(Path) ->
%% so they are forced to upload a cert file, or use an existing file path.
-spec drop_invalid_certs(map()) -> map().
drop_invalid_certs(#{enable := False} = SSL) when ?IS_FALSE(False) ->
lists:foldl(fun emqx_map_lib:deep_remove/2, SSL, ?SSL_FILE_OPT_PATHS_A);
lists:foldl(fun emqx_utils_maps:deep_remove/2, SSL, ?SSL_FILE_OPT_PATHS_A);
drop_invalid_certs(#{<<"enable">> := False} = SSL) when ?IS_FALSE(False) ->
lists:foldl(fun emqx_map_lib:deep_remove/2, SSL, ?SSL_FILE_OPT_PATHS);
lists:foldl(fun emqx_utils_maps:deep_remove/2, SSL, ?SSL_FILE_OPT_PATHS);
drop_invalid_certs(#{enable := True} = SSL) when ?IS_TRUE(True) ->
do_drop_invalid_certs(?SSL_FILE_OPT_PATHS_A, SSL);
drop_invalid_certs(#{<<"enable">> := True} = SSL) when ?IS_TRUE(True) ->
@ -493,7 +495,7 @@ drop_invalid_certs(#{<<"enable">> := True} = SSL) when ?IS_TRUE(True) ->
do_drop_invalid_certs([], SSL) ->
SSL;
do_drop_invalid_certs([KeyPath | KeyPaths], SSL) ->
case emqx_map_lib:deep_get(KeyPath, SSL, undefined) of
case emqx_utils_maps:deep_get(KeyPath, SSL, undefined) of
undefined ->
do_drop_invalid_certs(KeyPaths, SSL);
PemOrPath ->
@ -501,7 +503,7 @@ do_drop_invalid_certs([KeyPath | KeyPaths], SSL) ->
true ->
do_drop_invalid_certs(KeyPaths, SSL);
{error, _} ->
do_drop_invalid_certs(KeyPaths, emqx_map_lib:deep_remove(KeyPath, SSL))
do_drop_invalid_certs(KeyPaths, emqx_utils_maps:deep_remove(KeyPath, SSL))
end
end.
@ -586,7 +588,9 @@ ensure_ssl_file_key(_SSL, []) ->
ok;
ensure_ssl_file_key(SSL, RequiredKeyPaths) ->
NotFoundRef = make_ref(),
Filter = fun(KeyPath) -> NotFoundRef =:= emqx_map_lib:deep_get(KeyPath, SSL, NotFoundRef) end,
Filter = fun(KeyPath) ->
NotFoundRef =:= emqx_utils_maps:deep_get(KeyPath, SSL, NotFoundRef)
end,
case lists:filter(Filter, RequiredKeyPaths) of
[] -> ok;
Miss -> {error, #{reason => ssl_file_option_not_found, which_options => Miss}}

View File

@ -997,7 +997,7 @@ do_t_update_listener(Config) ->
<<"enable_crl_check">> => true
}
},
ListenerData1 = emqx_map_lib:deep_merge(ListenerData0, CRLConfig),
ListenerData1 = emqx_utils_maps:deep_merge(ListenerData0, CRLConfig),
{ok, {_, _, ListenerData2}} = update_listener_via_api(ListenerId, ListenerData1),
?assertMatch(
#{
@ -1040,7 +1040,7 @@ do_t_validations(_Config) ->
{ok, {{_, 200, _}, _, ListenerData0}} = get_listener_via_api(ListenerId),
ListenerData1 =
emqx_map_lib:deep_merge(
emqx_utils_maps:deep_merge(
ListenerData0,
#{
<<"ssl_options">> =>

View File

@ -143,7 +143,7 @@ init_per_testcase(t_ocsp_responder_error_responses, Config) ->
}
},
Conf = #{listeners => #{Type => #{Name => ListenerOpts}}},
ConfBin = emqx_map_lib:binary_key_map(Conf),
ConfBin = emqx_utils_maps:binary_key_map(Conf),
hocon_tconf:check_plain(emqx_schema, ConfBin, #{required => false, atom_keys => false}),
emqx_config:put_listener_conf(Type, Name, [], ListenerOpts),
snabbkaffe:start_trace(),
@ -184,7 +184,7 @@ init_per_testcase(_TestCase, Config) ->
}
},
Conf = #{listeners => #{Type => #{Name => ListenerOpts}}},
ConfBin = emqx_map_lib:binary_key_map(Conf),
ConfBin = emqx_utils_maps:binary_key_map(Conf),
hocon_tconf:check_plain(emqx_schema, ConfBin, #{required => false, atom_keys => false}),
emqx_config:put_listener_conf(Type, Name, [], ListenerOpts),
snabbkaffe:start_trace(),
@ -679,7 +679,7 @@ do_t_update_listener(Config) ->
{ok, {{_, 200, _}, _, ListenerData0}} = get_listener_via_api(ListenerId),
?assertEqual(
undefined,
emqx_map_lib:deep_get([<<"ssl_options">>, <<"ocsp">>], ListenerData0, undefined)
emqx_utils_maps:deep_get([<<"ssl_options">>, <<"ocsp">>], ListenerData0, undefined)
),
assert_no_http_get(),
@ -702,7 +702,7 @@ do_t_update_listener(Config) ->
}
}
},
ListenerData1 = emqx_map_lib:deep_merge(ListenerData0, OCSPConfig),
ListenerData1 = emqx_utils_maps:deep_merge(ListenerData0, OCSPConfig),
{ok, {_, _, ListenerData2}} = update_listener_via_api(ListenerId, ListenerData1),
?assertMatch(
#{
@ -722,14 +722,14 @@ do_t_update_listener(Config) ->
%% location
?assertNotEqual(
IssuerPemPath,
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[<<"ssl_options">>, <<"ocsp">>, <<"issuer_pem">>],
ListenerData2
)
),
?assertNotEqual(
IssuerPem,
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[<<"ssl_options">>, <<"ocsp">>, <<"issuer_pem">>],
ListenerData2
)
@ -818,7 +818,7 @@ do_t_validations(_Config) ->
{ok, {{_, 200, _}, _, ListenerData0}} = get_listener_via_api(ListenerId),
ListenerData1 =
emqx_map_lib:deep_merge(
emqx_utils_maps:deep_merge(
ListenerData0,
#{
<<"ssl_options">> =>
@ -843,7 +843,7 @@ do_t_validations(_Config) ->
),
ListenerData2 =
emqx_map_lib:deep_merge(
emqx_utils_maps:deep_merge(
ListenerData0,
#{
<<"ssl_options">> =>
@ -873,7 +873,7 @@ do_t_validations(_Config) ->
),
ListenerData3a =
emqx_map_lib:deep_merge(
emqx_utils_maps:deep_merge(
ListenerData0,
#{
<<"ssl_options">> =>
@ -886,7 +886,9 @@ do_t_validations(_Config) ->
}
}
),
ListenerData3 = emqx_map_lib:deep_remove([<<"ssl_options">>, <<"certfile">>], ListenerData3a),
ListenerData3 = emqx_utils_maps:deep_remove(
[<<"ssl_options">>, <<"certfile">>], ListenerData3a
),
{error, {_, _, ResRaw3}} = update_listener_via_api(ListenerId, ListenerData3),
#{<<"code">> := <<"BAD_REQUEST">>, <<"message">> := MsgRaw3} =
emqx_utils_json:decode(ResRaw3, [return_maps]),

View File

@ -191,7 +191,7 @@ ssl_files_save_delete_test() ->
FileKey = maps:get(<<"keyfile">>, SSL),
?assertMatch(<<"/tmp/ssl-test-dir/key-", _:16/binary>>, FileKey),
?assertEqual({ok, bin(test_key())}, file:read_file(FileKey)),
FileIssuerPem = emqx_map_lib:deep_get([<<"ocsp">>, <<"issuer_pem">>], SSL),
FileIssuerPem = emqx_utils_maps:deep_get([<<"ocsp">>, <<"issuer_pem">>], SSL),
?assertMatch(<<"/tmp/ssl-test-dir/ocsp_issuer_pem-", _:16/binary>>, FileIssuerPem),
?assertEqual({ok, bin(test_key())}, file:read_file(FileIssuerPem)),
%% no old file to delete
@ -251,8 +251,8 @@ ssl_file_replace_test() ->
{ok, SSL3} = emqx_tls_lib:ensure_ssl_files(Dir, SSL1),
File1 = maps:get(<<"keyfile">>, SSL2),
File2 = maps:get(<<"keyfile">>, SSL3),
IssuerPem1 = emqx_map_lib:deep_get([<<"ocsp">>, <<"issuer_pem">>], SSL2),
IssuerPem2 = emqx_map_lib:deep_get([<<"ocsp">>, <<"issuer_pem">>], SSL3),
IssuerPem1 = emqx_utils_maps:deep_get([<<"ocsp">>, <<"issuer_pem">>], SSL2),
IssuerPem2 = emqx_utils_maps:deep_get([<<"ocsp">>, <<"issuer_pem">>], SSL3),
?assert(filelib:is_regular(File1)),
?assert(filelib:is_regular(File2)),
?assert(filelib:is_regular(IssuerPem1)),

View File

@ -929,7 +929,7 @@ aggregate_metrics([]) ->
aggregate_metrics([HeadMetrics | AllMetrics]) ->
ErrorLogger = fun(Reason) -> ?SLOG(info, #{msg => "bad_metrics_value", error => Reason}) end,
Fun = fun(ElemMap, AccMap) ->
emqx_map_lib:best_effort_recursive_sum(AccMap, ElemMap, ErrorLogger)
emqx_utils_maps:best_effort_recursive_sum(AccMap, ElemMap, ErrorLogger)
end,
lists:foldl(Fun, HeadMetrics, AllMetrics).
@ -1069,7 +1069,7 @@ update_user(ChainName, AuthenticatorID, UserID, UserInfo0) ->
true ->
serialize_error({missing_parameter, password});
false ->
UserInfo = emqx_map_lib:safe_atom_key_map(UserInfo0),
UserInfo = emqx_utils_maps:safe_atom_key_map(UserInfo0),
case emqx_authentication:update_user(ChainName, AuthenticatorID, UserID, UserInfo) of
{ok, User} ->
{200, User};

View File

@ -403,7 +403,7 @@ aggregate_metrics([]) ->
aggregate_metrics([HeadMetrics | AllMetrics]) ->
ErrorLogger = fun(Reason) -> ?SLOG(info, #{msg => "bad_metrics_value", error => Reason}) end,
Fun = fun(ElemMap, AccMap) ->
emqx_map_lib:best_effort_recursive_sum(AccMap, ElemMap, ErrorLogger)
emqx_utils_maps:best_effort_recursive_sum(AccMap, ElemMap, ErrorLogger)
end,
lists:foldl(Fun, HeadMetrics, AllMetrics).

View File

@ -337,7 +337,7 @@ check_ssl_opts(Conf) ->
(#{<<"url">> := Url} = Source) ->
case emqx_authz_http:parse_url(Url) of
{<<"https", _/binary>>, _, _} ->
case emqx_map_lib:deep_find([<<"ssl">>, <<"enable">>], Source) of
case emqx_utils_maps:deep_find([<<"ssl">>, <<"enable">>], Source) of
{ok, true} -> true;
{ok, false} -> throw({ssl_not_enable, Url});
_ -> throw({ssl_enable_not_found, Url})

View File

@ -207,7 +207,7 @@ send_message(BridgeId, Message) ->
end.
query_opts(Config) ->
case emqx_map_lib:deep_get([resource_opts, request_timeout], Config, false) of
case emqx_utils_maps:deep_get([resource_opts, request_timeout], Config, false) of
Timeout when is_integer(Timeout) ->
%% request_timeout is configured
#{timeout => Timeout};
@ -367,7 +367,7 @@ perform_bridge_changes([{Action, MapConfs} | Tasks], Result0) ->
perform_bridge_changes(Tasks, Result).
diff_confs(NewConfs, OldConfs) ->
emqx_map_lib:diff_maps(
emqx_utils_maps:diff_maps(
flatten_confs(NewConfs),
flatten_confs(OldConfs)
).

View File

@ -1029,5 +1029,5 @@ deobfuscate(NewConf, OldConf) ->
map_to_json(M) ->
emqx_utils_json:encode(
emqx_map_lib:jsonable_map(M, fun(K, V) -> {K, emqx_map_lib:binary_string(V)} end)
emqx_utils_maps:jsonable_map(M, fun(K, V) -> {K, emqx_utils_maps:binary_string(V)} end)
).

View File

@ -186,7 +186,7 @@ update(Type, Name, {OldConf, Conf}, Opts0) ->
%% without restarting the bridge.
%%
Opts = override_start_after_created(Conf, Opts0),
case emqx_map_lib:if_only_to_toggle_enable(OldConf, Conf) of
case emqx_utils_maps:if_only_to_toggle_enable(OldConf, Conf) of
false ->
?SLOG(info, #{
msg => "update bridge",
@ -238,7 +238,7 @@ recreate(Type, Name, Conf, Opts) ->
create_dry_run(Type, Conf0) ->
TmpPath0 = iolist_to_binary([?TEST_ID_PREFIX, emqx_utils:gen_id(8)]),
TmpPath = emqx_utils:safe_filename(TmpPath0),
Conf = emqx_map_lib:safe_atom_key_map(Conf0),
Conf = emqx_utils_maps:safe_atom_key_map(Conf0),
case emqx_connector_ssl:convert_certs(TmpPath, Conf) of
{error, Reason} ->
{error, Reason};

View File

@ -251,7 +251,7 @@ do_convert_webhook_config(
case {MReqTRoot, MReqTResource} of
{{ok, ReqTRoot}, {ok, ReqTResource}} ->
{_Parsed, ReqTRaw} = max({ReqTRoot, ReqTRootRaw}, {ReqTResource, ReqTResourceRaw}),
Conf1 = emqx_map_lib:deep_merge(
Conf1 = emqx_utils_maps:deep_merge(
Conf0,
#{
<<"request_timeout">> => ReqTRaw,

View File

@ -1221,7 +1221,7 @@ t_inconsistent_webhook_request_timeouts(Config) ->
URL1 = ?URL(Port, "path1"),
Name = ?BRIDGE_NAME,
BadBridgeParams =
emqx_map_lib:deep_merge(
emqx_utils_maps:deep_merge(
?HTTP_BRIDGE(URL1, Name),
#{
<<"request_timeout">> => <<"1s">>,

View File

@ -270,7 +270,7 @@ t_mqtt_conn_bridge_ingress_downgrades_qos_2(_) ->
?SERVER_CONF(<<"user1">>)#{
<<"type">> => ?TYPE_MQTT,
<<"name">> => BridgeName,
<<"ingress">> => emqx_map_lib:deep_merge(
<<"ingress">> => emqx_utils_maps:deep_merge(
?INGRESS_CONF,
#{<<"remote">> => #{<<"qos">> => 2}}
)

View File

@ -673,7 +673,7 @@ create_bridge(Config, Overrides) ->
Type = ?BRIDGE_TYPE_BIN,
Name = ?config(kafka_name, Config),
KafkaConfig0 = ?config(kafka_config, Config),
KafkaConfig = emqx_map_lib:deep_merge(KafkaConfig0, Overrides),
KafkaConfig = emqx_utils_maps:deep_merge(KafkaConfig0, Overrides),
emqx_bridge:create(Type, Name, KafkaConfig).
delete_bridge(Config) ->
@ -696,7 +696,7 @@ create_bridge_api(Config, Overrides) ->
TypeBin = ?BRIDGE_TYPE_BIN,
Name = ?config(kafka_name, Config),
KafkaConfig0 = ?config(kafka_config, Config),
KafkaConfig = emqx_map_lib:deep_merge(KafkaConfig0, Overrides),
KafkaConfig = emqx_utils_maps:deep_merge(KafkaConfig0, Overrides),
Params = KafkaConfig#{<<"type">> => TypeBin, <<"name">> => Name},
Path = emqx_mgmt_api_test_util:api_path(["bridges"]),
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
@ -719,7 +719,7 @@ update_bridge_api(Config, Overrides) ->
TypeBin = ?BRIDGE_TYPE_BIN,
Name = ?config(kafka_name, Config),
KafkaConfig0 = ?config(kafka_config, Config),
KafkaConfig = emqx_map_lib:deep_merge(KafkaConfig0, Overrides),
KafkaConfig = emqx_utils_maps:deep_merge(KafkaConfig0, Overrides),
BridgeId = emqx_bridge_resource:bridge_id(TypeBin, Name),
Params = KafkaConfig#{<<"type">> => TypeBin, <<"name">> => Name},
Path = emqx_mgmt_api_test_util:api_path(["bridges", BridgeId]),

View File

@ -92,7 +92,7 @@ kafka_consumer_test() ->
),
%% Bad: can't repeat kafka topics.
BadConf1 = emqx_map_lib:deep_put(
BadConf1 = emqx_utils_maps:deep_put(
[<<"bridges">>, <<"kafka_consumer">>, <<"my_consumer">>, <<"topic_mapping">>],
Conf1,
[
@ -121,7 +121,7 @@ kafka_consumer_test() ->
),
%% Bad: there must be at least 1 mapping.
BadConf2 = emqx_map_lib:deep_put(
BadConf2 = emqx_utils_maps:deep_put(
[<<"bridges">>, <<"kafka_consumer">>, <<"my_consumer">>, <<"topic_mapping">>],
Conf1,
[]

View File

@ -43,50 +43,50 @@ add_handler(ConfKeyPath, HandlerName) ->
remove_handler(ConfKeyPath) ->
emqx_config_handler:remove_handler(ConfKeyPath).
-spec get(emqx_map_lib:config_key_path()) -> term().
-spec get(emqx_utils_maps:config_key_path()) -> term().
get(KeyPath) ->
emqx:get_config(KeyPath).
-spec get(emqx_map_lib:config_key_path(), term()) -> term().
-spec get(emqx_utils_maps:config_key_path(), term()) -> term().
get(KeyPath, Default) ->
emqx:get_config(KeyPath, Default).
-spec get_raw(emqx_map_lib:config_key_path(), term()) -> term().
-spec get_raw(emqx_utils_maps:config_key_path(), term()) -> term().
get_raw(KeyPath, Default) ->
emqx_config:get_raw(KeyPath, Default).
-spec get_raw(emqx_map_lib:config_key_path()) -> term().
-spec get_raw(emqx_utils_maps:config_key_path()) -> term().
get_raw(KeyPath) ->
emqx_config:get_raw(KeyPath).
%% @doc Returns all values in the cluster.
-spec get_all(emqx_map_lib:config_key_path()) -> #{node() => term()}.
-spec get_all(emqx_utils_maps:config_key_path()) -> #{node() => term()}.
get_all(KeyPath) ->
{ResL, []} = emqx_conf_proto_v2:get_all(KeyPath),
maps:from_list(ResL).
%% @doc Returns the specified node's KeyPath, or exception if not found
-spec get_by_node(node(), emqx_map_lib:config_key_path()) -> term().
-spec get_by_node(node(), emqx_utils_maps:config_key_path()) -> term().
get_by_node(Node, KeyPath) when Node =:= node() ->
emqx:get_config(KeyPath);
get_by_node(Node, KeyPath) ->
emqx_conf_proto_v2:get_config(Node, KeyPath).
%% @doc Returns the specified node's KeyPath, or the default value if not found
-spec get_by_node(node(), emqx_map_lib:config_key_path(), term()) -> term().
-spec get_by_node(node(), emqx_utils_maps:config_key_path(), term()) -> term().
get_by_node(Node, KeyPath, Default) when Node =:= node() ->
emqx:get_config(KeyPath, Default);
get_by_node(Node, KeyPath, Default) ->
emqx_conf_proto_v2:get_config(Node, KeyPath, Default).
%% @doc Returns the specified node's KeyPath, or config_not_found if key path not found
-spec get_node_and_config(emqx_map_lib:config_key_path()) -> term().
-spec get_node_and_config(emqx_utils_maps:config_key_path()) -> term().
get_node_and_config(KeyPath) ->
{node(), emqx:get_config(KeyPath, config_not_found)}.
%% @doc Update all value of key path in cluster-override.conf or local-override.conf.
-spec update(
emqx_map_lib:config_key_path(),
emqx_utils_maps:config_key_path(),
emqx_config:update_request(),
emqx_config:update_opts()
) ->
@ -97,7 +97,7 @@ update(KeyPath, UpdateReq, Opts) ->
%% @doc Update the specified node's key path in local-override.conf.
-spec update(
node(),
emqx_map_lib:config_key_path(),
emqx_utils_maps:config_key_path(),
emqx_config:update_request(),
emqx_config:update_opts()
) ->
@ -108,13 +108,13 @@ update(Node, KeyPath, UpdateReq, Opts) ->
emqx_conf_proto_v2:update(Node, KeyPath, UpdateReq, Opts).
%% @doc remove all value of key path in cluster-override.conf or local-override.conf.
-spec remove(emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
-spec remove(emqx_utils_maps:config_key_path(), emqx_config:update_opts()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
remove(KeyPath, Opts) ->
emqx_conf_proto_v2:remove_config(KeyPath, Opts).
%% @doc remove the specified node's key path in local-override.conf.
-spec remove(node(), emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
-spec remove(node(), emqx_utils_maps:config_key_path(), emqx_config:update_opts()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
remove(Node, KeyPath, Opts) when Node =:= node() ->
emqx:remove_config(KeyPath, Opts#{override_to => local});
@ -122,13 +122,13 @@ remove(Node, KeyPath, Opts) ->
emqx_conf_proto_v2:remove_config(Node, KeyPath, Opts).
%% @doc reset all value of key path in cluster-override.conf or local-override.conf.
-spec reset(emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
-spec reset(emqx_utils_maps:config_key_path(), emqx_config:update_opts()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
reset(KeyPath, Opts) ->
emqx_conf_proto_v2:reset(KeyPath, Opts).
%% @doc reset the specified node's key path in local-override.conf.
-spec reset(node(), emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
-spec reset(node(), emqx_utils_maps:config_key_path(), emqx_config:update_opts()) ->
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
reset(Node, KeyPath, Opts) when Node =:= node() ->
emqx:reset_config(KeyPath, Opts#{override_to => local});

View File

@ -38,22 +38,22 @@
-include_lib("emqx/include/bpapi.hrl").
-type update_config_key_path() :: [emqx_map_lib:config_key(), ...].
-type update_config_key_path() :: [emqx_utils_maps:config_key(), ...].
introduced_in() ->
"5.0.0".
-spec get_config(node(), emqx_map_lib:config_key_path()) ->
-spec get_config(node(), emqx_utils_maps:config_key_path()) ->
term() | emqx_rpc:badrpc().
get_config(Node, KeyPath) ->
rpc:call(Node, emqx, get_config, [KeyPath]).
-spec get_config(node(), emqx_map_lib:config_key_path(), _Default) ->
-spec get_config(node(), emqx_utils_maps:config_key_path(), _Default) ->
term() | emqx_rpc:badrpc().
get_config(Node, KeyPath, Default) ->
rpc:call(Node, emqx, get_config, [KeyPath, Default]).
-spec get_all(emqx_map_lib:config_key_path()) -> emqx_rpc:multicall_result().
-spec get_all(emqx_utils_maps:config_key_path()) -> emqx_rpc:multicall_result().
get_all(KeyPath) ->
rpc:multicall(emqx_conf, get_node_and_config, [KeyPath], 5000).

View File

@ -44,19 +44,19 @@ introduced_in() ->
-spec sync_data_from_node(node()) -> {ok, binary()} | emqx_rpc:badrpc().
sync_data_from_node(Node) ->
rpc:call(Node, emqx_conf_app, sync_data_from_node, [], 20000).
-type update_config_key_path() :: [emqx_map_lib:config_key(), ...].
-type update_config_key_path() :: [emqx_utils_maps:config_key(), ...].
-spec get_config(node(), emqx_map_lib:config_key_path()) ->
-spec get_config(node(), emqx_utils_maps:config_key_path()) ->
term() | emqx_rpc:badrpc().
get_config(Node, KeyPath) ->
rpc:call(Node, emqx, get_config, [KeyPath]).
-spec get_config(node(), emqx_map_lib:config_key_path(), _Default) ->
-spec get_config(node(), emqx_utils_maps:config_key_path(), _Default) ->
term() | emqx_rpc:badrpc().
get_config(Node, KeyPath, Default) ->
rpc:call(Node, emqx, get_config, [KeyPath, Default]).
-spec get_all(emqx_map_lib:config_key_path()) -> emqx_rpc:multicall_result().
-spec get_all(emqx_utils_maps:config_key_path()) -> emqx_rpc:multicall_result().
get_all(KeyPath) ->
rpc:multicall(emqx_conf, get_node_and_config, [KeyPath], 5000).

View File

@ -74,7 +74,7 @@ new_ssl_config(Config, _NewSSL) ->
normalize_key_to_bin(undefined) ->
undefined;
normalize_key_to_bin(Map) when is_map(Map) ->
emqx_map_lib:binary_key_map(Map).
emqx_utils_maps:binary_key_map(Map).
try_map_get(Key, Map, Default) when is_map(Map) ->
maps:get(Key, Map, Default);

View File

@ -410,7 +410,7 @@ handle_disconnect(_Reason) ->
ok.
maybe_publish_local(Msg, Vars, Props) ->
case emqx_map_lib:deep_get([local, topic], Vars, undefined) of
case emqx_utils_maps:deep_get([local, topic], Vars, undefined) of
%% local topic is not set, discard it
undefined ->
ok;

View File

@ -119,7 +119,7 @@ remove_handler() ->
pre_config_update(_Path, UpdateConf0, RawConf) ->
UpdateConf = remove_sensitive_data(UpdateConf0),
NewConf = emqx_map_lib:deep_merge(RawConf, UpdateConf),
NewConf = emqx_utils_maps:deep_merge(RawConf, UpdateConf),
ensure_ssl_cert(NewConf).
-define(SENSITIVE_PASSWORD, <<"******">>).
@ -134,7 +134,7 @@ remove_sensitive_data(Conf0) ->
end,
case Conf1 of
#{<<"listeners">> := #{<<"https">> := #{<<"password">> := ?SENSITIVE_PASSWORD}}} ->
emqx_map_lib:deep_remove([<<"listeners">>, <<"https">>, <<"password">>], Conf1);
emqx_utils_maps:deep_remove([<<"listeners">>, <<"https">>, <<"password">>], Conf1);
_ ->
Conf1
end.
@ -152,7 +152,7 @@ post_config_update(_, _Req, NewConf, OldConf, _AppEnvs) ->
ok.
get_listener(Type, Conf) ->
emqx_map_lib:deep_get([listeners, Type], Conf, undefined).
emqx_utils_maps:deep_get([listeners, Type], Conf, undefined).
diff_listeners(_, Listener, Listener) -> {#{}, #{}};
diff_listeners(Type, undefined, Start) -> {#{}, #{Type => Start}};
@ -162,13 +162,14 @@ diff_listeners(Type, Stop, Start) -> {#{Type => Stop}, #{Type => Start}}.
-define(DIR, <<"dashboard">>).
ensure_ssl_cert(#{<<"listeners">> := #{<<"https">> := #{<<"enable">> := true}}} = Conf) ->
Https = emqx_map_lib:deep_get([<<"listeners">>, <<"https">>], Conf, undefined),
Https = emqx_utils_maps:deep_get([<<"listeners">>, <<"https">>], Conf, undefined),
Opts = #{required_keys => [[<<"keyfile">>], [<<"certfile">>], [<<"cacertfile">>]]},
case emqx_tls_lib:ensure_ssl_files(?DIR, Https, Opts) of
{ok, undefined} ->
{error, <<"ssl_cert_not_found">>};
{ok, NewHttps} ->
{ok, emqx_map_lib:deep_merge(Conf, #{<<"listeners">> => #{<<"https">> => NewHttps}})};
{ok,
emqx_utils_maps:deep_merge(Conf, #{<<"listeners">> => #{<<"https">> => NewHttps}})};
{error, Reason} ->
?SLOG(error, Reason#{msg => "bad_ssl_config"}),
{error, Reason}

View File

@ -474,7 +474,7 @@ maybe_add_summary_from_label(Spec, Hocon) ->
get_i18n(Key, Struct, Default) ->
{ok, #{cache := Cache, lang := Lang}} = emqx_dashboard:get_i18n(),
Desc = hocon_schema:resolve_schema(Struct, Cache),
emqx_map_lib:deep_get([Key, Lang], Desc, Default).
emqx_utils_maps:deep_get([Key, Lang], Desc, Default).
trans_label(Spec, Hocon, Default) ->
Label =

View File

@ -507,11 +507,11 @@ sort_name_by_order(Names, Orders) ->
lists:sort(
fun
(A, B) when is_binary(A) ->
emqx_map_lib:deep_get([A, order], Orders) <
emqx_map_lib:deep_get([B, order], Orders);
emqx_utils_maps:deep_get([A, order], Orders) <
emqx_utils_maps:deep_get([B, order], Orders);
(#{name := A}, #{name := B}) ->
emqx_map_lib:deep_get([A, order], Orders) <
emqx_map_lib:deep_get([B, order], Orders)
emqx_utils_maps:deep_get([A, order], Orders) <
emqx_utils_maps:deep_get([B, order], Orders)
end,
Names
).

View File

@ -311,7 +311,7 @@ t_update(Cfg) ->
decode_json(Data) ->
BinJosn = emqx_utils_json:decode(Data, [return_maps]),
emqx_map_lib:unsafe_atom_key_map(BinJosn).
emqx_utils_maps:unsafe_atom_key_map(BinJosn).
request_api(Method, Url, Auth) ->
request_api(Method, Url, [], Auth, []).

View File

@ -96,7 +96,7 @@ listeners(post, #{bindings := #{name := Name0}, body := LConf}) ->
LName = binary_to_atom(maps:get(<<"name">>, LConf)),
Path = [listeners, Type, LName],
case emqx_map_lib:deep_get(Path, RunningConf, undefined) of
case emqx_utils_maps:deep_get(Path, RunningConf, undefined) of
undefined ->
ListenerId = emqx_gateway_utils:listener_id(
GwName, Type, LName

View File

@ -106,7 +106,7 @@ unconvert_listeners(Ls) when is_list(Ls) ->
{[Type, Name], Lis1} = maps_key_take([<<"type">>, <<"name">>], Lis),
_ = vaildate_listener_name(Name),
NLis1 = maps:without([<<"id">>, <<"running">>], Lis1),
emqx_map_lib:deep_merge(Acc, #{Type => #{Name => NLis1}})
emqx_utils_maps:deep_merge(Acc, #{Type => #{Name => NLis1}})
end,
#{},
Ls
@ -160,8 +160,8 @@ gateway(GwName0) ->
RawConf = emqx_config:fill_defaults(
emqx_config:get_root_raw(Path)
),
Confs = emqx_map_lib:jsonable_map(
emqx_map_lib:deep_get(Path, RawConf)
Confs = emqx_utils_maps:jsonable_map(
emqx_utils_maps:deep_get(Path, RawConf)
),
LsConf = maps:get(<<"listeners">>, Confs, #{}),
Confs#{<<"listeners">> => convert_listeners(GwName, LsConf)}.
@ -198,8 +198,8 @@ listeners(GwName0) ->
RawConf = emqx_config:fill_defaults(
emqx_config:get_root_raw([<<"gateway">>])
),
Listeners = emqx_map_lib:jsonable_map(
emqx_map_lib:deep_get(
Listeners = emqx_utils_maps:jsonable_map(
emqx_utils_maps:deep_get(
[<<"gateway">>, GwName, <<"listeners">>], RawConf
)
),
@ -213,12 +213,12 @@ listener(ListenerId) ->
),
try
Path = [<<"gateway">>, GwName, <<"listeners">>, Type, LName],
LConf = emqx_map_lib:deep_get(Path, RootConf),
LConf = emqx_utils_maps:deep_get(Path, RootConf),
Running = emqx_gateway_utils:is_running(
binary_to_existing_atom(ListenerId), LConf
),
{ok,
emqx_map_lib:jsonable_map(
emqx_utils_maps:jsonable_map(
LConf#{
id => ListenerId,
type => Type,
@ -305,8 +305,8 @@ ret_ok_err({ok, _}) -> ok;
ret_ok_err(Err) -> Err.
ret_gw(GwName, {ok, #{raw_config := GwConf}}) ->
GwConf1 = emqx_map_lib:deep_get([bin(GwName)], GwConf),
LsConf = emqx_map_lib:deep_get(
GwConf1 = emqx_utils_maps:deep_get([bin(GwName)], GwConf),
LsConf = emqx_utils_maps:deep_get(
[bin(GwName), <<"listeners">>],
GwConf,
#{}
@ -331,7 +331,7 @@ ret_gw(_GwName, Err) ->
Err.
ret_authn(GwName, {ok, #{raw_config := GwConf}}) ->
Authn = emqx_map_lib:deep_get(
Authn = emqx_utils_maps:deep_get(
[bin(GwName), <<"authentication">>],
GwConf
),
@ -340,7 +340,7 @@ ret_authn(_GwName, Err) ->
Err.
ret_authn(GwName, {LType, LName}, {ok, #{raw_config := GwConf}}) ->
Authn = emqx_map_lib:deep_get(
Authn = emqx_utils_maps:deep_get(
[
bin(GwName),
<<"listeners">>,
@ -355,7 +355,7 @@ ret_authn(_, _, Err) ->
Err.
ret_listener_or_err(GwName, {LType, LName}, {ok, #{raw_config := GwConf}}) ->
LConf = emqx_map_lib:deep_get(
LConf = emqx_utils_maps:deep_get(
[bin(GwName), <<"listeners">>, bin(LType), bin(LName)],
GwConf
),
@ -377,7 +377,7 @@ pre_config_update(_, {load_gateway, GwName, Conf}, RawConf) ->
case maps:get(GwName, RawConf, undefined) of
undefined ->
NConf = tune_gw_certs(fun convert_certs/2, GwName, Conf),
{ok, emqx_map_lib:deep_put([GwName], RawConf, NConf)};
{ok, emqx_utils_maps:deep_put([GwName], RawConf, NConf)};
_ ->
badres_gateway(already_exist, GwName)
end;
@ -389,7 +389,7 @@ pre_config_update(_, {update_gateway, GwName, Conf}, RawConf) ->
Conf1 = maps:without([<<"listeners">>, ?AUTHN_BIN], Conf),
NConf = tune_gw_certs(fun convert_certs/2, GwName, Conf1),
NConf1 = maps:merge(GwRawConf, NConf),
{ok, emqx_map_lib:deep_put([GwName], RawConf, NConf1)}
{ok, emqx_utils_maps:deep_put([GwName], RawConf, NConf1)}
end;
pre_config_update(_, {unload_gateway, GwName}, RawConf) ->
_ = tune_gw_certs(
@ -400,7 +400,7 @@ pre_config_update(_, {unload_gateway, GwName}, RawConf) ->
{ok, maps:remove(GwName, RawConf)};
pre_config_update(_, {add_listener, GwName, {LType, LName}, Conf}, RawConf) ->
case
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[GwName, <<"listeners">>, LType, LName], RawConf, undefined
)
of
@ -408,7 +408,7 @@ pre_config_update(_, {add_listener, GwName, {LType, LName}, Conf}, RawConf) ->
NConf = convert_certs(certs_dir(GwName), Conf),
NListener = #{LType => #{LName => NConf}},
{ok,
emqx_map_lib:deep_merge(
emqx_utils_maps:deep_merge(
RawConf,
#{GwName => #{<<"listeners">> => NListener}}
)};
@ -417,7 +417,7 @@ pre_config_update(_, {add_listener, GwName, {LType, LName}, Conf}, RawConf) ->
end;
pre_config_update(_, {update_listener, GwName, {LType, LName}, Conf}, RawConf) ->
case
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[GwName, <<"listeners">>, LType, LName], RawConf, undefined
)
of
@ -425,7 +425,7 @@ pre_config_update(_, {update_listener, GwName, {LType, LName}, Conf}, RawConf) -
badres_listener(not_found, GwName, LType, LName);
OldConf ->
NConf = convert_certs(certs_dir(GwName), Conf, OldConf),
NRawConf = emqx_map_lib:deep_put(
NRawConf = emqx_utils_maps:deep_put(
[GwName, <<"listeners">>, LType, LName],
RawConf,
NConf
@ -434,22 +434,22 @@ pre_config_update(_, {update_listener, GwName, {LType, LName}, Conf}, RawConf) -
end;
pre_config_update(_, {remove_listener, GwName, {LType, LName}}, RawConf) ->
Path = [GwName, <<"listeners">>, LType, LName],
case emqx_map_lib:deep_get(Path, RawConf, undefined) of
case emqx_utils_maps:deep_get(Path, RawConf, undefined) of
undefined ->
{ok, RawConf};
OldConf ->
clear_certs(certs_dir(GwName), OldConf),
{ok, emqx_map_lib:deep_remove(Path, RawConf)}
{ok, emqx_utils_maps:deep_remove(Path, RawConf)}
end;
pre_config_update(_, {add_authn, GwName, Conf}, RawConf) ->
case
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[GwName, ?AUTHN_BIN], RawConf, undefined
)
of
undefined ->
{ok,
emqx_map_lib:deep_merge(
emqx_utils_maps:deep_merge(
RawConf,
#{GwName => #{?AUTHN_BIN => Conf}}
)};
@ -458,7 +458,7 @@ pre_config_update(_, {add_authn, GwName, Conf}, RawConf) ->
end;
pre_config_update(_, {add_authn, GwName, {LType, LName}, Conf}, RawConf) ->
case
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[GwName, <<"listeners">>, LType, LName],
RawConf,
undefined
@ -477,25 +477,25 @@ pre_config_update(_, {add_authn, GwName, {LType, LName}, Conf}, RawConf) ->
#{LType => #{LName => NListener}}
}
},
{ok, emqx_map_lib:deep_merge(RawConf, NGateway)};
{ok, emqx_utils_maps:deep_merge(RawConf, NGateway)};
_ ->
badres_listener_authn(already_exist, GwName, LType, LName)
end
end;
pre_config_update(_, {update_authn, GwName, Conf}, RawConf) ->
case
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[GwName, ?AUTHN_BIN], RawConf, undefined
)
of
undefined ->
badres_authn(not_found, GwName);
_Authn ->
{ok, emqx_map_lib:deep_put([GwName, ?AUTHN_BIN], RawConf, Conf)}
{ok, emqx_utils_maps:deep_put([GwName, ?AUTHN_BIN], RawConf, Conf)}
end;
pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) ->
case
emqx_map_lib:deep_get(
emqx_utils_maps:deep_get(
[GwName, <<"listeners">>, LType, LName],
RawConf,
undefined
@ -514,7 +514,7 @@ pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) ->
Listener
),
{ok,
emqx_map_lib:deep_put(
emqx_utils_maps:deep_put(
[GwName, <<"listeners">>, LType, LName],
RawConf,
NListener
@ -523,12 +523,12 @@ pre_config_update(_, {update_authn, GwName, {LType, LName}, Conf}, RawConf) ->
end;
pre_config_update(_, {remove_authn, GwName}, RawConf) ->
{ok,
emqx_map_lib:deep_remove(
emqx_utils_maps:deep_remove(
[GwName, ?AUTHN_BIN], RawConf
)};
pre_config_update(_, {remove_authn, GwName, {LType, LName}}, RawConf) ->
Path = [GwName, <<"listeners">>, LType, LName, ?AUTHN_BIN],
{ok, emqx_map_lib:deep_remove(Path, RawConf)};
{ok, emqx_utils_maps:deep_remove(Path, RawConf)};
pre_config_update(_, UnknownReq, _RawConf) ->
logger:error("Unknown configuration update request: ~0p", [UnknownReq]),
{error, badreq}.

View File

@ -240,7 +240,7 @@ authn(GwName) ->
ChainName = emqx_gateway_utils:global_chain(GwName),
wrap_chain_name(
ChainName,
emqx_map_lib:jsonable_map(emqx:get_raw_config(Path))
emqx_utils_maps:jsonable_map(emqx:get_raw_config(Path))
).
-spec authn(gateway_name(), binary()) -> map().
@ -250,7 +250,7 @@ authn(GwName, ListenerId) ->
ChainName = emqx_gateway_utils:listener_chain(GwName, Type, Name),
wrap_chain_name(
ChainName,
emqx_map_lib:jsonable_map(emqx:get_raw_config(Path))
emqx_utils_maps:jsonable_map(emqx:get_raw_config(Path))
).
wrap_chain_name(ChainName, Conf) ->

View File

@ -164,7 +164,7 @@ t_gateway_stomp(_) ->
{204, _} = request(put, "/gateways/stomp", GwConf),
{200, ConfResp} = request(get, "/gateways/stomp"),
assert_confs(GwConf, ConfResp),
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{frame => #{max_headers => 10}}),
GwConf2 = emqx_utils_maps:deep_merge(GwConf, #{frame => #{max_headers => 10}}),
{204, _} = request(put, "/gateways/stomp", maps:without([name, listeners], GwConf2)),
{200, ConfResp2} = request(get, "/gateways/stomp"),
assert_confs(GwConf2, ConfResp2),
@ -186,7 +186,7 @@ t_gateway_mqttsn(_) ->
{204, _} = request(put, "/gateways/mqttsn", GwConf),
{200, ConfResp} = request(get, "/gateways/mqttsn"),
assert_confs(GwConf, ConfResp),
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{predefined => []}),
GwConf2 = emqx_utils_maps:deep_merge(GwConf, #{predefined => []}),
{204, _} = request(put, "/gateways/mqttsn", maps:without([name, listeners], GwConf2)),
{200, ConfResp2} = request(get, "/gateways/mqttsn"),
assert_confs(GwConf2, ConfResp2),
@ -206,7 +206,7 @@ t_gateway_coap(_) ->
{204, _} = request(put, "/gateways/coap", GwConf),
{200, ConfResp} = request(get, "/gateways/coap"),
assert_confs(GwConf, ConfResp),
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{heartbeat => <<"10s">>}),
GwConf2 = emqx_utils_maps:deep_merge(GwConf, #{heartbeat => <<"10s">>}),
{204, _} = request(put, "/gateways/coap", maps:without([name, listeners], GwConf2)),
{200, ConfResp2} = request(get, "/gateways/coap"),
assert_confs(GwConf2, ConfResp2),
@ -244,7 +244,7 @@ t_gateway_lwm2m(_) ->
{204, _} = request(put, "/gateways/lwm2m", GwConf),
{200, ConfResp} = request(get, "/gateways/lwm2m"),
assert_confs(GwConf, ConfResp),
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{qmode_time_window => <<"10s">>}),
GwConf2 = emqx_utils_maps:deep_merge(GwConf, #{qmode_time_window => <<"10s">>}),
{204, _} = request(put, "/gateways/lwm2m", maps:without([name, listeners], GwConf2)),
{200, ConfResp2} = request(get, "/gateways/lwm2m"),
assert_confs(GwConf2, ConfResp2),
@ -264,7 +264,7 @@ t_gateway_exproto(_) ->
{204, _} = request(put, "/gateways/exproto", GwConf),
{200, ConfResp} = request(get, "/gateways/exproto"),
assert_confs(GwConf, ConfResp),
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{server => #{bind => <<"9200">>}}),
GwConf2 = emqx_utils_maps:deep_merge(GwConf, #{server => #{bind => <<"9200">>}}),
{204, _} = request(put, "/gateways/exproto", maps:without([name, listeners], GwConf2)),
{200, ConfResp2} = request(get, "/gateways/exproto"),
assert_confs(GwConf2, ConfResp2),
@ -293,7 +293,7 @@ t_gateway_exproto_with_ssl(_) ->
{204, _} = request(put, "/gateways/exproto", GwConf),
{200, ConfResp} = request(get, "/gateways/exproto"),
assert_confs(GwConf, ConfResp),
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{
GwConf2 = emqx_utils_maps:deep_merge(GwConf, #{
server => #{
bind => <<"9200">>,
ssl_options => SslCliOpts

View File

@ -282,7 +282,7 @@ t_case_exproto(_) ->
disable_authn(GwName, Type, Name) ->
RawCfg = emqx_conf:get_raw([gateway, GwName], #{}),
ListenerCfg = emqx_map_lib:deep_get(
ListenerCfg = emqx_utils_maps:deep_get(
[<<"listeners">>, atom_to_binary(Type), atom_to_binary(Name)], RawCfg
),
{ok, _} = emqx_gateway_conf:update_listener(GwName, {Type, Name}, ListenerCfg#{

View File

@ -413,7 +413,7 @@ t_load_gateway_with_certs_content(_) ->
),
{ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
SslConf = emqx_map_lib:deep_get(
SslConf = emqx_utils_maps:deep_get(
[<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl_options">>],
emqx:get_raw_config([gateway, stomp])
),
@ -436,7 +436,7 @@ t_load_gateway_with_certs_content(_) ->
% ),
% {ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
% assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
% SslConf = emqx_map_lib:deep_get(
% SslConf = emqx_utils_maps:deep_get(
% [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl_options">>],
% emqx:get_raw_config([gateway, stomp])
% ),
@ -471,7 +471,7 @@ t_add_listener_with_certs_content(_) ->
emqx:get_raw_config([gateway, stomp])
),
SslConf = emqx_map_lib:deep_get(
SslConf = emqx_utils_maps:deep_get(
[<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl_options">>],
emqx:get_raw_config([gateway, stomp])
),

View File

@ -159,7 +159,7 @@ do_request(Mth, Req) ->
<<>> ->
#{};
_ ->
emqx_map_lib:unsafe_atom_key_map(
emqx_utils_maps:unsafe_atom_key_map(
emqx_utils_json:decode(Resp, [return_maps])
)
end,

View File

@ -149,7 +149,7 @@ start_grpc_server(GwName, Options = #{bind := ListenOn}) ->
}
},
SvrOptions =
case emqx_map_lib:deep_get([ssl, enable], Options, false) of
case emqx_utils_maps:deep_get([ssl, enable], Options, false) of
false ->
[];
true ->
@ -201,7 +201,7 @@ start_grpc_client_channel(GwName, Options = #{address := Address}) ->
}}
)
end,
case emqx_map_lib:deep_get([ssl, enable], Options, false) of
case emqx_utils_maps:deep_get([ssl, enable], Options, false) of
false ->
SvrAddr = compose_http_uri(http, Host, Port),
grpc_client_sup:create_channel_pool(GwName, SvrAddr, #{});

View File

@ -860,8 +860,8 @@ format_channel_info(ChannInfo = {_, _ClientInfo, _ClientStats}) ->
format_channel_info(WhichNode, {_, ClientInfo0, ClientStats}) ->
Node = maps:get(node, ClientInfo0, WhichNode),
ClientInfo1 = emqx_map_lib:deep_remove([conninfo, clientid], ClientInfo0),
ClientInfo2 = emqx_map_lib:deep_remove([conninfo, username], ClientInfo1),
ClientInfo1 = emqx_utils_maps:deep_remove([conninfo, clientid], ClientInfo0),
ClientInfo2 = emqx_utils_maps:deep_remove([conninfo, username], ClientInfo1),
StatsMap = maps:without(
[memory, next_pkt_id, total_heap_size],
maps:from_list(ClientStats)
@ -958,4 +958,4 @@ format_authz_cache({{PubSub, Topic}, {AuthzResult, Timestamp}}) ->
to_topic_info(Data) ->
M = maps:with([<<"topic">>, <<"qos">>, <<"nl">>, <<"rap">>, <<"rh">>], Data),
emqx_map_lib:safe_atom_key_map(M).
emqx_utils_maps:safe_atom_key_map(M).

View File

@ -215,7 +215,7 @@ fields(Field) ->
%% HTTP API Callbacks
config(get, _Params, Req) ->
Path = conf_path(Req),
{ok, Conf} = emqx_map_lib:deep_find(Path, get_full_config()),
{ok, Conf} = emqx_utils_maps:deep_find(Path, get_full_config()),
{200, Conf};
config(put, #{body := Body}, Req) ->
Path = conf_path(Req),
@ -349,7 +349,7 @@ gen_schema(_Conf) ->
#{type => string}.
with_default_value(Type, Value) ->
Type#{example => emqx_map_lib:binary_string(Value)}.
Type#{example => emqx_utils_maps:binary_string(Value)}.
global_zone_roots() ->
lists:map(fun({K, _}) -> K end, global_zone_schema()).

View File

@ -390,7 +390,7 @@ crud_listeners_by_id(put, #{bindings := #{id := Id}, body := Body0}) ->
undefined ->
{404, #{code => 'BAD_LISTENER_ID', message => ?LISTENER_NOT_FOUND}};
PrevConf ->
MergeConfT = emqx_map_lib:deep_merge(PrevConf, Conf),
MergeConfT = emqx_utils_maps:deep_merge(PrevConf, Conf),
MergeConf = emqx_listeners:ensure_override_limiter_conf(MergeConfT, Conf),
case update(Path, MergeConf) of
{ok, #{raw_config := _RawConf}} ->

View File

@ -55,7 +55,7 @@ t_update(_Config) ->
%% update ok
{ok, SysMon} = get_config(<<"sysmon">>),
#{<<"vm">> := #{<<"busy_port">> := BusyPort}} = SysMon,
NewSysMon = emqx_map_lib:deep_put([<<"vm">>, <<"busy_port">>], SysMon, not BusyPort),
NewSysMon = emqx_utils_maps:deep_put([<<"vm">>, <<"busy_port">>], SysMon, not BusyPort),
{ok, #{}} = update_config(<<"sysmon">>, NewSysMon),
{ok, SysMon1} = get_config(<<"sysmon">>),
#{<<"vm">> := #{<<"busy_port">> := BusyPort1}} = SysMon1,
@ -63,7 +63,7 @@ t_update(_Config) ->
assert_busy_port(BusyPort1),
%% update failed
ErrorSysMon = emqx_map_lib:deep_put([<<"vm">>, <<"busy_port">>], SysMon, "123"),
ErrorSysMon = emqx_utils_maps:deep_put([<<"vm">>, <<"busy_port">>], SysMon, "123"),
?assertMatch(
{error, {"HTTP/1.1", 400, _}},
update_config(<<"sysmon">>, ErrorSysMon)
@ -78,7 +78,7 @@ t_update(_Config) ->
assert_busy_port(true),
%% reset no_default_value config
NewSysMon1 = emqx_map_lib:deep_put([<<"vm">>, <<"busy_port">>], SysMon, false),
NewSysMon1 = emqx_utils_maps:deep_put([<<"vm">>, <<"busy_port">>], SysMon, false),
{ok, #{}} = update_config(<<"sysmon">>, NewSysMon1),
?assertMatch({error, {"HTTP/1.1", 400, _}}, reset_config(<<"sysmon">>, "")),
{ok, SysMon4} = get_config(<<"sysmon">>),
@ -94,27 +94,33 @@ t_log(_Config) ->
{ok, Log} = get_config("log"),
File = "log/emqx-test.log",
%% update handler
Log1 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, true),
Log2 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"default">>, <<"file">>], Log1, File),
Log1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, true),
Log2 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"file">>], Log1, File),
{ok, #{}} = update_config(<<"log">>, Log2),
{ok, Log3} = logger:get_handler_config(default),
?assertMatch(#{config := #{file := File}}, Log3),
ErrLog1 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, 1),
ErrLog1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, 1),
?assertMatch({error, {"HTTP/1.1", 400, _}}, update_config(<<"log">>, ErrLog1)),
ErrLog2 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"default">>, <<"enabfe">>], Log, true),
ErrLog2 = emqx_utils_maps:deep_put(
[<<"file_handlers">>, <<"default">>, <<"enabfe">>], Log, true
),
?assertMatch({error, {"HTTP/1.1", 400, _}}, update_config(<<"log">>, ErrLog2)),
%% add new handler
File1 = "log/emqx-test1.log",
Handler = emqx_map_lib:deep_get([<<"file_handlers">>, <<"default">>], Log2),
NewLog1 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"new">>], Log2, Handler),
NewLog2 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"new">>, <<"file">>], NewLog1, File1),
Handler = emqx_utils_maps:deep_get([<<"file_handlers">>, <<"default">>], Log2),
NewLog1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"new">>], Log2, Handler),
NewLog2 = emqx_utils_maps:deep_put(
[<<"file_handlers">>, <<"new">>, <<"file">>], NewLog1, File1
),
{ok, #{}} = update_config(<<"log">>, NewLog2),
{ok, Log4} = logger:get_handler_config(new),
?assertMatch(#{config := #{file := File1}}, Log4),
%% disable new handler
Disable = emqx_map_lib:deep_put([<<"file_handlers">>, <<"new">>, <<"enable">>], NewLog2, false),
Disable = emqx_utils_maps:deep_put(
[<<"file_handlers">>, <<"new">>, <<"enable">>], NewLog2, false
),
{ok, #{}} = update_config(<<"log">>, Disable),
?assertEqual({error, {not_found, new}}, logger:get_handler_config(new)),
ok.
@ -125,25 +131,25 @@ t_global_zone(_Config) ->
?assertEqual(lists:usort(ZonesKeys), lists:usort(maps:keys(Zones))),
?assertEqual(
emqx_config:get_zone_conf(no_default, [mqtt, max_qos_allowed]),
emqx_map_lib:deep_get([<<"mqtt">>, <<"max_qos_allowed">>], Zones)
emqx_utils_maps:deep_get([<<"mqtt">>, <<"max_qos_allowed">>], Zones)
),
NewZones = emqx_map_lib:deep_put([<<"mqtt">>, <<"max_qos_allowed">>], Zones, 1),
NewZones = emqx_utils_maps:deep_put([<<"mqtt">>, <<"max_qos_allowed">>], Zones, 1),
{ok, #{}} = update_global_zone(NewZones),
?assertEqual(1, emqx_config:get_zone_conf(no_default, [mqtt, max_qos_allowed])),
BadZones = emqx_map_lib:deep_put([<<"mqtt">>, <<"max_qos_allowed">>], Zones, 3),
BadZones = emqx_utils_maps:deep_put([<<"mqtt">>, <<"max_qos_allowed">>], Zones, 3),
?assertMatch({error, {"HTTP/1.1", 400, _}}, update_global_zone(BadZones)),
%% Remove max_qos_allowed from raw config, but we still get default value(2).
Mqtt0 = emqx_conf:get_raw([<<"mqtt">>]),
?assertEqual(1, emqx_map_lib:deep_get([<<"max_qos_allowed">>], Mqtt0)),
?assertEqual(1, emqx_utils_maps:deep_get([<<"max_qos_allowed">>], Mqtt0)),
Mqtt1 = maps:remove(<<"max_qos_allowed">>, Mqtt0),
ok = emqx_config:put_raw([<<"mqtt">>], Mqtt1),
Mqtt2 = emqx_conf:get_raw([<<"mqtt">>]),
?assertNot(maps:is_key(<<"max_qos_allowed">>, Mqtt2), Mqtt2),
{ok, #{<<"mqtt">> := Mqtt3}} = get_global_zone(),
%% the default value is 2
?assertEqual(2, emqx_map_lib:deep_get([<<"max_qos_allowed">>], Mqtt3)),
?assertEqual(2, emqx_utils_maps:deep_get([<<"max_qos_allowed">>], Mqtt3)),
ok = emqx_config:put_raw([<<"mqtt">>], Mqtt0),
ok.

View File

@ -193,10 +193,10 @@ t_clear_certs(Config) when is_list(Config) ->
},
%% create, make sure the cert files are created
NewConf = emqx_map_lib:deep_put(
NewConf = emqx_utils_maps:deep_put(
[<<"ssl_options">>, <<"certfile">>], ConfTemp, cert_file("certfile")
),
NewConf2 = emqx_map_lib:deep_put(
NewConf2 = emqx_utils_maps:deep_put(
[<<"ssl_options">>, <<"keyfile">>], NewConf, cert_file("keyfile")
),
@ -205,7 +205,7 @@ t_clear_certs(Config) when is_list(Config) ->
?assertMatch({ok, [_, _]}, ListResult1),
%% update
UpdateConf = emqx_map_lib:deep_put(
UpdateConf = emqx_utils_maps:deep_put(
[<<"ssl_options">>, <<"keyfile">>], NewConf2, cert_file("keyfile2")
),
_ = request(put, NewPath, [], UpdateConf),

View File

@ -34,8 +34,8 @@ init_per_testcase(t_log_path, Config) ->
emqx_config_logger:add_handler(),
Log = emqx_conf:get_raw([log], #{}),
File = "log/emqx-test.log",
Log1 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, true),
Log2 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"default">>, <<"file">>], Log1, File),
Log1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, true),
Log2 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"file">>], Log1, File),
{ok, #{}} = emqx_conf:update([log], Log2, #{rawconf_with_defaults => true}),
Config;
init_per_testcase(_, Config) ->
@ -43,7 +43,7 @@ init_per_testcase(_, Config) ->
end_per_testcase(t_log_path, Config) ->
Log = emqx_conf:get_raw([log], #{}),
Log1 = emqx_map_lib:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, false),
Log1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, false),
{ok, #{}} = emqx_conf:update([log], Log1, #{rawconf_with_defaults => true}),
emqx_config_logger:remove_handler(),
Config;

View File

@ -230,7 +230,7 @@ t_large_payload(_) ->
decode_json(Data) ->
BinJson = emqx_utils_json:decode(Data, [return_maps]),
emqx_map_lib:unsafe_atom_key_map(BinJson).
emqx_utils_maps:unsafe_atom_key_map(BinJson).
clear_all_record() ->
ets:delete_all_objects(emqx_delayed).

View File

@ -156,7 +156,7 @@ handle_cast({dispatch, Context, Pid, Topic}, #{limiter := Limiter} = State) ->
{ok, Limiter2} = dispatch(Context, Pid, Topic, undefined, Limiter),
{noreply, State#{limiter := Limiter2}};
handle_cast({refresh_limiter, Conf}, State) ->
BucketCfg = emqx_map_lib:deep_get([flow_control, batch_deliver_limiter], Conf, undefined),
BucketCfg = emqx_utils_maps:deep_get([flow_control, batch_deliver_limiter], Conf, undefined),
{ok, Limiter} = emqx_limiter_server:connect(?APP, internal, BucketCfg),
{noreply, State#{limiter := Limiter}};
handle_cast(Msg, State) ->

View File

@ -257,7 +257,7 @@ t_change_storage_type(_Config) ->
#{data := Msgs0, meta := _} = decode_json(MsgsJson0),
?assertEqual(1, length(Msgs0)),
ChangedConf = emqx_map_lib:deep_merge(
ChangedConf = emqx_utils_maps:deep_merge(
RawConf,
#{
<<"backend">> =>
@ -312,7 +312,7 @@ t_change_storage_type(_Config) ->
%%--------------------------------------------------------------------
decode_json(Data) ->
BinJson = emqx_utils_json:decode(Data, [return_maps]),
emqx_map_lib:unsafe_atom_key_map(BinJson).
emqx_utils_maps:unsafe_atom_key_map(BinJson).
%%--------------------------------------------------------------------
%% Internal funcs

View File

@ -115,7 +115,7 @@ start_link() ->
%%------------------------------------------------------------------------------
post_config_update(_, _Req, NewRules, OldRules, _AppEnvs) ->
#{added := Added, removed := Removed, changed := Updated} =
emqx_map_lib:diff_maps(NewRules, OldRules),
emqx_utils_maps:diff_maps(NewRules, OldRules),
maps_foreach(
fun({Id, {_Old, New}}) ->
{ok, _} = update_rule(New#{id => bin(Id)})

View File

@ -166,7 +166,7 @@ t_settting(_) ->
decode_json(Data) ->
BinJosn = emqx_utils_json:decode(Data, [return_maps]),
emqx_map_lib:unsafe_atom_key_map(BinJosn).
emqx_utils_maps:unsafe_atom_key_map(BinJosn).
request_api(Method, Url, Auth) ->
request_api(Method, Url, [], Auth, []).

View File

@ -13,7 +13,7 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_map_lib).
-module(emqx_utils_maps).
-export([
deep_get/2,
@ -332,7 +332,7 @@ deep_filter(M, F) when is_map(M) ->
if_only_to_toggle_enable(OldConf, Conf) ->
#{added := Added, removed := Removed, changed := Updated} =
emqx_map_lib:diff_maps(OldConf, Conf),
emqx_utils_maps:diff_maps(OldConf, Conf),
case {Added, Removed, Updated} of
{Added, Removed, #{enable := _} = Updated} when
map_size(Added) =:= 0,

View File

@ -14,7 +14,7 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_map_lib_tests).
-module(emqx_utils_maps_tests).
-include_lib("eunit/include/eunit.hrl").
best_effort_recursive_sum_test_() ->
@ -22,21 +22,21 @@ best_effort_recursive_sum_test_() ->
[
?_assertEqual(
#{foo => 3},
emqx_map_lib:best_effort_recursive_sum(#{foo => 1}, #{foo => 2}, DummyLogger)
emqx_utils_maps:best_effort_recursive_sum(#{foo => 1}, #{foo => 2}, DummyLogger)
),
?_assertEqual(
#{foo => 3, bar => 6.0},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => 1, bar => 2.0}, #{foo => 2, bar => 4.0}, DummyLogger
)
),
?_assertEqual(
#{foo => 1, bar => 2},
emqx_map_lib:best_effort_recursive_sum(#{foo => 1}, #{bar => 2}, DummyLogger)
emqx_utils_maps:best_effort_recursive_sum(#{foo => 1}, #{bar => 2}, DummyLogger)
),
?_assertEqual(
#{foo => #{bar => 42}},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => #{bar => 2}}, #{foo => #{bar => 40}}, DummyLogger
)
),
@ -45,7 +45,9 @@ best_effort_recursive_sum_test_() ->
Logger = fun(What) -> Self ! {log, What} end,
?assertEqual(
#{foo => 1, bar => 2},
emqx_map_lib:best_effort_recursive_sum(#{foo => 1, bar => 2}, #{bar => bar}, Logger)
emqx_utils_maps:best_effort_recursive_sum(
#{foo => 1, bar => 2}, #{bar => bar}, Logger
)
),
receive
{log, Log} ->
@ -55,55 +57,55 @@ best_effort_recursive_sum_test_() ->
end,
?_assertEqual(
#{},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => foo}, #{foo => bar}, DummyLogger
)
),
?_assertEqual(
#{foo => 1},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => 1}, #{foo => bar}, DummyLogger
)
),
?_assertEqual(
#{foo => 1},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => bar}, #{foo => 1}, DummyLogger
)
),
?_assertEqual(
#{foo => #{bar => 1}},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => #{bar => 1}}, #{foo => 1}, DummyLogger
)
),
?_assertEqual(
#{foo => #{bar => 1}},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => 1}, #{foo => #{bar => 1}}, DummyLogger
)
),
?_assertEqual(
#{foo => #{bar => 1}},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => 1, bar => ignored}, #{foo => #{bar => 1}}, DummyLogger
)
),
?_assertEqual(
#{foo => #{bar => 2}, bar => #{foo => 1}},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => 1, bar => #{foo => 1}}, #{foo => #{bar => 2}, bar => 2}, DummyLogger
)
),
?_assertEqual(
#{foo => #{bar => 2}, bar => #{foo => 1}},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => #{bar => 2}, bar => 2}, #{foo => 1, bar => #{foo => 1}}, DummyLogger
)
),
?_assertEqual(
#{foo => #{bar => #{}}},
emqx_map_lib:best_effort_recursive_sum(
emqx_utils_maps:best_effort_recursive_sum(
#{foo => #{bar => #{foo => []}}}, #{foo => 1}, DummyLogger
)
)

View File

@ -261,7 +261,7 @@ create_bridge(Config, Overrides) ->
BridgeType = ?config(cassa_bridge_type, Config),
Name = ?config(cassa_name, Config),
BridgeConfig0 = ?config(cassa_config, Config),
BridgeConfig = emqx_map_lib:deep_merge(BridgeConfig0, Overrides),
BridgeConfig = emqx_utils_maps:deep_merge(BridgeConfig0, Overrides),
emqx_bridge:create(BridgeType, Name, BridgeConfig).
delete_bridge(Config) ->

View File

@ -193,7 +193,7 @@ create_bridge(Config, Overrides) ->
BridgeType = ?config(dynamo_bridge_type, Config),
Name = ?config(dynamo_name, Config),
DynamoConfig0 = ?config(dynamo_config, Config),
DynamoConfig = emqx_map_lib:deep_merge(DynamoConfig0, Overrides),
DynamoConfig = emqx_utils_maps:deep_merge(DynamoConfig0, Overrides),
emqx_bridge:create(BridgeType, Name, DynamoConfig).
delete_all_bridges() ->

View File

@ -181,7 +181,7 @@ create_bridge(Config, GCPPubSubConfigOverrides) ->
TypeBin = ?BRIDGE_TYPE_BIN,
Name = ?config(gcp_pubsub_name, Config),
GCPPubSubConfig0 = ?config(gcp_pubsub_config, Config),
GCPPubSubConfig = emqx_map_lib:deep_merge(GCPPubSubConfig0, GCPPubSubConfigOverrides),
GCPPubSubConfig = emqx_utils_maps:deep_merge(GCPPubSubConfig0, GCPPubSubConfigOverrides),
ct:pal("creating bridge: ~p", [GCPPubSubConfig]),
Res = emqx_bridge:create(TypeBin, Name, GCPPubSubConfig),
ct:pal("bridge creation result: ~p", [Res]),
@ -194,7 +194,7 @@ create_bridge_http(Config, GCPPubSubConfigOverrides) ->
TypeBin = ?BRIDGE_TYPE_BIN,
Name = ?config(gcp_pubsub_name, Config),
GCPPubSubConfig0 = ?config(gcp_pubsub_config, Config),
GCPPubSubConfig = emqx_map_lib:deep_merge(GCPPubSubConfig0, GCPPubSubConfigOverrides),
GCPPubSubConfig = emqx_utils_maps:deep_merge(GCPPubSubConfig0, GCPPubSubConfigOverrides),
Params = GCPPubSubConfig#{<<"type">> => TypeBin, <<"name">> => Name},
Path = emqx_mgmt_api_test_util:api_path(["bridges"]),
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),

View File

@ -354,7 +354,7 @@ create_bridge(Config, Overrides) ->
Type = influxdb_type_bin(?config(influxdb_type, Config)),
Name = ?config(influxdb_name, Config),
InfluxDBConfig0 = ?config(influxdb_config, Config),
InfluxDBConfig = emqx_map_lib:deep_merge(InfluxDBConfig0, Overrides),
InfluxDBConfig = emqx_utils_maps:deep_merge(InfluxDBConfig0, Overrides),
emqx_bridge:create(Type, Name, InfluxDBConfig).
delete_bridge(Config) ->
@ -390,7 +390,7 @@ create_rule_and_action_http(Config, Overrides) ->
sql => <<"SELECT * FROM \"t/topic\"">>,
actions => [BridgeId]
},
Params = emqx_map_lib:deep_merge(Params0, Overrides),
Params = emqx_utils_maps:deep_merge(Params0, Overrides),
Path = emqx_mgmt_api_test_util:api_path(["rules"]),
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
case emqx_mgmt_api_test_util:request_api(post, Path, "", AuthHeader, Params) of

View File

@ -245,7 +245,7 @@ create_bridge(Config, Overrides) ->
Type = mongo_type_bin(?config(mongo_type, Config)),
Name = ?config(mongo_name, Config),
MongoConfig0 = ?config(mongo_config, Config),
MongoConfig = emqx_map_lib:deep_merge(MongoConfig0, Overrides),
MongoConfig = emqx_utils_maps:deep_merge(MongoConfig0, Overrides),
ct:pal("creating ~p bridge with config:\n ~p", [Type, MongoConfig]),
emqx_bridge:create(Type, Name, MongoConfig).

View File

@ -229,7 +229,7 @@ create_bridge(Config, Overrides) ->
BridgeType = ?config(pgsql_bridge_type, Config),
Name = ?config(pgsql_name, Config),
PGConfig0 = ?config(pgsql_config, Config),
PGConfig = emqx_map_lib:deep_merge(PGConfig0, Overrides),
PGConfig = emqx_utils_maps:deep_merge(PGConfig0, Overrides),
emqx_bridge:create(BridgeType, Name, PGConfig).
delete_bridge(Config) ->

View File

@ -207,7 +207,7 @@ create_bridge(Config, Overrides) ->
BridgeType = ?config(tdengine_bridge_type, Config),
Name = ?config(tdengine_name, Config),
TDConfig0 = ?config(tdengine_config, Config),
TDConfig = emqx_map_lib:deep_merge(TDConfig0, Overrides),
TDConfig = emqx_utils_maps:deep_merge(TDConfig0, Overrides),
emqx_bridge:create(BridgeType, Name, TDConfig).
delete_bridge(Config) ->

View File

@ -67,7 +67,7 @@ get_schema(SchemaName) ->
-spec add_schema(schema_name(), schema()) -> ok | {error, term()}.
add_schema(Name, Schema) ->
RawSchema = emqx_map_lib:binary_key_map(Schema),
RawSchema = emqx_utils_maps:binary_key_map(Schema),
Res = emqx_conf:update(
[?CONF_KEY_ROOT, schemas, Name],
RawSchema,
@ -113,7 +113,7 @@ post_config_update(
added := Added,
changed := Changed0,
removed := Removed
} = emqx_map_lib:diff_maps(NewSchemas, OldSchemas),
} = emqx_utils_maps:diff_maps(NewSchemas, OldSchemas),
Changed = maps:map(fun(_N, {_Old, New}) -> New end, Changed0),
RemovedNames = maps:keys(Removed),
case RemovedNames of

View File

@ -344,7 +344,7 @@ t_decode(Config) ->
t_fail_rollback(Config) ->
SerdeType = ?config(serde_type, Config),
OkSchema = emqx_map_lib:binary_key_map(schema_params(SerdeType)),
OkSchema = emqx_utils_maps:binary_key_map(schema_params(SerdeType)),
BrokenSchema = OkSchema#{<<"source">> := <<"{}">>},
%% hopefully, for this small map, the key order is used.
Serdes = #{