chore(source dir): split out postgresql connector
This commit is contained in:
parent
7a6c756b7c
commit
4f14e8df22
|
@ -9,7 +9,7 @@
|
||||||
stdlib,
|
stdlib,
|
||||||
emqx,
|
emqx,
|
||||||
emqx_auth,
|
emqx_auth,
|
||||||
emqx_connector
|
emqx_postgresql
|
||||||
]},
|
]},
|
||||||
{env, []},
|
{env, []},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
|
|
|
@ -46,14 +46,14 @@ create(Config0) ->
|
||||||
{Config, State} = parse_config(Config0, ResourceId),
|
{Config, State} = parse_config(Config0, ResourceId),
|
||||||
{ok, _Data} = emqx_authn_utils:create_resource(
|
{ok, _Data} = emqx_authn_utils:create_resource(
|
||||||
ResourceId,
|
ResourceId,
|
||||||
emqx_connector_pgsql,
|
emqx_postgresql,
|
||||||
Config
|
Config
|
||||||
),
|
),
|
||||||
{ok, State#{resource_id => ResourceId}}.
|
{ok, State#{resource_id => ResourceId}}.
|
||||||
|
|
||||||
update(Config0, #{resource_id := ResourceId} = _State) ->
|
update(Config0, #{resource_id := ResourceId} = _State) ->
|
||||||
{Config, NState} = parse_config(Config0, ResourceId),
|
{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, Reason} ->
|
||||||
error({load_config_error, Reason});
|
error({load_config_error, Reason});
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
|
|
|
@ -50,7 +50,7 @@ fields(postgresql) ->
|
||||||
{query, fun query/1}
|
{query, fun query/1}
|
||||||
] ++
|
] ++
|
||||||
emqx_authn_schema:common_fields() ++
|
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) ->
|
||||||
?DESC(postgresql);
|
?DESC(postgresql);
|
||||||
|
|
|
@ -50,10 +50,10 @@ description() ->
|
||||||
|
|
||||||
create(#{query := SQL0} = Source) ->
|
create(#{query := SQL0} = Source) ->
|
||||||
{SQL, PlaceHolders} = emqx_authz_utils:parse_sql(SQL0, '$n', ?PLACEHOLDERS),
|
{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(
|
{ok, _Data} = emqx_authz_utils:create_resource(
|
||||||
ResourceID,
|
ResourceID,
|
||||||
emqx_connector_pgsql,
|
emqx_postgresql,
|
||||||
Source#{prepare_statement => #{ResourceID => SQL}}
|
Source#{prepare_statement => #{ResourceID => SQL}}
|
||||||
),
|
),
|
||||||
Source#{annotations => #{id => ResourceID, placeholders => PlaceHolders}}.
|
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),
|
{SQL, PlaceHolders} = emqx_authz_utils:parse_sql(SQL0, '$n', ?PLACEHOLDERS),
|
||||||
case
|
case
|
||||||
emqx_authz_utils:update_resource(
|
emqx_authz_utils:update_resource(
|
||||||
emqx_connector_pgsql,
|
emqx_postgresql,
|
||||||
Source#{prepare_statement => #{ResourceID => SQL}}
|
Source#{prepare_statement => #{ResourceID => SQL}}
|
||||||
)
|
)
|
||||||
of
|
of
|
||||||
|
|
|
@ -33,7 +33,7 @@ type() -> ?AUTHZ_TYPE.
|
||||||
|
|
||||||
fields(postgresql) ->
|
fields(postgresql) ->
|
||||||
emqx_authz_schema:authz_common_fields(?AUTHZ_TYPE) ++
|
emqx_authz_schema:authz_common_fields(?AUTHZ_TYPE) ++
|
||||||
emqx_connector_pgsql:fields(config) ++
|
emqx_postgresql:fields(config) ++
|
||||||
[{query, query()}].
|
[{query, query()}].
|
||||||
|
|
||||||
desc(postgresql) ->
|
desc(postgresql) ->
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
-compile(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("emqx_auth/include/emqx_authn.hrl").
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
@ -64,7 +64,7 @@ init_per_suite(Config) ->
|
||||||
{ok, _} = emqx_resource:create_local(
|
{ok, _} = emqx_resource:create_local(
|
||||||
?PGSQL_RESOURCE,
|
?PGSQL_RESOURCE,
|
||||||
?AUTHN_RESOURCE_GROUP,
|
?AUTHN_RESOURCE_GROUP,
|
||||||
emqx_connector_pgsql,
|
emqx_postgresql,
|
||||||
pgsql_config(),
|
pgsql_config(),
|
||||||
#{}
|
#{}
|
||||||
),
|
),
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
-compile(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("emqx_auth/include/emqx_authn.hrl").
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
-compile(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("emqx_auth/include/emqx_authz.hrl").
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
@ -438,7 +438,7 @@ create_pgsql_resource() ->
|
||||||
emqx_resource:create_local(
|
emqx_resource:create_local(
|
||||||
?PGSQL_RESOURCE,
|
?PGSQL_RESOURCE,
|
||||||
?AUTHZ_RESOURCE_GROUP,
|
?AUTHZ_RESOURCE_GROUP,
|
||||||
emqx_connector_pgsql,
|
emqx_postgresql,
|
||||||
pgsql_config(),
|
pgsql_config(),
|
||||||
#{}
|
#{}
|
||||||
).
|
).
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
%% -*- mode: erlang -*-
|
%% -*- mode: erlang -*-
|
||||||
{application, emqx_bridge, [
|
{application, emqx_bridge, [
|
||||||
{description, "EMQX bridges"},
|
{description, "EMQX bridges"},
|
||||||
{vsn, "0.1.28"},
|
{vsn, "0.1.29"},
|
||||||
{registered, [emqx_bridge_sup]},
|
{registered, [emqx_bridge_sup]},
|
||||||
{mod, {emqx_bridge_app, []}},
|
{mod, {emqx_bridge_app, []}},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|
|
@ -113,9 +113,9 @@ resource_type(influxdb_api_v2) -> emqx_bridge_influxdb_connector;
|
||||||
resource_type(redis_single) -> emqx_bridge_redis_connector;
|
resource_type(redis_single) -> emqx_bridge_redis_connector;
|
||||||
resource_type(redis_sentinel) -> emqx_bridge_redis_connector;
|
resource_type(redis_sentinel) -> emqx_bridge_redis_connector;
|
||||||
resource_type(redis_cluster) -> emqx_bridge_redis_connector;
|
resource_type(redis_cluster) -> emqx_bridge_redis_connector;
|
||||||
resource_type(pgsql) -> emqx_connector_pgsql;
|
resource_type(pgsql) -> emqx_postgresql;
|
||||||
resource_type(timescale) -> emqx_connector_pgsql;
|
resource_type(timescale) -> emqx_postgresql;
|
||||||
resource_type(matrix) -> emqx_connector_pgsql;
|
resource_type(matrix) -> emqx_postgresql;
|
||||||
resource_type(tdengine) -> emqx_bridge_tdengine_connector;
|
resource_type(tdengine) -> emqx_bridge_tdengine_connector;
|
||||||
resource_type(clickhouse) -> emqx_bridge_clickhouse_connector;
|
resource_type(clickhouse) -> emqx_bridge_clickhouse_connector;
|
||||||
resource_type(dynamo) -> emqx_bridge_dynamo_connector;
|
resource_type(dynamo) -> emqx_bridge_dynamo_connector;
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
{deps, [
|
{deps, [
|
||||||
{emqx_connector, {path, "../../apps/emqx_connector"}},
|
{emqx_connector, {path, "../../apps/emqx_connector"}},
|
||||||
{emqx_resource, {path, "../../apps/emqx_resource"}},
|
{emqx_resource, {path, "../../apps/emqx_resource"}},
|
||||||
{emqx_bridge, {path, "../../apps/emqx_bridge"}}
|
{emqx_bridge, {path, "../../apps/emqx_bridge"}},
|
||||||
|
{emqx_postgresql, {path, "../../apps/emqx_postgresql"}}
|
||||||
]}.
|
]}.
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
{application, emqx_bridge_pgsql, [
|
{application, emqx_bridge_pgsql, [
|
||||||
{description, "EMQX Enterprise PostgreSQL Bridge"},
|
{description, "EMQX Enterprise PostgreSQL Bridge"},
|
||||||
{vsn, "0.1.3"},
|
{vsn, "0.1.4"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [
|
{applications, [
|
||||||
kernel,
|
kernel,
|
||||||
stdlib,
|
stdlib,
|
||||||
emqx_resource
|
emqx_resource,
|
||||||
|
emqx_postgresql
|
||||||
]},
|
]},
|
||||||
{env, []},
|
{env, []},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
|
|
|
@ -82,7 +82,7 @@ fields("config") ->
|
||||||
#{desc => ?DESC("local_topic"), default => undefined}
|
#{desc => ?DESC("local_topic"), default => undefined}
|
||||||
)}
|
)}
|
||||||
] ++ emqx_resource_schema:fields("resource_opts") ++
|
] ++ emqx_resource_schema:fields("resource_opts") ++
|
||||||
(emqx_connector_pgsql:fields(config) --
|
(emqx_postgresql:fields(config) --
|
||||||
emqx_connector_schema_lib:prepare_statement_fields());
|
emqx_connector_schema_lib:prepare_statement_fields());
|
||||||
fields("post") ->
|
fields("post") ->
|
||||||
fields("post", pgsql);
|
fields("post", pgsql);
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
-define(MYSQL_DEFAULT_PORT, 3306).
|
-define(MYSQL_DEFAULT_PORT, 3306).
|
||||||
-define(MONGO_DEFAULT_PORT, 27017).
|
-define(MONGO_DEFAULT_PORT, 27017).
|
||||||
-define(REDIS_DEFAULT_PORT, 6379).
|
-define(REDIS_DEFAULT_PORT, 6379).
|
||||||
-define(PGSQL_DEFAULT_PORT, 5432).
|
|
||||||
-define(CLICKHOUSE_DEFAULT_PORT, 8123).
|
-define(CLICKHOUSE_DEFAULT_PORT, 8123).
|
||||||
|
|
||||||
-define(AUTO_RECONNECT_INTERVAL, 2).
|
-define(AUTO_RECONNECT_INTERVAL, 2).
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
{deps, [
|
{deps, [
|
||||||
{emqx, {path, "../emqx"}},
|
{emqx, {path, "../emqx"}},
|
||||||
{emqx_utils, {path, "../emqx_utils"}},
|
{emqx_utils, {path, "../emqx_utils"}},
|
||||||
{emqx_resource, {path, "../emqx_resource"}},
|
{emqx_resource, {path, "../emqx_resource"}}
|
||||||
{epgsql, {git, "https://github.com/emqx/epgsql", {tag, "4.7.0.1"}}}
|
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{shell, [
|
{shell, [
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
ecpool,
|
ecpool,
|
||||||
emqx_resource,
|
emqx_resource,
|
||||||
eredis_cluster,
|
eredis_cluster,
|
||||||
eredis,
|
|
||||||
epgsql,
|
|
||||||
ehttpc,
|
ehttpc,
|
||||||
jose,
|
jose,
|
||||||
emqx,
|
emqx,
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
emqx_mongodb,
|
emqx_mongodb,
|
||||||
emqx_redis,
|
emqx_redis,
|
||||||
emqx_mysql,
|
emqx_mysql,
|
||||||
|
emqx_postgresql,
|
||||||
emqx_plugins,
|
emqx_plugins,
|
||||||
emqx_opentelemetry,
|
emqx_opentelemetry,
|
||||||
quicer,
|
quicer,
|
||||||
|
|
|
@ -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).
|
|
@ -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).
|
|
@ -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"}}
|
||||||
|
]}.
|
|
@ -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, []}
|
||||||
|
]}.
|
|
@ -13,9 +13,10 @@
|
||||||
%% See the License for the specific language governing permissions and
|
%% See the License for the specific language governing permissions and
|
||||||
%% limitations under the License.
|
%% 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("typerefl/include/types.hrl").
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
-include_lib("hocon/include/hoconsc.hrl").
|
-include_lib("hocon/include/hoconsc.hrl").
|
|
@ -13,18 +13,19 @@
|
||||||
% %% limitations under the License.
|
% %% limitations under the License.
|
||||||
% %%--------------------------------------------------------------------
|
% %%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqx_connector_pgsql_SUITE).
|
-module(emqx_postgresql_SUITE).
|
||||||
|
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
-compile(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("eunit/include/eunit.hrl").
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-include_lib("stdlib/include/assert.hrl").
|
-include_lib("stdlib/include/assert.hrl").
|
||||||
|
|
||||||
-define(PGSQL_HOST, "pgsql").
|
-define(PGSQL_HOST, "pgsql").
|
||||||
-define(PGSQL_RESOURCE_MOD, emqx_connector_pgsql).
|
-define(PGSQL_RESOURCE_MOD, emqx_postgresql).
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
@ -60,7 +61,7 @@ end_per_testcase(_, _Config) ->
|
||||||
|
|
||||||
t_lifecycle(_Config) ->
|
t_lifecycle(_Config) ->
|
||||||
perform_lifecycle_check(
|
perform_lifecycle_check(
|
||||||
<<"emqx_connector_pgsql_SUITE">>,
|
<<"emqx_postgresql_SUITE">>,
|
||||||
pgsql_config()
|
pgsql_config()
|
||||||
).
|
).
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
emqx_connector_pgsql {
|
emqx_postgresql {
|
||||||
|
|
||||||
server.desc:
|
server.desc:
|
||||||
"""The IPv4 or IPv6 address or the hostname to connect to.<br/>
|
"""The IPv4 or IPv6 address or the hostname to connect to.<br/>
|
Loading…
Reference in New Issue