fix(authz): ensure acl.conf path template rendered

This commit is contained in:
Zaiming (Stone) Shi 2023-05-02 09:04:35 +02:00
parent a3b1664c06
commit c825102bed
2 changed files with 11 additions and 4 deletions

View File

@ -205,7 +205,7 @@ sources(get, _) ->
},
AccIn
) ->
case file:read_file(Path) of
case emqx_authz_file:read_file(Path) of
{ok, Rules} ->
lists:append(AccIn, [
#{
@ -242,7 +242,7 @@ source(get, #{bindings := #{type := Type}}) ->
Type,
fun
(#{<<"type">> := <<"file">>, <<"enable">> := Enable, <<"path">> := Path}) ->
case file:read_file(Path) of
case emqx_authz_file:read_file(Path) of
{ok, Rules} ->
{200, #{
type => file,

View File

@ -32,14 +32,15 @@
create/1,
update/1,
destroy/1,
authorize/4
authorize/4,
read_file/1
]).
description() ->
"AuthZ with static rules".
create(#{path := Path0} = Source) ->
Path = emqx_schema:naive_env_interpolation(Path0),
Path = filename(Path0),
Rules =
case file:consult(Path) of
{ok, Terms} ->
@ -64,3 +65,9 @@ destroy(_Source) -> ok.
authorize(Client, PubSub, Topic, #{annotations := #{rules := Rules}}) ->
emqx_authz_rule:matches(Client, PubSub, Topic, Rules).
read_file(Path) ->
file:read_file(filename(Path)).
filename(PathMaybeTemplate) ->
emqx_schema:naive_env_interpolation(PathMaybeTemplate).