fix: can't get default raw config

This commit is contained in:
Zhongwen Deng 2022-11-18 15:07:23 +08:00
parent 4ce3d43446
commit 65820eb943
2 changed files with 14 additions and 2 deletions

View File

@ -268,7 +268,7 @@ config(put, #{body := Body}, Req) ->
global_zone_configs(get, _Params, _Req) -> global_zone_configs(get, _Params, _Req) ->
Paths = global_zone_roots(), Paths = global_zone_roots(),
Zones = lists:foldl( Zones = lists:foldl(
fun(Path, Acc) -> Acc#{Path => get_config_with_default([Path])} end, fun(Path, Acc) -> maps:merge(Acc, get_config_with_default(Path)) end,
#{}, #{},
Paths Paths
), ),
@ -343,7 +343,7 @@ get_full_config() ->
). ).
get_config_with_default(Path) -> get_config_with_default(Path) ->
emqx_config:fill_defaults(emqx:get_raw_config(Path)). emqx_config:fill_defaults(#{Path => emqx:get_raw_config([Path])}).
conf_path_from_querystr(Req) -> conf_path_from_querystr(Req) ->
case proplists:get_value(<<"conf_path">>, cowboy_req:parse_qs(Req)) of case proplists:get_value(<<"conf_path">>, cowboy_req:parse_qs(Req)) of

View File

@ -133,6 +133,18 @@ t_global_zone(_Config) ->
BadZones = emqx_map_lib:deep_put([<<"mqtt">>, <<"max_qos_allowed">>], Zones, 3), BadZones = emqx_map_lib:deep_put([<<"mqtt">>, <<"max_qos_allowed">>], Zones, 3),
?assertMatch({error, {"HTTP/1.1", 400, _}}, update_global_zone(BadZones)), ?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)),
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)),
ok = emqx_config:put_raw([<<"mqtt">>], Mqtt0),
ok. ok.
get_global_zone() -> get_global_zone() ->