diff --git a/apps/emqx_auth_postgresql/src/emqx_auth_postgresql.app.src b/apps/emqx_auth_postgresql/src/emqx_auth_postgresql.app.src index 3157b7bd75c..1d23ccac42f 100644 --- a/apps/emqx_auth_postgresql/src/emqx_auth_postgresql.app.src +++ b/apps/emqx_auth_postgresql/src/emqx_auth_postgresql.app.src @@ -9,7 +9,7 @@ stdlib, emqx, emqx_auth, - emqx_connector + emqx_postgresql ]}, {env, []}, {modules, []}, diff --git a/apps/emqx_auth_postgresql/src/emqx_authn_postgresql.erl b/apps/emqx_auth_postgresql/src/emqx_authn_postgresql.erl index 1ce2e405c82..ba92d252597 100644 --- a/apps/emqx_auth_postgresql/src/emqx_authn_postgresql.erl +++ b/apps/emqx_auth_postgresql/src/emqx_authn_postgresql.erl @@ -46,14 +46,14 @@ create(Config0) -> {Config, State} = parse_config(Config0, ResourceId), {ok, _Data} = emqx_authn_utils:create_resource( ResourceId, - emqx_connector_pgsql, + emqx_postgresql, Config ), {ok, State#{resource_id => ResourceId}}. update(Config0, #{resource_id := ResourceId} = _State) -> {Config, NState} = parse_config(Config0, ResourceId), - case emqx_authn_utils:update_resource(emqx_connector_pgsql, Config, ResourceId) of + case emqx_authn_utils:update_resource(emqx_postgresql, Config, ResourceId) of {error, Reason} -> error({load_config_error, Reason}); {ok, _} -> diff --git a/apps/emqx_auth_postgresql/src/emqx_authn_postgresql_schema.erl b/apps/emqx_auth_postgresql/src/emqx_authn_postgresql_schema.erl index 93819d7bfc2..6b3b600ee05 100644 --- a/apps/emqx_auth_postgresql/src/emqx_authn_postgresql_schema.erl +++ b/apps/emqx_auth_postgresql/src/emqx_authn_postgresql_schema.erl @@ -50,7 +50,7 @@ fields(postgresql) -> {query, fun query/1} ] ++ emqx_authn_schema:common_fields() ++ - proplists:delete(prepare_statement, emqx_connector_pgsql:fields(config)). + proplists:delete(prepare_statement, emqx_postgresql:fields(config)). desc(postgresql) -> ?DESC(postgresql); diff --git a/apps/emqx_auth_postgresql/src/emqx_authz_postgresql.erl b/apps/emqx_auth_postgresql/src/emqx_authz_postgresql.erl index 27f2d31ee5e..b930f77e4ab 100644 --- a/apps/emqx_auth_postgresql/src/emqx_authz_postgresql.erl +++ b/apps/emqx_auth_postgresql/src/emqx_authz_postgresql.erl @@ -50,10 +50,10 @@ description() -> create(#{query := SQL0} = Source) -> {SQL, PlaceHolders} = emqx_authz_utils:parse_sql(SQL0, '$n', ?PLACEHOLDERS), - ResourceID = emqx_authz_utils:make_resource_id(emqx_connector_pgsql), + ResourceID = emqx_authz_utils:make_resource_id(emqx_postgresql), {ok, _Data} = emqx_authz_utils:create_resource( ResourceID, - emqx_connector_pgsql, + emqx_postgresql, Source#{prepare_statement => #{ResourceID => SQL}} ), Source#{annotations => #{id => ResourceID, placeholders => PlaceHolders}}. @@ -62,7 +62,7 @@ update(#{query := SQL0, annotations := #{id := ResourceID}} = Source) -> {SQL, PlaceHolders} = emqx_authz_utils:parse_sql(SQL0, '$n', ?PLACEHOLDERS), case emqx_authz_utils:update_resource( - emqx_connector_pgsql, + emqx_postgresql, Source#{prepare_statement => #{ResourceID => SQL}} ) of diff --git a/apps/emqx_auth_postgresql/src/emqx_authz_postgresql_schema.erl b/apps/emqx_auth_postgresql/src/emqx_authz_postgresql_schema.erl index a52cc4fdddb..2be7e9387d9 100644 --- a/apps/emqx_auth_postgresql/src/emqx_authz_postgresql_schema.erl +++ b/apps/emqx_auth_postgresql/src/emqx_authz_postgresql_schema.erl @@ -33,7 +33,7 @@ type() -> ?AUTHZ_TYPE. fields(postgresql) -> emqx_authz_schema:authz_common_fields(?AUTHZ_TYPE) ++ - emqx_connector_pgsql:fields(config) ++ + emqx_postgresql:fields(config) ++ [{query, query()}]. desc(postgresql) -> diff --git a/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_SUITE.erl b/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_SUITE.erl index 752202610a6..ea44c0a4540 100644 --- a/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_SUITE.erl +++ b/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_SUITE.erl @@ -19,7 +19,7 @@ -compile(nowarn_export_all). -compile(export_all). --include_lib("emqx_connector/include/emqx_connector.hrl"). +-include_lib("emqx_postgresql/include/emqx_postgresql.hrl"). -include_lib("emqx_auth/include/emqx_authn.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("common_test/include/ct.hrl"). @@ -64,7 +64,7 @@ init_per_suite(Config) -> {ok, _} = emqx_resource:create_local( ?PGSQL_RESOURCE, ?AUTHN_RESOURCE_GROUP, - emqx_connector_pgsql, + emqx_postgresql, pgsql_config(), #{} ), diff --git a/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_tls_SUITE.erl b/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_tls_SUITE.erl index 25a65f66091..ba6cf060481 100644 --- a/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_tls_SUITE.erl +++ b/apps/emqx_auth_postgresql/test/emqx_authn_postgresql_tls_SUITE.erl @@ -19,7 +19,7 @@ -compile(nowarn_export_all). -compile(export_all). --include_lib("emqx_connector/include/emqx_connector.hrl"). +-include_lib("emqx_postgresql/include/emqx_postgresql.hrl"). -include_lib("emqx_auth/include/emqx_authn.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("common_test/include/ct.hrl"). diff --git a/apps/emqx_auth_postgresql/test/emqx_authz_postgresql_SUITE.erl b/apps/emqx_auth_postgresql/test/emqx_authz_postgresql_SUITE.erl index 4d38e9c96e5..f486cbd3d39 100644 --- a/apps/emqx_auth_postgresql/test/emqx_authz_postgresql_SUITE.erl +++ b/apps/emqx_auth_postgresql/test/emqx_authz_postgresql_SUITE.erl @@ -18,7 +18,7 @@ -compile(nowarn_export_all). -compile(export_all). --include("emqx_connector.hrl"). +-include_lib("emqx_postgresql/include/emqx_postgresql.hrl"). -include_lib("emqx_auth/include/emqx_authz.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("common_test/include/ct.hrl"). @@ -438,7 +438,7 @@ create_pgsql_resource() -> emqx_resource:create_local( ?PGSQL_RESOURCE, ?AUTHZ_RESOURCE_GROUP, - emqx_connector_pgsql, + emqx_postgresql, pgsql_config(), #{} ). diff --git a/apps/emqx_bridge/src/emqx_bridge.app.src b/apps/emqx_bridge/src/emqx_bridge.app.src index ecf0042cab9..c2387fe9994 100644 --- a/apps/emqx_bridge/src/emqx_bridge.app.src +++ b/apps/emqx_bridge/src/emqx_bridge.app.src @@ -1,7 +1,7 @@ %% -*- mode: erlang -*- {application, emqx_bridge, [ {description, "EMQX bridges"}, - {vsn, "0.1.28"}, + {vsn, "0.1.29"}, {registered, [emqx_bridge_sup]}, {mod, {emqx_bridge_app, []}}, {applications, [ diff --git a/apps/emqx_bridge/src/schema/emqx_bridge_enterprise.erl b/apps/emqx_bridge/src/schema/emqx_bridge_enterprise.erl index a6bd4a7549d..06a23a45f1b 100644 --- a/apps/emqx_bridge/src/schema/emqx_bridge_enterprise.erl +++ b/apps/emqx_bridge/src/schema/emqx_bridge_enterprise.erl @@ -113,9 +113,9 @@ resource_type(influxdb_api_v2) -> emqx_bridge_influxdb_connector; resource_type(redis_single) -> emqx_bridge_redis_connector; resource_type(redis_sentinel) -> emqx_bridge_redis_connector; resource_type(redis_cluster) -> emqx_bridge_redis_connector; -resource_type(pgsql) -> emqx_connector_pgsql; -resource_type(timescale) -> emqx_connector_pgsql; -resource_type(matrix) -> emqx_connector_pgsql; +resource_type(pgsql) -> emqx_postgresql; +resource_type(timescale) -> emqx_postgresql; +resource_type(matrix) -> emqx_postgresql; resource_type(tdengine) -> emqx_bridge_tdengine_connector; resource_type(clickhouse) -> emqx_bridge_clickhouse_connector; resource_type(dynamo) -> emqx_bridge_dynamo_connector; diff --git a/apps/emqx_bridge_pgsql/rebar.config b/apps/emqx_bridge_pgsql/rebar.config index 87c145f2601..da2729b702a 100644 --- a/apps/emqx_bridge_pgsql/rebar.config +++ b/apps/emqx_bridge_pgsql/rebar.config @@ -3,5 +3,6 @@ {deps, [ {emqx_connector, {path, "../../apps/emqx_connector"}}, {emqx_resource, {path, "../../apps/emqx_resource"}}, - {emqx_bridge, {path, "../../apps/emqx_bridge"}} + {emqx_bridge, {path, "../../apps/emqx_bridge"}}, + {emqx_postgresql, {path, "../../apps/emqx_postgresql"}} ]}. diff --git a/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.app.src b/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.app.src index 85131baf085..7a17652e007 100644 --- a/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.app.src +++ b/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.app.src @@ -1,11 +1,12 @@ {application, emqx_bridge_pgsql, [ {description, "EMQX Enterprise PostgreSQL Bridge"}, - {vsn, "0.1.3"}, + {vsn, "0.1.4"}, {registered, []}, {applications, [ kernel, stdlib, - emqx_resource + emqx_resource, + emqx_postgresql ]}, {env, []}, {modules, []}, diff --git a/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.erl b/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.erl index 12161b9b9f3..bb15dfad970 100644 --- a/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.erl +++ b/apps/emqx_bridge_pgsql/src/emqx_bridge_pgsql.erl @@ -82,7 +82,7 @@ fields("config") -> #{desc => ?DESC("local_topic"), default => undefined} )} ] ++ emqx_resource_schema:fields("resource_opts") ++ - (emqx_connector_pgsql:fields(config) -- + (emqx_postgresql:fields(config) -- emqx_connector_schema_lib:prepare_statement_fields()); fields("post") -> fields("post", pgsql); diff --git a/apps/emqx_connector/include/emqx_connector.hrl b/apps/emqx_connector/include/emqx_connector.hrl index cdb6ddd9233..216dca0310a 100644 --- a/apps/emqx_connector/include/emqx_connector.hrl +++ b/apps/emqx_connector/include/emqx_connector.hrl @@ -22,7 +22,6 @@ -define(MYSQL_DEFAULT_PORT, 3306). -define(MONGO_DEFAULT_PORT, 27017). -define(REDIS_DEFAULT_PORT, 6379). --define(PGSQL_DEFAULT_PORT, 5432). -define(CLICKHOUSE_DEFAULT_PORT, 8123). -define(AUTO_RECONNECT_INTERVAL, 2). diff --git a/apps/emqx_connector/rebar.config b/apps/emqx_connector/rebar.config index 78515abe6c3..94da3c58082 100644 --- a/apps/emqx_connector/rebar.config +++ b/apps/emqx_connector/rebar.config @@ -8,8 +8,7 @@ {deps, [ {emqx, {path, "../emqx"}}, {emqx_utils, {path, "../emqx_utils"}}, - {emqx_resource, {path, "../emqx_resource"}}, - {epgsql, {git, "https://github.com/emqx/epgsql", {tag, "4.7.0.1"}}} + {emqx_resource, {path, "../emqx_resource"}} ]}. {shell, [ diff --git a/apps/emqx_connector/src/emqx_connector.app.src b/apps/emqx_connector/src/emqx_connector.app.src index 7ecabb0ffd8..6b462986ba4 100644 --- a/apps/emqx_connector/src/emqx_connector.app.src +++ b/apps/emqx_connector/src/emqx_connector.app.src @@ -10,8 +10,6 @@ ecpool, emqx_resource, eredis_cluster, - eredis, - epgsql, ehttpc, jose, emqx, diff --git a/apps/emqx_machine/priv/reboot_lists.eterm b/apps/emqx_machine/priv/reboot_lists.eterm index 768424db691..16f901d27c3 100644 --- a/apps/emqx_machine/priv/reboot_lists.eterm +++ b/apps/emqx_machine/priv/reboot_lists.eterm @@ -80,6 +80,7 @@ emqx_mongodb, emqx_redis, emqx_mysql, + emqx_postgresql, emqx_plugins, emqx_opentelemetry, quicer, diff --git a/apps/emqx_postgresql/README.md b/apps/emqx_postgresql/README.md new file mode 100644 index 00000000000..bdc21db72ac --- /dev/null +++ b/apps/emqx_postgresql/README.md @@ -0,0 +1,14 @@ +# PostgreSQL Connector + +This application houses the PostgreSQL Database connector. +It provides the APIs to connect to PostgreSQL Databases. + +It is used by the PostgreSQL bridge to insert messages and by the `emqx_auth_postgresql` application to check user permissions. + +## Contributing + +Please see our [contributing.md](../../CONTRIBUTING.md). + +## License + +See [APL](../../APL.txt). diff --git a/apps/emqx_connector/docker-ct b/apps/emqx_postgresql/docker-ct similarity index 100% rename from apps/emqx_connector/docker-ct rename to apps/emqx_postgresql/docker-ct diff --git a/apps/emqx_postgresql/include/emqx_postgresql.hrl b/apps/emqx_postgresql/include/emqx_postgresql.hrl new file mode 100644 index 00000000000..3810bd6c235 --- /dev/null +++ b/apps/emqx_postgresql/include/emqx_postgresql.hrl @@ -0,0 +1,17 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2021-2023 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- + +-define(PGSQL_DEFAULT_PORT, 5432). diff --git a/apps/emqx_postgresql/rebar.config b/apps/emqx_postgresql/rebar.config new file mode 100644 index 00000000000..1ae1309c949 --- /dev/null +++ b/apps/emqx_postgresql/rebar.config @@ -0,0 +1,8 @@ +%% -*- mode: erlang; -*- + +{erl_opts, [debug_info]}. +{deps, [ + {epgsql, {git, "https://github.com/emqx/epgsql", {tag, "4.7.0.1"}}}, + {emqx_connector, {path, "../../apps/emqx_connector"}}, + {emqx_resource, {path, "../../apps/emqx_resource"}} +]}. diff --git a/apps/emqx_postgresql/src/emqx_postgresql.app.src b/apps/emqx_postgresql/src/emqx_postgresql.app.src new file mode 100644 index 00000000000..efe422cd06c --- /dev/null +++ b/apps/emqx_postgresql/src/emqx_postgresql.app.src @@ -0,0 +1,16 @@ +{application, emqx_postgresql, [ + {description, "EMQX PostgreSQL Database Connector"}, + {vsn, "0.1.0"}, + {registered, []}, + {applications, [ + kernel, + stdlib, + epgsql, + emqx_connector, + emqx_resource + ]}, + {env, []}, + {modules, []}, + + {links, []} +]}. diff --git a/apps/emqx_connector/src/emqx_connector_pgsql.erl b/apps/emqx_postgresql/src/emqx_postgresql.erl similarity index 99% rename from apps/emqx_connector/src/emqx_connector_pgsql.erl rename to apps/emqx_postgresql/src/emqx_postgresql.erl index b1e4a9fdbbe..dc6447536fc 100644 --- a/apps/emqx_connector/src/emqx_connector_pgsql.erl +++ b/apps/emqx_postgresql/src/emqx_postgresql.erl @@ -13,9 +13,10 @@ %% See the License for the specific language governing permissions and %% limitations under the License. %%-------------------------------------------------------------------- --module(emqx_connector_pgsql). +-module(emqx_postgresql). --include("emqx_connector.hrl"). +-include("emqx_postgresql.hrl"). +-include_lib("emqx_connector/include/emqx_connector.hrl"). -include_lib("typerefl/include/types.hrl"). -include_lib("emqx/include/logger.hrl"). -include_lib("hocon/include/hoconsc.hrl"). diff --git a/apps/emqx_connector/test/emqx_connector_pgsql_SUITE.erl b/apps/emqx_postgresql/test/emqx_postgresql_SUITE.erl similarity index 96% rename from apps/emqx_connector/test/emqx_connector_pgsql_SUITE.erl rename to apps/emqx_postgresql/test/emqx_postgresql_SUITE.erl index a4ac4f93205..5a93a0578fd 100644 --- a/apps/emqx_connector/test/emqx_connector_pgsql_SUITE.erl +++ b/apps/emqx_postgresql/test/emqx_postgresql_SUITE.erl @@ -13,18 +13,19 @@ % %% limitations under the License. % %%-------------------------------------------------------------------- --module(emqx_connector_pgsql_SUITE). +-module(emqx_postgresql_SUITE). -compile(nowarn_export_all). -compile(export_all). --include("emqx_connector.hrl"). +-include("emqx_connector/include/emqx_connector.hrl"). +-include_lib("emqx_postgresql/include/emqx_postgresql.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("emqx/include/emqx.hrl"). -include_lib("stdlib/include/assert.hrl"). -define(PGSQL_HOST, "pgsql"). --define(PGSQL_RESOURCE_MOD, emqx_connector_pgsql). +-define(PGSQL_RESOURCE_MOD, emqx_postgresql). all() -> emqx_common_test_helpers:all(?MODULE). @@ -60,7 +61,7 @@ end_per_testcase(_, _Config) -> t_lifecycle(_Config) -> perform_lifecycle_check( - <<"emqx_connector_pgsql_SUITE">>, + <<"emqx_postgresql_SUITE">>, pgsql_config() ). diff --git a/rel/i18n/emqx_connector_pgsql.hocon b/rel/i18n/emqx_postgresql.hocon similarity index 91% rename from rel/i18n/emqx_connector_pgsql.hocon rename to rel/i18n/emqx_postgresql.hocon index 485e666a068..c6d2581c183 100644 --- a/rel/i18n/emqx_connector_pgsql.hocon +++ b/rel/i18n/emqx_postgresql.hocon @@ -1,4 +1,4 @@ -emqx_connector_pgsql { +emqx_postgresql { server.desc: """The IPv4 or IPv6 address or the hostname to connect to.