Browse Source

fix(emqx_bridge_cassandra): allow cassandra bridge without username/password

Cassandra can be used without credentials, if it is configured with AllowAllAuthenticator (default).
Serge Tupchii 2 years atrás
parent
commit
1bf86250dd

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

@@ -1,6 +1,6 @@
 {application, emqx_bridge_cassandra, [
 {application, emqx_bridge_cassandra, [
     {description, "EMQX Enterprise Cassandra Bridge"},
     {description, "EMQX Enterprise Cassandra Bridge"},
-    {vsn, "0.1.3"},
+    {vsn, "0.1.4"},
     {registered, []},
     {registered, []},
     {applications, [
     {applications, [
         kernel,
         kernel,

+ 19 - 4
apps/emqx_bridge_cassandra/src/emqx_bridge_cassandra_connector.erl

@@ -94,7 +94,6 @@ on_start(
     #{
     #{
         servers := Servers0,
         servers := Servers0,
         keyspace := Keyspace,
         keyspace := Keyspace,
-        username := Username,
         pool_size := PoolSize,
         pool_size := PoolSize,
         ssl := SSL
         ssl := SSL
     } = Config
     } = Config
@@ -114,12 +113,12 @@ on_start(
 
 
     Options = [
     Options = [
         {nodes, Servers},
         {nodes, Servers},
-        {username, Username},
-        {password, emqx_secret:wrap(maps:get(password, Config, ""))},
         {keyspace, Keyspace},
         {keyspace, Keyspace},
         {auto_reconnect, ?AUTO_RECONNECT_INTERVAL},
         {auto_reconnect, ?AUTO_RECONNECT_INTERVAL},
         {pool_size, PoolSize}
         {pool_size, PoolSize}
     ],
     ],
+    Options1 = maybe_add_opt(username, Config, Options),
+    Options2 = maybe_add_opt(password, Config, Options1, _IsSensitive = true),
 
 
     SslOpts =
     SslOpts =
         case maps:get(enable, SSL) of
         case maps:get(enable, SSL) of
@@ -132,7 +131,7 @@ on_start(
                 []
                 []
         end,
         end,
     State = parse_prepare_cql(Config),
     State = parse_prepare_cql(Config),
-    case emqx_resource_pool:start(InstId, ?MODULE, Options ++ SslOpts) of
+    case emqx_resource_pool:start(InstId, ?MODULE, Options2 ++ SslOpts) of
         ok ->
         ok ->
             {ok, init_prepare(State#{pool_name => InstId, prepare_statement => #{}})};
             {ok, init_prepare(State#{pool_name => InstId, prepare_statement => #{}})};
         {error, Reason} ->
         {error, Reason} ->
@@ -513,3 +512,19 @@ maybe_assign_type(V) when is_integer(V) ->
 maybe_assign_type(V) when is_float(V) -> {double, V};
 maybe_assign_type(V) when is_float(V) -> {double, V};
 maybe_assign_type(V) ->
 maybe_assign_type(V) ->
     V.
     V.
+
+maybe_add_opt(Key, Conf, Opts) ->
+    maybe_add_opt(Key, Conf, Opts, _IsSensitive = false).
+
+maybe_add_opt(Key, Conf, Opts, IsSensitive) ->
+    case Conf of
+        #{Key := Val} ->
+            [{Key, maybe_wrap(IsSensitive, Val)} | Opts];
+        _ ->
+            Opts
+    end.
+
+maybe_wrap(false = _IsSensitive, Val) ->
+    Val;
+maybe_wrap(true, Val) ->
+    emqx_secret:wrap(Val).