fix(oracle): require either sid or service name

Fixes https://emqx.atlassian.net/browse/EMQX-9980
This commit is contained in:
Paulo Zulato 2023-05-30 21:28:43 -03:00
parent b7c72e6cfb
commit 3a6ad3b049
5 changed files with 26 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{application, emqx_bridge_oracle, [
{description, "EMQX Enterprise Oracle Database Bridge"},
{vsn, "0.1.1"},
{vsn, "0.1.2"},
{registered, []},
{applications, [
kernel,

View File

@ -16,7 +16,8 @@
namespace/0,
roots/0,
fields/1,
desc/1
desc/1,
config_validator/1
]).
-define(DEFAULT_SQL, <<
@ -107,3 +108,12 @@ type_field(Type) ->
name_field() ->
{name, hoconsc:mk(binary(), #{required => true, desc => ?DESC("desc_name")})}.
config_validator(#{<<"server">> := Server} = Config) when
not is_map(Server) andalso
not is_map_key(<<"sid">>, Config) andalso
not is_map_key(<<"service_name">>, Config)
->
{error, "neither SID nor Service Name was set"};
config_validator(_) ->
ok.

View File

@ -517,3 +517,15 @@ t_on_get_status(Config) ->
?assertEqual({ok, connected}, emqx_resource_manager:health_check(ResourceId))
),
ok.
t_no_sid_nor_service_name(Config0) ->
OracleConfig0 = ?config(oracle_config, Config0),
OracleConfig1 = maps:remove(<<"sid">>, OracleConfig0),
OracleConfig = maps:remove(<<"service_name">>, OracleConfig1),
NewOracleConfig = {oracle_config, OracleConfig},
Config = lists:keyreplace(oracle_config, 1, Config0, NewOracleConfig),
?assertMatch(
{error, #{kind := validation_error}},
create_bridge(Config)
),
ok.

View File

@ -0,0 +1 @@
Require that SID or Service Name is set on Oracle Database bridge creation.

View File

@ -186,6 +186,7 @@ fields(bridges) ->
hoconsc:map(name, ref(emqx_bridge_oracle, "config")),
#{
desc => <<"Oracle Bridge Config">>,
validator => fun emqx_bridge_oracle:config_validator/1,
required => false
}
)},