Explorar el Código

Merge pull request #9680 from JimMoen/fix-influxdb-api

fix(influxdb): authentication is not required for influxdb v1 api
JimMoen hace 3 años
padre
commit
050d245fa5

+ 1 - 0
changes/v5.0.15/fix-9680.en.md

@@ -0,0 +1 @@
+Fix the problem that username and password authentication is mandatory in Influxdb v1 write API.

+ 1 - 0
changes/v5.0.15/fix-9680.zh.md

@@ -0,0 +1 @@
+修复 InfluxDB v1 桥接写入 API 配置中强制需要用户名密码认证的问题。

+ 18 - 9
lib-ee/emqx_ee_connector/src/emqx_ee_connector_influxdb.erl

@@ -278,19 +278,18 @@ client_config(
     ] ++ protocol_config(Config).
 
 %% api v1 config
-protocol_config(#{
-    username := Username,
-    password := Password,
-    database := DB,
-    ssl := SSL
-}) ->
+protocol_config(
+    #{
+        database := DB,
+        ssl := SSL
+    } = Config
+) ->
     [
         {protocol, http},
         {version, v1},
-        {username, str(Username)},
-        {password, str(Password)},
         {database, str(DB)}
-    ] ++ ssl_config(SSL);
+    ] ++ username(Config) ++
+        password(Config) ++ ssl_config(SSL);
 %% api v2 config
 protocol_config(#{
     bucket := Bucket,
@@ -321,6 +320,16 @@ ssl_config(SSL = #{enable := true}) ->
         {transport, ssl}
     ] ++ maps:to_list(maps:remove(enable, SSL)).
 
+username(#{username := Username}) ->
+    [{username, str(Username)}];
+username(_) ->
+    [].
+
+password(#{password := Password}) ->
+    [{password, str(Password)}];
+password(_) ->
+    [].
+
 %% -------------------------------------------------------------------------------------------------
 %% Query
 do_query(InstId, Client, Points) ->