Merge pull request #13398 from zhongwencool/authz-db-clear-table
fix: don't destory when authz'source unchanged
This commit is contained in:
commit
5f321702e7
|
@ -327,18 +327,32 @@ do_post_config_update(?ROOT_KEY, _Conf, NewConf) ->
|
||||||
|
|
||||||
overwrite_entire_sources(Sources) ->
|
overwrite_entire_sources(Sources) ->
|
||||||
PrevSources = lookup(),
|
PrevSources = lookup(),
|
||||||
NewSourcesTypes = lists:map(fun type/1, Sources),
|
#{
|
||||||
EnsureDelete = fun(S) ->
|
removed := Removed,
|
||||||
TypeName = type(S),
|
added := Added,
|
||||||
Opts =
|
identical := Identical,
|
||||||
case lists:member(TypeName, NewSourcesTypes) of
|
changed := Changed
|
||||||
true -> #{clear_metric => false};
|
} = emqx_utils:diff_lists(Sources, PrevSources, fun type/1),
|
||||||
false -> #{clear_metric => true}
|
lists:foreach(
|
||||||
end,
|
fun(S) -> ensure_deleted(S, #{clear_metric => true}) end,
|
||||||
ensure_deleted(S, Opts)
|
Removed
|
||||||
end,
|
),
|
||||||
lists:foreach(EnsureDelete, PrevSources),
|
AddedSources = create_sources(Added),
|
||||||
create_sources(Sources).
|
ChangedSources = lists:map(
|
||||||
|
fun({Old, New}) ->
|
||||||
|
update_source(type(New), Old, New)
|
||||||
|
end,
|
||||||
|
Changed
|
||||||
|
),
|
||||||
|
New = Identical ++ AddedSources ++ ChangedSources,
|
||||||
|
lists:map(
|
||||||
|
fun(Type) ->
|
||||||
|
SearchFun = fun(S) -> type(S) =:= type(Type) end,
|
||||||
|
{value, Val} = lists:search(SearchFun, New),
|
||||||
|
Val
|
||||||
|
end,
|
||||||
|
Sources
|
||||||
|
).
|
||||||
|
|
||||||
%% @doc do source move
|
%% @doc do source move
|
||||||
do_move({?CMD_MOVE, Type, ?CMD_MOVE_FRONT}, Sources) ->
|
do_move({?CMD_MOVE, Type, ?CMD_MOVE_FRONT}, Sources) ->
|
||||||
|
|
|
@ -256,6 +256,30 @@ t_destroy(_Config) ->
|
||||||
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH, <<"t">>)
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH, <<"t">>)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
t_conf_cli_load(_Config) ->
|
||||||
|
ClientInfo = emqx_authz_test_lib:base_client_info(),
|
||||||
|
|
||||||
|
ok = emqx_authz_mnesia:store_rules(
|
||||||
|
{username, <<"username">>},
|
||||||
|
[#{<<"permission">> => <<"allow">>, <<"action">> => <<"publish">>, <<"topic">> => <<"t">>}]
|
||||||
|
),
|
||||||
|
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH, <<"t">>)
|
||||||
|
),
|
||||||
|
PrevRules = ets:tab2list(emqx_acl),
|
||||||
|
Hocon = emqx_conf_cli:get_config("authorization"),
|
||||||
|
Bin = iolist_to_binary(hocon_pp:do(Hocon, #{})),
|
||||||
|
ok = emqx_conf_cli:load_config(Bin, #{mode => merge}),
|
||||||
|
%% ensure emqx_acl table not clear
|
||||||
|
?assertEqual(PrevRules, ets:tab2list(emqx_acl)),
|
||||||
|
%% still working
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH, <<"t">>)
|
||||||
|
).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Helpers
|
%% Helpers
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue