chore(authz): rename mongo to mongodb

This commit is contained in:
zhanghongtong 2021-09-22 11:28:31 +08:00
parent ab2cdfeab1
commit 00d7d66871
8 changed files with 50 additions and 42 deletions

View File

@ -46,7 +46,7 @@ authorization {
# cmd: "HGETALL mqtt_authz:%u"
# },
# {
# type: mongo
# type: mongodb
# mongo_type: single
# server: "127.0.0.1:27017"
# pool_size: 1

View File

@ -39,7 +39,7 @@
-export([post_config_update/4, pre_config_update/2]).
-define(CONF_KEY_PATH, [authorization, sources]).
-define(SOURCE_TYPES, [file, http, mongo, mysql, postgresql, redis]).
-define(SOURCE_TYPES, [file, http, mongodb, mysql, postgresql, redis]).
-spec(register_metrics() -> ok).
register_metrics() ->
@ -300,7 +300,7 @@ init_source(#{enable := true,
init_source(#{enable := true,
type := DB
} = Source) when DB =:= redis;
DB =:= mongo ->
DB =:= mongodb ->
case create_resource(Source) of
{error, Reason} -> error({load_config_error, Reason});
Id -> Source#{annotations => #{id => Id}}
@ -407,6 +407,8 @@ create_resource(#{type := DB} = Source) ->
authz_module(Type) ->
list_to_existing_atom("emqx_authz_" ++ atom_to_list(Type)).
connector_module(mongodb) ->
emqx_connector_mongo;
connector_module(postgresql) ->
emqx_connector_pgsql;
connector_module(Type) ->

View File

@ -132,8 +132,8 @@ definitions() ->
properties => #{
type => #{
type => string,
enum => [<<"mongo">>],
example => <<"mongo">>
enum => [<<"mongodb">>],
example => <<"mongodb">>
},
enable => #{
type => boolean,
@ -188,8 +188,8 @@ definitions() ->
properties => #{
type => #{
type => string,
enum => [<<"mongo">>],
example => <<"mongo">>
enum => [<<"mongodb">>],
example => <<"mongodb">>
},
enable => #{
type => boolean,
@ -245,8 +245,8 @@ definitions() ->
properties => #{
type => #{
type => string,
enum => [<<"mongo">>],
example => <<"mongo">>
enum => [<<"mongodb">>],
example => <<"mongodb">>
},
enable => #{
type => boolean,

View File

@ -14,7 +14,7 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_authz_mongo).
-module(emqx_authz_mongodb).
-include("emqx_authz.hrl").
-include_lib("emqx/include/emqx.hrl").
@ -31,7 +31,7 @@
-endif.
description() ->
"AuthZ with Mongo".
"AuthZ with MongoDB".
authorize(Client, PubSub, Topic,
#{collection := Collection,

View File

@ -114,28 +114,34 @@ fields(http_post) ->
}
] ++ proplists:delete(base_url, emqx_connector_http:fields(config));
fields(mongo_single) ->
connector_fields(mongo, single) ++
[ {collection, #{type => atom()}}
, {selector, #{type => map()}}
];
, {type, #{type => mongodb}}
, {enable, #{type => boolean(),
default => true}}
] ++ emqx_connector_mongo:fields(single);
fields(mongo_rs) ->
connector_fields(mongo, rs) ++
[ {collection, #{type => atom()}}
, {selector, #{type => map()}}
];
, {type, #{type => mongodb}}
, {enable, #{type => boolean(),
default => true}}
] ++ emqx_connector_mongo:fields(rs);
fields(mongo_sharded) ->
connector_fields(mongo, sharded) ++
[ {collection, #{type => atom()}}
, {selector, #{type => map()}}
];
, {type, #{type => mongodb}}
, {enable, #{type => boolean(),
default => true}}
] ++ emqx_connector_mongo:fields(sharded);
fields(mysql) ->
connector_fields(mysql) ++
[ {query, query()} ];
fields(postgresql) ->
[ {type, #{type => postgresql}}
[ {query, query()}
, {type, #{type => postgresql}}
, {enable, #{type => boolean(),
default => true}}
, {query, query()}
] ++ emqx_connector_pgsql:fields(config);
fields(redis_single) ->
connector_fields(redis, single) ++

View File

@ -67,7 +67,7 @@ init_per_testcase(_, Config) ->
<<"method">> => <<"get">>,
<<"request_timeout">> => 5000
}).
-define(SOURCE2, #{<<"type">> => <<"mongo">>,
-define(SOURCE2, #{<<"type">> => <<"mongodb">>,
<<"enable">> => true,
<<"mongo_type">> => <<"single">>,
<<"server">> => <<"127.0.0.1:27017">>,
@ -128,7 +128,7 @@ t_update_source(_) ->
{ok, _} = emqx_authz:update(tail, [?SOURCE6]),
?assertMatch([ #{type := http, enable := true}
, #{type := mongo, enable := true}
, #{type := mongodb, enable := true}
, #{type := mysql, enable := true}
, #{type := postgresql, enable := true}
, #{type := redis, enable := true}
@ -136,14 +136,14 @@ t_update_source(_) ->
], emqx:get_config([authorization, sources], [])),
{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, mongodb}, ?SOURCE2#{<<"enable">> := false}),
{ok, _} = emqx_authz:update({replace_once, mysql}, ?SOURCE3#{<<"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, file}, ?SOURCE6#{<<"enable">> := false}),
?assertMatch([ #{type := http, enable := false}
, #{type := mongo, enable := false}
, #{type := mongodb, enable := false}
, #{type := mysql, enable := false}
, #{type := postgresql, enable := false}
, #{type := redis, enable := false}
@ -155,7 +155,7 @@ t_update_source(_) ->
t_move_source(_) ->
{ok, _} = emqx_authz:update(replace, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6]),
?assertMatch([ #{type := http}
, #{type := mongo}
, #{type := mongodb}
, #{type := mysql}
, #{type := postgresql}
, #{type := redis}
@ -165,7 +165,7 @@ t_move_source(_) ->
{ok, _} = emqx_authz:move(postgresql, <<"top">>),
?assertMatch([ #{type := postgresql}
, #{type := http}
, #{type := mongo}
, #{type := mongodb}
, #{type := mysql}
, #{type := redis}
, #{type := file}
@ -173,7 +173,7 @@ t_move_source(_) ->
{ok, _} = emqx_authz:move(http, <<"bottom">>),
?assertMatch([ #{type := postgresql}
, #{type := mongo}
, #{type := mongodb}
, #{type := mysql}
, #{type := redis}
, #{type := file}
@ -183,19 +183,19 @@ t_move_source(_) ->
{ok, _} = emqx_authz:move(mysql, #{<<"before">> => postgresql}),
?assertMatch([ #{type := mysql}
, #{type := postgresql}
, #{type := mongo}
, #{type := mongodb}
, #{type := redis}
, #{type := file}
, #{type := http}
], emqx_authz:lookup()),
{ok, _} = emqx_authz:move(mongo, #{<<"after">> => http}),
{ok, _} = emqx_authz:move(mongodb, #{<<"after">> => http}),
?assertMatch([ #{type := mysql}
, #{type := postgresql}
, #{type := redis}
, #{type := file}
, #{type := http}
, #{type := mongo}
, #{type := mongodb}
], emqx_authz:lookup()),
ok.

View File

@ -44,7 +44,7 @@
<<"method">> => <<"get">>,
<<"request_timeout">> => 5000
}).
-define(SOURCE2, #{<<"type">> => <<"mongo">>,
-define(SOURCE2, #{<<"type">> => <<"mongodb">>,
<<"enable">> => true,
<<"mongo_type">> => <<"sharded">>,
<<"servers">> => [<<"127.0.0.1:27017">>,
@ -181,7 +181,7 @@ t_api(_) ->
{ok, 200, Result2} = request(get, uri(["authorization", "sources"]), []),
Sources = get_sources(Result2),
?assertMatch([ #{<<"type">> := <<"http">>}
, #{<<"type">> := <<"mongo">>}
, #{<<"type">> := <<"mongodb">>}
, #{<<"type">> := <<"mysql">>}
, #{<<"type">> := <<"postgresql">>}
, #{<<"type">> := <<"redis">>}
@ -193,7 +193,7 @@ t_api(_) ->
{ok, 200, Result3} = request(get, uri(["authorization", "sources", "http"]), []),
?assertMatch(#{<<"type">> := <<"http">>, <<"enable">> := false}, jsx:decode(Result3)),
{ok, 204, _} = request(put, uri(["authorization", "sources", "mongo"]),
{ok, 204, _} = request(put, uri(["authorization", "sources", "mongodb"]),
?SOURCE2#{<<"ssl">> := #{
<<"enable">> => true,
<<"cacertfile">> => <<"fake cacert file">>,
@ -201,8 +201,8 @@ t_api(_) ->
<<"keyfile">> => <<"fake key file">>,
<<"verify">> => false
}}),
{ok, 200, Result4} = request(get, uri(["authorization", "sources", "mongo"]), []),
?assertMatch(#{<<"type">> := <<"mongo">>,
{ok, 200, Result4} = request(get, uri(["authorization", "sources", "mongodb"]), []),
?assertMatch(#{<<"type">> := <<"mongodb">>,
<<"ssl">> := #{<<"enable">> := true,
<<"cacertfile">> := <<"fake cacert file">>,
<<"certfile">> := <<"fake cert file">>,
@ -225,7 +225,7 @@ t_api(_) ->
t_move_source(_) ->
{ok, _} = emqx_authz:update(replace, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5]),
?assertMatch([ #{type := http}
, #{type := mongo}
, #{type := mongodb}
, #{type := mysql}
, #{type := postgresql}
, #{type := redis}
@ -235,7 +235,7 @@ t_move_source(_) ->
#{<<"position">> => <<"top">>}),
?assertMatch([ #{type := postgresql}
, #{type := http}
, #{type := mongo}
, #{type := mongodb}
, #{type := mysql}
, #{type := redis}
], emqx_authz:lookup()),
@ -243,7 +243,7 @@ t_move_source(_) ->
{ok, 204, _} = request(post, uri(["authorization", "sources", "http", "move"]),
#{<<"position">> => <<"bottom">>}),
?assertMatch([ #{type := postgresql}
, #{type := mongo}
, #{type := mongodb}
, #{type := mysql}
, #{type := redis}
, #{type := http}
@ -253,18 +253,18 @@ t_move_source(_) ->
#{<<"position">> => #{<<"before">> => <<"postgresql">>}}),
?assertMatch([ #{type := mysql}
, #{type := postgresql}
, #{type := mongo}
, #{type := mongodb}
, #{type := redis}
, #{type := http}
], emqx_authz:lookup()),
{ok, 204, _} = request(post, uri(["authorization", "sources", "mongo", "move"]),
{ok, 204, _} = request(post, uri(["authorization", "sources", "mongodb", "move"]),
#{<<"position">> => #{<<"after">> => <<"http">>}}),
?assertMatch([ #{type := mysql}
, #{type := postgresql}
, #{type := redis}
, #{type := http}
, #{type := mongo}
, #{type := mongodb}
], emqx_authz:lookup()),
ok.

View File

@ -13,7 +13,7 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_authz_mongo_SUITE).
-module(emqx_authz_mongodb_SUITE).
-compile(nowarn_export_all).
-compile(export_all).
@ -46,7 +46,7 @@ init_per_suite(Config) ->
ok = emqx_ct_helpers:start_apps([emqx_authz]),
{ok, _} = emqx:update_config([authorization, cache, enable], false),
{ok, _} = emqx:update_config([authorization, no_match], deny),
Rules = [#{<<"type">> => <<"mongo">>,
Rules = [#{<<"type">> => <<"mongodb">>,
<<"mongo_type">> => <<"single">>,
<<"server">> => <<"127.0.0.1:27017">>,
<<"pool_size">> => 1,