From 00d7d66871c0c8b5011f25a3de3d26f3d004ade0 Mon Sep 17 00:00:00 2001 From: zhanghongtong Date: Wed, 22 Sep 2021 11:28:31 +0800 Subject: [PATCH] chore(authz): rename mongo to mongodb --- apps/emqx_authz/etc/emqx_authz.conf | 2 +- apps/emqx_authz/src/emqx_authz.erl | 6 +++-- apps/emqx_authz/src/emqx_authz_api_schema.erl | 12 +++++----- ...authz_mongo.erl => emqx_authz_mongodb.erl} | 4 ++-- apps/emqx_authz/src/emqx_authz_schema.erl | 22 ++++++++++++------- apps/emqx_authz/test/emqx_authz_SUITE.erl | 20 ++++++++--------- .../test/emqx_authz_api_sources_SUITE.erl | 22 +++++++++---------- ...SUITE.erl => emqx_authz_mongodb_SUITE.erl} | 4 ++-- 8 files changed, 50 insertions(+), 42 deletions(-) rename apps/emqx_authz/src/{emqx_authz_mongo.erl => emqx_authz_mongodb.erl} (98%) rename apps/emqx_authz/test/{emqx_authz_mongo_SUITE.erl => emqx_authz_mongodb_SUITE.erl} (98%) diff --git a/apps/emqx_authz/etc/emqx_authz.conf b/apps/emqx_authz/etc/emqx_authz.conf index 19bb2737b..1111a7819 100644 --- a/apps/emqx_authz/etc/emqx_authz.conf +++ b/apps/emqx_authz/etc/emqx_authz.conf @@ -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 diff --git a/apps/emqx_authz/src/emqx_authz.erl b/apps/emqx_authz/src/emqx_authz.erl index cf7447f6a..e7ccbe5b0 100644 --- a/apps/emqx_authz/src/emqx_authz.erl +++ b/apps/emqx_authz/src/emqx_authz.erl @@ -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) -> diff --git a/apps/emqx_authz/src/emqx_authz_api_schema.erl b/apps/emqx_authz/src/emqx_authz_api_schema.erl index 4fd2f8ca1..d99c5acb5 100644 --- a/apps/emqx_authz/src/emqx_authz_api_schema.erl +++ b/apps/emqx_authz/src/emqx_authz_api_schema.erl @@ -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, diff --git a/apps/emqx_authz/src/emqx_authz_mongo.erl b/apps/emqx_authz/src/emqx_authz_mongodb.erl similarity index 98% rename from apps/emqx_authz/src/emqx_authz_mongo.erl rename to apps/emqx_authz/src/emqx_authz_mongodb.erl index 68808c20b..6c0fb126a 100644 --- a/apps/emqx_authz/src/emqx_authz_mongo.erl +++ b/apps/emqx_authz/src/emqx_authz_mongodb.erl @@ -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, diff --git a/apps/emqx_authz/src/emqx_authz_schema.erl b/apps/emqx_authz/src/emqx_authz_schema.erl index bda8d8e74..c880b7669 100644 --- a/apps/emqx_authz/src/emqx_authz_schema.erl +++ b/apps/emqx_authz/src/emqx_authz_schema.erl @@ -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) ++ diff --git a/apps/emqx_authz/test/emqx_authz_SUITE.erl b/apps/emqx_authz/test/emqx_authz_SUITE.erl index bed20e0e4..bfdc131a0 100644 --- a/apps/emqx_authz/test/emqx_authz_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_SUITE.erl @@ -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. diff --git a/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl b/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl index f2118c05f..a3c6e6e50 100644 --- a/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl @@ -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. diff --git a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl b/apps/emqx_authz/test/emqx_authz_mongodb_SUITE.erl similarity index 98% rename from apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl rename to apps/emqx_authz/test/emqx_authz_mongodb_SUITE.erl index ec4c4f384..6925194bd 100644 --- a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_mongodb_SUITE.erl @@ -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,