Browse Source

chore(source dir): split out postgresql connector

Ilya Averyanov 2 years atrás
parent
commit
4f14e8df22

+ 1 - 1
apps/emqx_auth_postgresql/src/emqx_auth_postgresql.app.src

@@ -9,7 +9,7 @@
         stdlib,
         emqx,
         emqx_auth,
-        emqx_connector
+        emqx_postgresql
     ]},
     {env, []},
     {modules, []},

+ 2 - 2
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, _} ->

+ 1 - 1
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);

+ 3 - 3
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

+ 1 - 1
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) ->

+ 2 - 2
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(),
                 #{}
             ),

+ 1 - 1
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").

+ 2 - 2
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(),
         #{}
     ).

+ 1 - 1
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, [

+ 3 - 3
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;

+ 2 - 1
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"}}
 ]}.

+ 3 - 2
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, []},

+ 1 - 1
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);

+ 0 - 1
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).

+ 1 - 2
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, [

+ 0 - 2
apps/emqx_connector/src/emqx_connector.app.src

@@ -10,8 +10,6 @@
         ecpool,
         emqx_resource,
         eredis_cluster,
-        eredis,
-        epgsql,
         ehttpc,
         jose,
         emqx,

+ 1 - 0
apps/emqx_machine/priv/reboot_lists.eterm

@@ -80,6 +80,7 @@
             emqx_mongodb,
             emqx_redis,
             emqx_mysql,
+            emqx_postgresql,
             emqx_plugins,
             emqx_opentelemetry,
             quicer,

+ 14 - 0
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).

apps/emqx_connector/docker-ct → apps/emqx_postgresql/docker-ct


+ 17 - 0
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).

+ 8 - 0
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"}}
+]}.

+ 16 - 0
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, []}
+]}.

+ 3 - 2
apps/emqx_connector/src/emqx_connector_pgsql.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").

+ 5 - 4
apps/emqx_connector/test/emqx_connector_pgsql_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()
     ).
 

+ 1 - 1
rel/i18n/emqx_connector_pgsql.hocon

@@ -1,4 +1,4 @@
-emqx_connector_pgsql {
+emqx_postgresql {
 
 server.desc:
 """The IPv4 or IPv6 address or the hostname to connect to.<br/>