fix(emqx_authz): fix function 'create_resource'
This commit is contained in:
parent
580901b678
commit
fae91d72f2
|
@ -71,3 +71,5 @@
|
||||||
, limit => 100
|
, limit => 100
|
||||||
, count => 1
|
, count => 1
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
-define(RESOURCE_GROUP, <<"emqx_authz">>).
|
|
@ -53,6 +53,7 @@ init(#{query := SQL0} = Source) ->
|
||||||
ResourceID = emqx_authz_utils:make_resource_id(emqx_connector_pgsql),
|
ResourceID = emqx_authz_utils:make_resource_id(emqx_connector_pgsql),
|
||||||
case emqx_resource:create_local(
|
case emqx_resource:create_local(
|
||||||
ResourceID,
|
ResourceID,
|
||||||
|
?RESOURCE_GROUP,
|
||||||
emqx_connector_pgsql,
|
emqx_connector_pgsql,
|
||||||
Source#{named_queries => #{ResourceID => SQL}}) of
|
Source#{named_queries => #{ResourceID => SQL}}) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
-module(emqx_authz_utils).
|
-module(emqx_authz_utils).
|
||||||
|
|
||||||
-include_lib("emqx/include/emqx_placeholder.hrl").
|
-include_lib("emqx/include/emqx_placeholder.hrl").
|
||||||
|
-include_lib("emqx_authz.hrl").
|
||||||
|
|
||||||
-export([ cleanup_resources/0
|
-export([ cleanup_resources/0
|
||||||
, make_resource_id/1
|
, make_resource_id/1
|
||||||
|
@ -28,15 +29,13 @@
|
||||||
, render_sql_params/2
|
, render_sql_params/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(RESOURCE_GROUP, <<"emqx_authz">>).
|
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% APIs
|
%% APIs
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
create_resource(Module, Config) ->
|
create_resource(Module, Config) ->
|
||||||
ResourceID = make_resource_id(Module),
|
ResourceID = make_resource_id(Module),
|
||||||
case emqx_resource:create_local(ResourceID, Module, Config) of
|
case emqx_resource:create_local(ResourceID, ?RESOURCE_GROUP, Module, Config) of
|
||||||
{ok, already_created} -> {ok, ResourceID};
|
{ok, already_created} -> {ok, ResourceID};
|
||||||
{ok, _} -> {ok, ResourceID};
|
{ok, _} -> {ok, ResourceID};
|
||||||
{error, Reason} -> {error, Reason}
|
{error, Reason} -> {error, Reason}
|
||||||
|
@ -49,7 +48,7 @@ cleanup_resources() ->
|
||||||
|
|
||||||
make_resource_id(Name) ->
|
make_resource_id(Name) ->
|
||||||
NameBin = bin(Name),
|
NameBin = bin(Name),
|
||||||
emqx_resource:generate_id(?RESOURCE_GROUP, NameBin).
|
emqx_resource:generate_id(NameBin).
|
||||||
|
|
||||||
update_config(Path, ConfigRequest) ->
|
update_config(Path, ConfigRequest) ->
|
||||||
emqx_conf:update(Path, ConfigRequest, #{rawconf_with_defaults => true,
|
emqx_conf:update(Path, ConfigRequest, #{rawconf_with_defaults => true,
|
||||||
|
|
|
@ -31,7 +31,7 @@ groups() ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create_local, fun(_, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, create_local, fun(_, _, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, remove_local, fun(_) -> ok end),
|
meck:expect(emqx_resource, remove_local, fun(_) -> ok end),
|
||||||
meck:expect(emqx_resource, create_dry_run_local, fun(_, _) -> ok end),
|
meck:expect(emqx_resource, create_dry_run_local, fun(_, _) -> ok end),
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ groups() ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create_local, fun(_, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, create_local, fun(_, _, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, create_dry_run_local,
|
meck:expect(emqx_resource, create_dry_run_local,
|
||||||
fun(emqx_connector_mysql, _) -> ok;
|
fun(emqx_connector_mysql, _) -> ok;
|
||||||
(emqx_connector_mongo, _) -> ok;
|
(emqx_connector_mongo, _) -> ok;
|
||||||
|
|
Loading…
Reference in New Issue