diff --git a/apps/emqx_authz/src/emqx_authz.erl b/apps/emqx_authz/src/emqx_authz.erl index da776f291..9ba67ddd1 100644 --- a/apps/emqx_authz/src/emqx_authz.erl +++ b/apps/emqx_authz/src/emqx_authz.erl @@ -151,8 +151,9 @@ pre_config_update({{replace_once, Type}, Source}, Conf) when is_map(Source), is_ Error -> Error end; pre_config_update({{delete_once, Type}, _Source}, Conf) when is_list(Conf) -> - {_, Source} = find_source_by_type(Type), - NConf = lists:delete(Source, Conf), + {Index, _} = find_source_by_type(Type), + {List1, List2} = lists:split(Index, Conf), + NConf = lists:droplast(List1) ++ List2, case check_dup_types(NConf) of ok -> {ok, NConf}; Error -> Error diff --git a/apps/emqx_authz/src/emqx_authz_api_sources.erl b/apps/emqx_authz/src/emqx_authz_api_sources.erl index acef52f44..54ac28409 100644 --- a/apps/emqx_authz/src/emqx_authz_api_sources.erl +++ b/apps/emqx_authz/src/emqx_authz_api_sources.erl @@ -336,11 +336,8 @@ sources(get, _) -> lists:append(AccIn, [Source#{annotations => #{status => healthy}}]) end, [], emqx_authz:lookup()), {200, #{sources => Sources}}; -sources(post, #{body := #{<<"type">> := <<"file">>, <<"rules">> := Rules}}) when is_list(Rules) -> - {ok, Filename} = write_file(filename:join([emqx:get_config([node, data_dir]), "acl.conf"]), - erlang:list_to_bitstring([<> || Rule <- Rules]) - ), - +sources(post, #{body := #{<<"type">> := <<"file">>, <<"rules">> := Rules}}) -> + {ok, Filename} = write_file(filename:join([emqx:get_config([node, data_dir]), "acl.conf"]), Rules), update_config(head, [#{type => file, enable => true, path => Filename}]); sources(post, #{body := Body}) when is_map(Body) -> update_config(head, [write_cert(Body)]); diff --git a/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl b/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl index b4b7b87c9..3862e06d0 100644 --- a/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl @@ -219,6 +219,7 @@ t_api(_) -> end, Sources), {ok, 200, Result5} = request(get, uri(["authorization", "sources"]), []), ?assertEqual([], get_sources(Result5)), + ?assertEqual([], emqx:get_config([authorization, sources])), ok. t_move_source(_) ->