fix: authz mysql prepare query
This commit is contained in:
parent
365ca67078
commit
2aedd38a43
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
-behaviour(emqx_authz).
|
-behaviour(emqx_authz).
|
||||||
|
|
||||||
|
-define(PREPARE_KEY, ?MODULE).
|
||||||
|
|
||||||
%% AuthZ Callbacks
|
%% AuthZ Callbacks
|
||||||
-export([
|
-export([
|
||||||
description/0,
|
description/0,
|
||||||
|
@ -52,10 +54,11 @@ init(#{query := SQL} = Source) ->
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
error({load_config_error, Reason});
|
error({load_config_error, Reason});
|
||||||
{ok, Id} ->
|
{ok, Id} ->
|
||||||
{PrepareKey, PrepareStatement} = emqx_authz_utils:parse_sql(SQL, '?', ?PLACEHOLDERS),
|
{PrepareSQL, TmplToken} = emqx_authz_utils:parse_sql(SQL, '?', ?PLACEHOLDERS),
|
||||||
case emqx_resource:query(Id, {prepare_sql, [{PrepareKey, PrepareStatement}]}) of
|
case emqx_resource:query(Id, {prepare_sql, [{?MODULE, PrepareSQL}]}) of
|
||||||
ok ->
|
ok ->
|
||||||
Source#{annotations => #{id => Id, prepare => {PrepareKey, PrepareStatement}}};
|
Source#{annotations => #{
|
||||||
|
id => Id, tmpl_oken => TmplToken}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
error({load_config_error, Reason})
|
error({load_config_error, Reason})
|
||||||
end
|
end
|
||||||
|
@ -71,12 +74,12 @@ authorize(
|
||||||
#{
|
#{
|
||||||
annotations := #{
|
annotations := #{
|
||||||
id := ResourceID,
|
id := ResourceID,
|
||||||
prepare := {PrepareKey, PrepareStatement}
|
tmpl_oken := TmplToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
RenderParams = emqx_authz_utils:render_sql_params(PrepareStatement, Client),
|
RenderParams = emqx_authz_utils:render_sql_params(TmplToken, Client),
|
||||||
case emqx_resource:query(ResourceID, {sql, PrepareKey, RenderParams}) of
|
case emqx_resource:query(ResourceID, {prepared_query, ?MODULE, RenderParams}) of
|
||||||
{ok, _Columns, []} ->
|
{ok, _Columns, []} ->
|
||||||
nomatch;
|
nomatch;
|
||||||
{ok, Columns, Rows} ->
|
{ok, Columns, Rows} ->
|
||||||
|
@ -85,7 +88,7 @@ authorize(
|
||||||
?SLOG(error, #{
|
?SLOG(error, #{
|
||||||
msg => "query_mysql_error",
|
msg => "query_mysql_error",
|
||||||
reason => Reason,
|
reason => Reason,
|
||||||
prepare => {PrepareKey, PrepareStatement},
|
tmpl_oken => TmplToken,
|
||||||
params => RenderParams,
|
params => RenderParams,
|
||||||
resource_id => ResourceID
|
resource_id => ResourceID
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue