chore(authz): rename pgsql to postgresql
Signed-off-by: zhanghongtong <rory-z@outlook.com>
This commit is contained in:
parent
deac54c847
commit
fa467d0741
|
@ -26,7 +26,7 @@ authz:{
|
||||||
sql: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or clientid = '%c'"
|
sql: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or clientid = '%c'"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: pgsql
|
type: postgresql
|
||||||
config: {
|
config: {
|
||||||
server: "127.0.0.1:5432"
|
server: "127.0.0.1:5432"
|
||||||
database: mqtt
|
database: mqtt
|
||||||
|
@ -96,7 +96,7 @@ Sample data in the default configuration:
|
||||||
INSERT INTO mqtt_authz (ipaddress, username, clientid, action, permission, topic) VALUES ('127.0.0.1', '', '', 'subscribe', 'allow', '$SYS/#');
|
INSERT INTO mqtt_authz (ipaddress, username, clientid, action, permission, topic) VALUES ('127.0.0.1', '', '', 'subscribe', 'allow', '$SYS/#');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Pgsql
|
#### PostgreSQL
|
||||||
|
|
||||||
Create Example Table
|
Create Example Table
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ authorization {
|
||||||
# query: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or clientid = '%c'"
|
# query: "select ipaddress, username, clientid, action, permission, topic from mqtt_authz where ipaddr = '%a' or username = '%u' or clientid = '%c'"
|
||||||
# },
|
# },
|
||||||
# {
|
# {
|
||||||
# type: pgsql
|
# type: postgresql
|
||||||
# server: "127.0.0.1:5432"
|
# server: "127.0.0.1:5432"
|
||||||
# database: mqtt
|
# database: mqtt
|
||||||
# pool_size: 1
|
# pool_size: 1
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
-export([post_config_update/4, pre_config_update/2]).
|
-export([post_config_update/4, pre_config_update/2]).
|
||||||
|
|
||||||
-define(CONF_KEY_PATH, [authorization, sources]).
|
-define(CONF_KEY_PATH, [authorization, sources]).
|
||||||
-define(SOURCE_TYPES, [file, http, mongo, mysql, pgsql, redis]).
|
-define(SOURCE_TYPES, [file, http, mongo, mysql, postgresql, redis]).
|
||||||
|
|
||||||
-spec(register_metrics() -> ok).
|
-spec(register_metrics() -> ok).
|
||||||
register_metrics() ->
|
register_metrics() ->
|
||||||
|
@ -309,7 +309,7 @@ init_source(#{enable := true,
|
||||||
type := DB,
|
type := DB,
|
||||||
query := SQL
|
query := SQL
|
||||||
} = Source) when DB =:= mysql;
|
} = Source) when DB =:= mysql;
|
||||||
DB =:= pgsql ->
|
DB =:= postgresql ->
|
||||||
Mod = authz_module(DB),
|
Mod = authz_module(DB),
|
||||||
case create_resource(Source) of
|
case create_resource(Source) of
|
||||||
{error, Reason} -> error({load_config_error, Reason});
|
{error, Reason} -> error({load_config_error, Reason});
|
||||||
|
@ -407,6 +407,8 @@ create_resource(#{type := DB} = Source) ->
|
||||||
authz_module(Type) ->
|
authz_module(Type) ->
|
||||||
list_to_existing_atom("emqx_authz_" ++ atom_to_list(Type)).
|
list_to_existing_atom("emqx_authz_" ++ atom_to_list(Type)).
|
||||||
|
|
||||||
|
connector_module(postgresql) ->
|
||||||
|
emqx_connector_pgsql;
|
||||||
connector_module(Type) ->
|
connector_module(Type) ->
|
||||||
list_to_existing_atom("emqx_connector_" ++ atom_to_list(Type)).
|
list_to_existing_atom("emqx_connector_" ++ atom_to_list(Type)).
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ definitions() ->
|
||||||
, minirest:ref(<<"mongo_rs">>)
|
, minirest:ref(<<"mongo_rs">>)
|
||||||
, minirest:ref(<<"mongo_sharded">>)
|
, minirest:ref(<<"mongo_sharded">>)
|
||||||
, minirest:ref(<<"mysql">>)
|
, minirest:ref(<<"mysql">>)
|
||||||
, minirest:ref(<<"pgsql">>)
|
, minirest:ref(<<"postgresql">>)
|
||||||
, minirest:ref(<<"redis_single">>)
|
, minirest:ref(<<"redis_single">>)
|
||||||
, minirest:ref(<<"redis_sentinel">>)
|
, minirest:ref(<<"redis_sentinel">>)
|
||||||
, minirest:ref(<<"redis_cluster">>)
|
, minirest:ref(<<"redis_cluster">>)
|
||||||
|
@ -335,8 +335,8 @@ definitions() ->
|
||||||
properties => #{
|
properties => #{
|
||||||
type => #{
|
type => #{
|
||||||
type => string,
|
type => string,
|
||||||
enum => [<<"pgsql">>],
|
enum => [<<"postgresql">>],
|
||||||
example => <<"pgsql">>
|
example => <<"postgresql">>
|
||||||
},
|
},
|
||||||
enable => #{
|
enable => #{
|
||||||
type => boolean,
|
type => boolean,
|
||||||
|
@ -501,7 +501,7 @@ definitions() ->
|
||||||
, #{<<"mongo_rs">> => MongoRs}
|
, #{<<"mongo_rs">> => MongoRs}
|
||||||
, #{<<"mongo_sharded">> => MongoSharded}
|
, #{<<"mongo_sharded">> => MongoSharded}
|
||||||
, #{<<"mysql">> => Mysql}
|
, #{<<"mysql">> => Mysql}
|
||||||
, #{<<"pgsql">> => Pgsql}
|
, #{<<"postgresql">> => Pgsql}
|
||||||
, #{<<"redis_single">> => RedisSingle}
|
, #{<<"redis_single">> => RedisSingle}
|
||||||
, #{<<"redis_sentinel">> => RedisSentinel}
|
, #{<<"redis_sentinel">> => RedisSentinel}
|
||||||
, #{<<"redis_cluster">> => RedisCluster}
|
, #{<<"redis_cluster">> => RedisCluster}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqx_authz_pgsql).
|
-module(emqx_authz_postgresql).
|
||||||
|
|
||||||
-include("emqx_authz.hrl").
|
-include("emqx_authz.hrl").
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
description() ->
|
description() ->
|
||||||
"AuthZ with pgsql".
|
"AuthZ with postgresql".
|
||||||
|
|
||||||
parse_query(undefined) ->
|
parse_query(undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
|
@ -59,7 +59,7 @@ authorize(Client, PubSub, Topic,
|
||||||
{ok, Columns, Rows} ->
|
{ok, Columns, Rows} ->
|
||||||
do_authorize(Client, PubSub, Topic, Columns, Rows);
|
do_authorize(Client, PubSub, Topic, Columns, Rows);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(error, "[AuthZ] Query pgsql error: ~p~n", [Reason]),
|
?LOG(error, "[AuthZ] Query postgresql error: ~p~n", [Reason]),
|
||||||
nomatch
|
nomatch
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -33,7 +33,7 @@ fields("authorization") ->
|
||||||
, hoconsc:ref(?MODULE, mongo_rs)
|
, hoconsc:ref(?MODULE, mongo_rs)
|
||||||
, hoconsc:ref(?MODULE, mongo_sharded)
|
, hoconsc:ref(?MODULE, mongo_sharded)
|
||||||
, hoconsc:ref(?MODULE, mysql)
|
, hoconsc:ref(?MODULE, mysql)
|
||||||
, hoconsc:ref(?MODULE, pgsql)
|
, hoconsc:ref(?MODULE, postgresql)
|
||||||
, hoconsc:ref(?MODULE, redis_single)
|
, hoconsc:ref(?MODULE, redis_single)
|
||||||
, hoconsc:ref(?MODULE, redis_sentinel)
|
, hoconsc:ref(?MODULE, redis_sentinel)
|
||||||
, hoconsc:ref(?MODULE, redis_cluster)
|
, hoconsc:ref(?MODULE, redis_cluster)
|
||||||
|
@ -131,9 +131,12 @@ fields(mongo_sharded) ->
|
||||||
fields(mysql) ->
|
fields(mysql) ->
|
||||||
connector_fields(mysql) ++
|
connector_fields(mysql) ++
|
||||||
[ {query, query()} ];
|
[ {query, query()} ];
|
||||||
fields(pgsql) ->
|
fields(postgresql) ->
|
||||||
connector_fields(pgsql) ++
|
[ {type, #{type => postgresql}}
|
||||||
[ {query, query()} ];
|
, {enable, #{type => boolean(),
|
||||||
|
default => true}}
|
||||||
|
, {query, query()}
|
||||||
|
] ++ emqx_connector_pgsql:fields(config);
|
||||||
fields(redis_single) ->
|
fields(redis_single) ->
|
||||||
connector_fields(redis, single) ++
|
connector_fields(redis, single) ++
|
||||||
[ {cmd, query()} ];
|
[ {cmd, query()} ];
|
||||||
|
@ -181,4 +184,4 @@ connector_fields(DB, Fields) ->
|
||||||
to_list(A) when is_atom(A) ->
|
to_list(A) when is_atom(A) ->
|
||||||
atom_to_list(A);
|
atom_to_list(A);
|
||||||
to_list(B) when is_binary(B) ->
|
to_list(B) when is_binary(B) ->
|
||||||
binary_to_list(B).
|
binary_to_list(B).
|
||||||
|
|
|
@ -88,7 +88,7 @@ init_per_testcase(_, Config) ->
|
||||||
<<"ssl">> => #{<<"enable">> => false},
|
<<"ssl">> => #{<<"enable">> => false},
|
||||||
<<"query">> => <<"abcb">>
|
<<"query">> => <<"abcb">>
|
||||||
}).
|
}).
|
||||||
-define(SOURCE4, #{<<"type">> => <<"pgsql">>,
|
-define(SOURCE4, #{<<"type">> => <<"postgresql">>,
|
||||||
<<"enable">> => true,
|
<<"enable">> => true,
|
||||||
<<"server">> => <<"127.0.0.1:27017">>,
|
<<"server">> => <<"127.0.0.1:27017">>,
|
||||||
<<"pool_size">> => 1,
|
<<"pool_size">> => 1,
|
||||||
|
@ -130,7 +130,7 @@ t_update_source(_) ->
|
||||||
?assertMatch([ #{type := http, enable := true}
|
?assertMatch([ #{type := http, enable := true}
|
||||||
, #{type := mongo, enable := true}
|
, #{type := mongo, enable := true}
|
||||||
, #{type := mysql, enable := true}
|
, #{type := mysql, enable := true}
|
||||||
, #{type := pgsql, enable := true}
|
, #{type := postgresql, enable := true}
|
||||||
, #{type := redis, enable := true}
|
, #{type := redis, enable := true}
|
||||||
, #{type := file, enable := true}
|
, #{type := file, enable := true}
|
||||||
], emqx:get_config([authorization, sources], [])),
|
], emqx:get_config([authorization, sources], [])),
|
||||||
|
@ -138,14 +138,14 @@ t_update_source(_) ->
|
||||||
{ok, _} = emqx_authz:update({replace_once, http}, ?SOURCE1#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, http}, ?SOURCE1#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, mongo}, ?SOURCE2#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, mongo}, ?SOURCE2#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, mysql}, ?SOURCE3#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, mysql}, ?SOURCE3#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, pgsql}, ?SOURCE4#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, postgresql}, ?SOURCE4#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, redis}, ?SOURCE5#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, redis}, ?SOURCE5#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, file}, ?SOURCE6#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, file}, ?SOURCE6#{<<"enable">> := false}),
|
||||||
|
|
||||||
?assertMatch([ #{type := http, enable := false}
|
?assertMatch([ #{type := http, enable := false}
|
||||||
, #{type := mongo, enable := false}
|
, #{type := mongo, enable := false}
|
||||||
, #{type := mysql, enable := false}
|
, #{type := mysql, enable := false}
|
||||||
, #{type := pgsql, enable := false}
|
, #{type := postgresql, enable := false}
|
||||||
, #{type := redis, enable := false}
|
, #{type := redis, enable := false}
|
||||||
, #{type := file, enable := false}
|
, #{type := file, enable := false}
|
||||||
], emqx:get_config([authorization, sources], [])),
|
], emqx:get_config([authorization, sources], [])),
|
||||||
|
@ -157,13 +157,13 @@ t_move_source(_) ->
|
||||||
?assertMatch([ #{type := http}
|
?assertMatch([ #{type := http}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := pgsql}
|
, #{type := postgresql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(pgsql, <<"top">>),
|
{ok, _} = emqx_authz:move(postgresql, <<"top">>),
|
||||||
?assertMatch([ #{type := pgsql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
|
@ -172,7 +172,7 @@ t_move_source(_) ->
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(http, <<"bottom">>),
|
{ok, _} = emqx_authz:move(http, <<"bottom">>),
|
||||||
?assertMatch([ #{type := pgsql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
|
@ -180,9 +180,9 @@ t_move_source(_) ->
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(mysql, #{<<"before">> => pgsql}),
|
{ok, _} = emqx_authz:move(mysql, #{<<"before">> => postgresql}),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := pgsql}
|
, #{type := postgresql}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
|
@ -191,7 +191,7 @@ t_move_source(_) ->
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(mongo, #{<<"after">> => http}),
|
{ok, _} = emqx_authz:move(mongo, #{<<"after">> => http}),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := pgsql}
|
, #{type := postgresql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<<"ssl">> => #{<<"enable">> => false},
|
<<"ssl">> => #{<<"enable">> => false},
|
||||||
<<"query">> => <<"abcb">>
|
<<"query">> => <<"abcb">>
|
||||||
}).
|
}).
|
||||||
-define(SOURCE4, #{<<"type">> => <<"pgsql">>,
|
-define(SOURCE4, #{<<"type">> => <<"postgresql">>,
|
||||||
<<"enable">> => true,
|
<<"enable">> => true,
|
||||||
<<"server">> => <<"127.0.0.1:5432">>,
|
<<"server">> => <<"127.0.0.1:5432">>,
|
||||||
<<"pool_size">> => 1,
|
<<"pool_size">> => 1,
|
||||||
|
@ -183,7 +183,7 @@ t_api(_) ->
|
||||||
?assertMatch([ #{<<"type">> := <<"http">>}
|
?assertMatch([ #{<<"type">> := <<"http">>}
|
||||||
, #{<<"type">> := <<"mongo">>}
|
, #{<<"type">> := <<"mongo">>}
|
||||||
, #{<<"type">> := <<"mysql">>}
|
, #{<<"type">> := <<"mysql">>}
|
||||||
, #{<<"type">> := <<"pgsql">>}
|
, #{<<"type">> := <<"postgresql">>}
|
||||||
, #{<<"type">> := <<"redis">>}
|
, #{<<"type">> := <<"redis">>}
|
||||||
, #{<<"type">> := <<"file">>}
|
, #{<<"type">> := <<"file">>}
|
||||||
], Sources),
|
], Sources),
|
||||||
|
@ -227,13 +227,13 @@ t_move_source(_) ->
|
||||||
?assertMatch([ #{type := http}
|
?assertMatch([ #{type := http}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := pgsql}
|
, #{type := postgresql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "pgsql", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "postgresql", "move"]),
|
||||||
#{<<"position">> => <<"top">>}),
|
#{<<"position">> => <<"top">>}),
|
||||||
?assertMatch([ #{type := pgsql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
|
@ -242,7 +242,7 @@ t_move_source(_) ->
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "http", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "http", "move"]),
|
||||||
#{<<"position">> => <<"bottom">>}),
|
#{<<"position">> => <<"bottom">>}),
|
||||||
?assertMatch([ #{type := pgsql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
|
@ -250,9 +250,9 @@ t_move_source(_) ->
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "mysql", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "mysql", "move"]),
|
||||||
#{<<"position">> => #{<<"before">> => <<"pgsql">>}}),
|
#{<<"position">> => #{<<"before">> => <<"postgresql">>}}),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := pgsql}
|
, #{type := postgresql}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
|
@ -261,7 +261,7 @@ t_move_source(_) ->
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "mongo", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "mongo", "move"]),
|
||||||
#{<<"position">> => #{<<"after">> => <<"http">>}}),
|
#{<<"position">> => #{<<"after">> => <<"http">>}}),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := pgsql}
|
, #{type := postgresql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
%% limitations under the License.
|
%% limitations under the License.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqx_authz_pgsql_SUITE).
|
-module(emqx_authz_postgresql_SUITE).
|
||||||
|
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
|
@ -47,7 +47,7 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
Rules = [#{<<"type">> => <<"pgsql">>,
|
Rules = [#{<<"type">> => <<"postgresql">>,
|
||||||
<<"server">> => <<"127.0.0.1:27017">>,
|
<<"server">> => <<"127.0.0.1:27017">>,
|
||||||
<<"pool_size">> => 1,
|
<<"pool_size">> => 1,
|
||||||
<<"database">> => <<"mqtt">>,
|
<<"database">> => <<"mqtt">>,
|
Loading…
Reference in New Issue